I’m actually curious how to go about doing this too. Because when you create a movieclip in Corona, the creation can be slow. So I’d like to duplicate the movieclip object if I need more than one, rather than making it off a new object… [import]uid: 6678 topic_id: 1411 reply_id: 4347[/import]
Looking at the sample code it would seem that there’s no way to clone instances of DisplayObjects. For example, the Fishies demo repeatedly loads the same graphic file for multiple sprites. I tried adding the same Display object repeatedly to a group object in different positions but that simply moves the single instance rather than creating multiple instances. SpriteSets in the Game API may emulate this functionality but that API is a bit broken at the moment. [import]uid: 3953 topic_id: 1411 reply_id: 4549[/import]
The actual graphic bitmaps are cached for DisplayObjects, so loading an image twice re-uses the same texture. [import]uid: 54 topic_id: 1411 reply_id: 5248[/import]
I realised from looking at some of Matthew Pringle’s excellent code samples that you can in fact use all frames in the spritesheet statically. Just ignore the animation calls:
local sheet = sprite.newSpriteSheet(imageFile, cellsAcross , cellsDown)
local spriteSet = sprite.newSpriteSet(sheet, 1, cellsAcross \* cellsDown)
sprite.add(spriteSet, "myImages", 1, cellsAcross \* cellsDown, 1, 0)
-- then reference each image from within the texture atlas
local instance = sprite.newSprite(spriteSet)
instance.currentFrame = index\_into\_image\_grid
-- cellsDown and cellsAcross can be anything from 1 to imageWidth and imageHeight respectively
When I got a crash on calling :prepare() I gave up until I saw his latest demoEngine code. [import]uid: 3953 topic_id: 1411 reply_id: 5249[/import]
Thanks Eric. That’s handy to know. Does that mean that Corona keeps a table of the source filenames and simply points to the same texture memory when a multiple load is done on the same file? [import]uid: 3953 topic_id: 1411 reply_id: 5250[/import]