Best Practices - display.newImage

Best practices question. If i want to load an image and later switch it out with another… is utilizing the removeSelf( ) function the best way to go about it. For example:

myImage   = display.newImage( “image1.png” )

myImage.x = 100; myImage.y = 100

(unimportant stuff happens here but some time passes)

myImage:removeSelf( )

myImage   = display.newImage( “image2.png” )

myImage.x = 150; myImage.y = 100

Or is there a better way from a resource management, efficiency standpoint?

It depends on the size of the images and your max texture size, but having your images combined into an “image sheet” and then treating it as a sprite would be the most efficient resource wise.  See:
 

http://www.coronalabs.com/blog/2013/05/14/sprites-and-image-sheets-for-beginners/

I completely agree. I use spritesheets all of the time. But, in the case where you simply want to replace one image for another, say for an image viewer where you are loading images dynamically, how do you handle the refresh best. Would adding a line like myIm age = nil after removeSelf be best practice?

Yes, then that technique will work, just make sure to do myImage = nil after the removeSelf()

Thanks!

It depends on the size of the images and your max texture size, but having your images combined into an “image sheet” and then treating it as a sprite would be the most efficient resource wise.  See:
 

http://www.coronalabs.com/blog/2013/05/14/sprites-and-image-sheets-for-beginners/

I completely agree. I use spritesheets all of the time. But, in the case where you simply want to replace one image for another, say for an image viewer where you are loading images dynamically, how do you handle the refresh best. Would adding a line like myIm age = nil after removeSelf be best practice?

Yes, then that technique will work, just make sure to do myImage = nil after the removeSelf()

Thanks!