hyperandroid / CAAT

Canvas Advanced Animation Toolkit
hyperandroid.github.com/CAAT
MIT License
727 stars 117 forks source link

Fixed sprite image index copy in getRef() #161

Open arnuschky opened 10 years ago

arnuschky commented 10 years ago

We're using sprite maps with CAAT: on startup, we load a 2048x2048px map with the preloader and initialize it using the initializeFromMap function. Works like a charm.

In order to use the sprites of the map, we would need to do something along these lines:

var sprite = spriteMap.getRef().setSpriteIndex('name'); var actor = new CAAT.Actor(); actor.setBackgroundImage(sprite, false); actor.setSize(sprite.getWidth(), sprite.getHeight());

This is obviously quite uncomfortable. Preferably, one would use something like this:

var actor = new CAAT.Actor(); actor.setBackgroundImage(spriteMap.setSpriteIndex('name'), true);

Unfortunately, this does not work because setBackgroundImage calls getRef(), which does not copy the spriteIndex of the image.

We fixed this by copying the spriteIndex in getRef() as well. We can now use the spritemap as describe above, which is really efficient.