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

Commit

Permalink
ECS sprite example
Browse files Browse the repository at this point in the history
  • Loading branch information
shosanna committed Sep 18, 2023
1 parent 214cbb9 commit 74d7f58
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
EXAMPLE=animated_shapes
# EXAMPLE=animated_shapes
# EXAMPLE=sprite
# EXAMPLE=text
# EXAMPLE=particles
# EXAMPLE=post_processing
# EXAMPLE=shapes
EXAMPLE=ecs_sprite

# default: build-examples
# default: wasm-build
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,10 @@ Examples
- [ ] top-down minigame
- [x] platformer minigame
- [x] timed draw
- [ ] ecs sprite
- [x] ecs sprite
- [ ] ecs animatedsprite

- [ ] rename example_game to simple_game
- [ ] context example

# Games using comfy

Expand Down
12 changes: 11 additions & 1 deletion comfy/examples/ecs_sprite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ example_game!("ECS Sprite Example", setup, update);
struct Player;

fn setup(c: &mut EngineContext) {
c.load_texture_from_bytes(
// Every texture gets a string name later used to reference it.
"comfy",
include_bytes!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../assets/comfy.png"
)),
wgpu::AddressMode::ClampToEdge,
);

// Spawn a new entity with a sprite and a transform.
c.commands().spawn((
Sprite::new("comfy".to_string(), vec2(1.0, 1.0), 100, WHITE),
Expand All @@ -19,6 +29,6 @@ fn update(c: &mut EngineContext) {
for (entity, (player, sprite, transform)) in
c.world().query::<(&Player, &Sprite, &mut Transform)>().iter()
{
transform.scale += 10.0 * c.delta;
transform.scale = (get_time() as f32).sin() + 2.0;
}
}

0 comments on commit 74d7f58

Please sign in to comment.