Is there a way to duplicate an instance of a sprite?

If I am loading 2 sprites:
local redBalloon = display.newImageRect( “images/balloonRed.png”, 64, 64 )

local blueBalloon = display.newImageRect( “images/balloonBlue.png”, 64, 64 )

and I want to show many of them on the screen, do I need to load each one separately?

Thanks
Yalon
 

  1. Those are not actually sprites.  They are display objects of the type imageRect that display a texture on screen.

This function creates a sprite (used for animations typically):  https://docs.coronalabs.com/api/library/display/newSprite.html

  1. You’re not loading them per se.  That is, the first time you use a texture, it gets loaded into texture memory, but after that, any objects created that use the texture, will get the reference from texture memory directly (until it gets unloaded later).

  2. For each image you wish to display on the screen, you need to ‘create’ it.

There is a great guide here on textures, caching,etc. here: https://docs.coronalabs.com/guide/graphics/textureManagement.html 

  1. Welcome to the community.  Please use the forums tools to format code posts in the future.  It was no big deal in this case, but large posts can be hard to read if not formatted.

formatyourcode.jpg

  1. Are you taking a class that uses Corona?  I ask because there was a similar question recently and it helps us (me) to know the basis/source of your question.

Hi roaminggamer

Thank you very very much for the detailed info

I don’t take any class that uses Corona, I try to learn it by myself and I use this forum occasionally - Corona I see has a great community

Yalon

  1. Those are not actually sprites.  They are display objects of the type imageRect that display a texture on screen.

This function creates a sprite (used for animations typically):  https://docs.coronalabs.com/api/library/display/newSprite.html

  1. You’re not loading them per se.  That is, the first time you use a texture, it gets loaded into texture memory, but after that, any objects created that use the texture, will get the reference from texture memory directly (until it gets unloaded later).

  2. For each image you wish to display on the screen, you need to ‘create’ it.

There is a great guide here on textures, caching,etc. here: https://docs.coronalabs.com/guide/graphics/textureManagement.html 

  1. Welcome to the community.  Please use the forums tools to format code posts in the future.  It was no big deal in this case, but large posts can be hard to read if not formatted.

formatyourcode.jpg

  1. Are you taking a class that uses Corona?  I ask because there was a similar question recently and it helps us (me) to know the basis/source of your question.

Hi roaminggamer

Thank you very very much for the detailed info

I don’t take any class that uses Corona, I try to learn it by myself and I use this forum occasionally - Corona I see has a great community

Yalon