Skip to content
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

Allow usage of multiple sprites per entity. #1190

Open
miou-gh opened this issue Sep 13, 2018 · 1 comment
Open

Allow usage of multiple sprites per entity. #1190

miou-gh opened this issue Sep 13, 2018 · 1 comment

Comments

@miou-gh
Copy link

miou-gh commented Sep 13, 2018

I have a few separate tilemap images for various animations that I want to apply to a given entity or component.

For example, I'd like to do something like the following.

let __standing_sprites = {
'PlayerStandUp': [0, 0],
'PlayerStandDown': [1, 0]
};

let __walking_sprites = {
'PlayerWalkUp': [0, 0],
'PlayerWalkUp2': [0, 0],
'PlayerWalkDown': [1, 0]
'PlayerWalkDown2': [1, 0]
};

Crafty.sprite(18, 58, "gfx/skins/101.png", __standing_sprites);
Crafty.sprite(26, 61, "gfx/skins/102.png", __walking_sprites);
let entity = Crafty.e("2D, Canvas, SpriteAnimation, PlayerStandUp");

entity.reel('PlayerWalkUp', 500, [ 'PlayerWalkUp', 'PlayerWalkUp2' ]);
entity.reel('PlayerWalkDown', 500, [ 'PlayerWalkDown', 'PlayerWalkDown2' ]);

Is there any way you could do this?

I don't see any way I could currently, without shoving them into one huge tile sheet and losing the ability to define the grid like I do with 18, 58 and 26, 61. Thanks. 🐰

@starwed
Copy link
Member

starwed commented Sep 22, 2018

As a workaround, you can swap which tilesheet is used by swapping components. (Removing PlayerStandUp and adding PlayerWalkDown, in this instance.) But you'd have to do this each time you wanted to start the reel, and likely you'd want to check the current sprite to avoid doing unnecessary work.

It would be better if there was a convenience method for doing this, though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants