Allow custom sprites, introduce collider files, collider_creator example #24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 toEngineState::add_sprite
GameState::add_text_actor
has been renamed toEngineState::add_text
GameState.screen_dimensions
, which was set at startup and never updated, has been replaced byEngineState.window_dimensions
, which is updated every frame so resizing the window can be handled in your game logic.fn somename(engine_state: &mut EngineState, game_state: &mut GameState) -> bool
, whereGameState
is the user-defined struct passed torusty_engine::init!()
, or()
if nothing was passed in.Actor::build
has been replaced bySprite::new
, which must be used to create aSprite
instead of defining a struct literal (enforced via private phantom data). TheDefault
implementation has been removed because of the previous restriction.Actor.preset
has been removedActor.filename
(aString
) has been replaced withSprite.filepath
(aPathBuf
)Actor::set_collision
andActor::set_collider
have been removed since we never ended up adopting a builder pattern.Sprite.collider_filepath
has been addedSprite::write_collider
has been added (see note below about changes to colliders)TextActor.text
is nowText.value
for similar reasons.Sprite
s may now be created with either aSpritePreset
or the path to an image file via bothSprite::new
orEngineState::add_sprite
SpritePreset::build_from_name
andSpritePreset::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 bySpritePreset::filepath -> PathBuf
, which powers theimpl From<SpritePreset> for PathBuf
implementation.collider_creator
example by cloning therusty_engine
repository and runningcargo run --release --example collider_creator relative/path/to/my/image.png
. The image needs to be somewhere inside theassets/
directory. You could also create the collider programmatically, set it on theSprite
struct, and call the sprite'swrite_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).collider_creator
exampleCollider
now implementsPartialEq
,Serialize
, andDeserialize
Collider::is_convex
was added to make it easier to tell if you have a convex collider.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 itmy_image.png
) anywhere inside your local clone of the Rusty Engineassets/
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 filemy_image.collider
file over to the assets directory of your own project.EngineState.debug_sprite_colliders
totrue
. Thecollision
example will now toggle that value when you press theC
key.Part of #16