Skip to content

Allow custom sprites, introduce collider files, collider_creator example #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2021

Conversation

CleanCut
Copy link
Owner

The pro (and con) of doing a bunch of work that's primarily for yourself is that you occassionally end up doing a wee bit more than you originally intended to do in a single pull request. 😊

The changes...extracted from the changelog diff:

  • GameState::add_actor has been renamed to EngineState::add_sprite
  • GameState::add_text_actor has been renamed to EngineState::add_text
  • GameState.screen_dimensions, which was set at startup and never updated, has been replaced by EngineState.window_dimensions, which is updated every frame so resizing the window can be handled in your game logic.
  • Logic functions now need to fit the signature fn somename(engine_state: &mut EngineState, game_state: &mut GameState) -> bool, where GameState is the user-defined struct passed to rusty_engine::init!(), or () if nothing was passed in.
  • Actor::build has been replaced by Sprite::new, which must be used to create a Sprite instead of defining a struct literal (enforced via private phantom data). The Default implementation has been removed because of the previous restriction.
  • Actor.preset has been removed
  • Actor.filename (a String) has been replaced with Sprite.filepath (a PathBuf)
  • The builder methods Actor::set_collision and Actor::set_collider have been removed since we never ended up adopting a builder pattern.
  • Sprite.collider_filepath has been added
  • Sprite::write_collider has been added (see note below about changes to colliders)
  • TextActor.text is now Text.value for similar reasons.
  • Sprites may now be created with either a SpritePreset or the path to an image file via both Sprite::new or EngineState::add_sprite
  • SpritePreset::build_from_name and SpritePreset::build have been removed (see note above about the new, more flexible way to create sprites)
  • SpritePreset::collider() has been removed since colliders are no longer hard-coded features of presets (see note below about changes to colliders)
  • SpritePreset::filename -> String has been replaced by SpritePreset::filepath -> PathBuf, which powers the impl From<SpritePreset> for PathBuf implementation.
  • Colliders are now loaded from collider files. Collider files use the Rusty Object Notation (RON) format. The easiest way to create a collider is to run the collider_creator example by cloning the rusty_engine repository and running cargo run --release --example collider_creator relative/path/to/my/image.png. The image needs to be somewhere inside the assets/ directory. You could also create the collider programmatically, set it on the Sprite struct, and call the sprite's write_collider() method. Or you could copy an existing collider file, name it the same as your image file (but with the .collider extension) and change it to match your image. Collider coordinates need to define a convex polygon with points going in clockwise order. Coordinates are floating point values relative to the center of the image, with the center of the image being (0.0, 0.0).
  • All sprites' colliders in the asset pack have been recreated more cleanly using the new collider_creator example
  • Collider now implements PartialEq, Serialize, and Deserialize
  • Collider::is_convex was added to make it easier to tell if you have a convex collider.
  • The collider_creator example was added to make it easy to load a sprite and make a collider file for it. Place your image file (let's call it my_image.png) anywhere inside your local clone of the Rusty Engine assets/ directory and then run the example: cargo run --release --example collider_creator -- assets/my_image.png. Afterwards, copy the image file and the new collider file my_image.collider file over to the assets directory of your own project.
  • You can now toggle debug rendering of colliders by setting EngineState.debug_sprite_colliders to true. The collision example will now toggle that value when you press the C key.
  • Circular colliders no longer have duplicate starting and ending coordinates

Part of #16

@CleanCut CleanCut merged commit 20ba77d into main Dec 27, 2021
@CleanCut CleanCut deleted the sprite-overhaul branch December 27, 2021 05:47
@CleanCut CleanCut mentioned this pull request Dec 27, 2021
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant