Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
Cleaner AnimatedSprite + example fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
darthdeus committed Sep 21, 2023
1 parent ecd40a4 commit bef5eda
Show file tree
Hide file tree
Showing 10 changed files with 394 additions and 224 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
[workspace]
resolver = "2"

members = [
"comfy",
"comfy-core",
"comfy-wgpu",
]
members = ["comfy", "comfy-core", "comfy-wgpu", "games/bitmob"]

[profile.dev]
opt-level = 3
Expand Down
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# EXAMPLE=animated_shapes
EXAMPLE=sprite
# EXAMPLE=sprite
# EXAMPLE=text
# EXAMPLE=particles
# EXAMPLE=post_processing
# EXAMPLE=shapes
# EXAMPLE=ecs_sprite
# EXAMPLE=ecs_topdown_game
EXAMPLE=ecs_topdown_game

# default: build-examples
# default: wasm-build
default: example
# default: profile-startup
# default: bitmob
default: example

FLAGS=--release
ENV_VARS=RUST_LOG=info,wgpu=warn,symphonia=warn

bitmob:
$(ENV_VARS) cargo run --bin bitmob $(FLAGS)

example:
RUST_LOG=info,wgpu=warn,symphonia=warn cargo run --example $(EXAMPLE) $(FLAGS)
$(ENV_VARS) cargo run --example $(EXAMPLE) $(FLAGS)

tests:
cargo test
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ Only features that require maximum few weeks of work are listed here.
does make games look better by default, but it is one of the first few things
that will get fixed after v0.1 release.
- Configurable post processing.
- Camera render targets
- Custom shaders/materials.
- Render targets.
- Gamepad & touchpad support.
- Antialiasing.
- 2D shadowcasters with soft shadows.
Expand All @@ -284,6 +284,18 @@ Only features that require maximum few weeks of work are listed here.
being said, almost everything you find in comfy should work to a reasonable
extent.

While comfy is ready to use, the codebase is far from clean. The engine
evolves rapidly as we work on our games, and there are many parts that can
and will be improved. Comfy is being released before it is 100% perfect,
because even in its current state it can be very well used to make 2D games.

There may be a few oddities you may run into, and some internals are
planned to be re-done, but anything covered by the examples should 100%
work. We have been using comfy internally for over 6 months, and a large
part of its codebase has been ported from our previous OpenGL based
engine. This doesn't mean the engine is mature, but we have had real
players play our games made with comfy.

# Contributing

Comfy is still very early in its lifecycle. While it has been used to make
Expand Down
47 changes: 36 additions & 11 deletions comfy/examples/ecs_topdown_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,40 @@ fn setup(c: &mut EngineContext) {
}
}

let sprite = AnimatedSpriteBuilder::new()
.z_index(10)
.add_animation("idle", 0.1, true, AnimationSource::Atlas {
name: "player".into(),
offset: ivec2(0, 0),
step: ivec2(16, 0),
size: isplat(16),
frames: 4,
})
.add_animation("walk", 0.1, true, AnimationSource::Atlas {
name: "player".into(),
offset: ivec2(16 * 4, 0),
step: ivec2(16, 0),
size: isplat(16),
frames: 4,
})
.build();

// Spawn the player entity and make sure z-index is above the grass
c.commands().spawn((
Transform::position(vec2(10.0, 10.0)),
Player,
AnimatedSprite::spritesheet(
"player",
Spritesheet { rows: 1, columns: 28 },
0.1,
true,
10,
splat(1.0),
WHITE,
splat(0.0),
Box::new(|_| {}),
),
sprite,
// AnimatedSprite::spritesheet(
// "player",
// Spritesheet { rows: 1, columns: 28 },
// 0.1,
// true,
// 10,
// splat(1.0),
// WHITE,
// splat(0.0),
// Box::new(|_| {}),
// ),
));
}

Expand Down Expand Up @@ -86,6 +105,12 @@ fn update(c: &mut EngineContext) {
moved = true;
}

if moved {
animated_sprite.play("walk");
} else {
animated_sprite.play("idle");
}

main_camera_mut().center = transform.position;
}
}
2 changes: 1 addition & 1 deletion comfy/examples/sprite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn setup(c: &mut EngineContext) {
);
}

fn update(c: &mut EngineContext) {
fn update(_c: &mut EngineContext) {
draw_sprite(
// Drawing sprites/textures requires a TextureHandle which can be calculated from its
// string name. This incurs a non-measurable overhead in hashing the string, but saves
Expand Down
Loading

0 comments on commit bef5eda

Please sign in to comment.