craftyjs/Crafty

Allow usage of multiple sprites per entity.

miou-gh opened this issue · 1 comments

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. 🐰

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!