I have a card game in which I create all 52 cards once and cache them one by one.
I want be able to display same card (e.g. King of Spades) multiple times as efficiently as possible. Currently I'm cloning the existing cards whenever I need to display multiple instances of it.
Is there a way to either clone a cached card, so that the clone will have the same cache or get a reference to bitmap (cached) version of my card?
You can clone the card using card.clone()
, which will share the same cacheCanvas
as the originally cloned item. Additionally, you can create bitmaps using another cacheCanvas as the source:
var bmp = new createjs.Bitmap(otherItem.cacheCanvas);
Have you considered using the SpriteSheetBuilder class? Creating a single SpriteSheet behind the scenes, and then generating Sprites using it would give you performance gains, since only a single bitmap would be used behind the scenes.
http://www.createjs.com/docs/easeljs/classes/SpriteSheetBuilder.html