Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Movie Clip / Image Duplication in Lua?
Started by soclean Jul 13 2010 11:17 PM

- - - - -
6 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

soclean

[GLOBAL: userInfoPane.html]
soclean
  • Observer

  • 13 posts
  • Corona SDK

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!
uid: 4258 topic_id: 1411 reply_id: 301411


[TOPIC: post.html]
#2

DFox

[GLOBAL: userInfoPane.html]
DFox
  • Contributor

  • 139 posts
  • Corona SDK

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...
uid: 6678 topic_id: 1411 reply_id: 4347


[TOPIC: post.html]
#3

MarkHenryC

[GLOBAL: userInfoPane.html]
MarkHenryC
  • Contributor

  • 181 posts
  • Corona SDK

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.
uid: 3953 topic_id: 1411 reply_id: 4549


[TOPIC: post.html]
#4

Eric

[GLOBAL: userInfoPane.html]
Eric
  • Contributor

  • 485 posts
  • Guests

The actual graphic bitmaps are cached for DisplayObjects, so loading an image twice re-uses the same texture.
uid: 54 topic_id: 1411 reply_id: 5248


[TOPIC: post.html]
#5

MarkHenryC

[GLOBAL: userInfoPane.html]
MarkHenryC
  • Contributor

  • 181 posts
  • Corona SDK

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.
uid: 3953 topic_id: 1411 reply_id: 5249


[TOPIC: post.html]
#6

MarkHenryC

[GLOBAL: userInfoPane.html]
MarkHenryC
  • Contributor

  • 181 posts
  • Corona SDK

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?
uid: 3953 topic_id: 1411 reply_id: 5250


[TOPIC: post.html]
#7

MarkHenryC

[GLOBAL: userInfoPane.html]
MarkHenryC
  • Contributor

  • 181 posts
  • Corona SDK

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.
uid: 3953 topic_id: 1411 reply_id: 5436



[topic_controls]
[/topic_controls]