Movie Clip / Image Duplication in Lua?

I’ve got the following line in flash, which allows me to spawn multiple instances of a movie clip/ image programmatically:


for(i=1;i<=5;i++)
{
_root[“face”].duplicateMovieClip(“face”+i,i+1000,face);
}


Anyone with clues on how to get the same thing accomplished in Lua/Corona? I’ve been checking out this sample code for a clue:

http://developer.anscamobile.com/forum/2009/12/09/simple-parallax-starfield-or-use-it-snow-freshworks

Any help would be appreciated. Many Thanks! [import]uid: 4258 topic_id: 1411 reply_id: 301411[/import]

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]

Extra question: is it the same with spritesheets? If you create another with the same filename does it point to the same texture memory?

Thanks. [import]uid: 3953 topic_id: 1411 reply_id: 5436[/import]