Getting A Grip on Images

Hey Corona experts, I’m slowly getting up to speed with Corona after using GameSalad and am trying to get a handle on how to deal with images. Hoping I can get a few questions answered (sorry if this stuff is already answered somewhere):

  • Once you’ve created an image instance, ie display.newImage(), is it possible to change the filepath for that image? Or is the “Corona way” of doing things to remove that image from memory and create a whole new instance? (can’t find any reference to this in the docs)

  • Related to the above, if multiple images are created, is it possible to relayer/reorient the stacking order of the images?

  • Is there any threshold for how far an image can be moved offscreen? In GameSalad, if an image moves beyond something like 200 pixels offscreen, it automatically gets destroyed. Does Corona have any kind of behavior like this?

Thanks in advance for your help. [import]uid: 6756 topic_id: 4430 reply_id: 304430[/import]

I believe you need to destroy and recreate. I will put in a .source/.load feature request.

There is a new tofront and toback layer function but for z indexing you’ll need to create your own sort routine using this and the insert function

I believe you need to manage your own “offscreen object” removal, but I don’t know of any specific limit for the x value. Not tried though so not done any performance tests around this [import]uid: 6645 topic_id: 4430 reply_id: 13816[/import]

  1. when an image is uploaded, you can rotate/relayer/ the image stack.
  2. corona optimizes image loading, so if you load the same image twice or trice or 100 times, it just loads it once.
  3. corona optimizes isVisible flag. if you set isVisible to false, it will not eat OGL texture memory but it will be around until you nil the value so that it gets garbage collected or you can call removeSelf() to destroy.

i don’t quite follow “once you’ve created an image instance, ie display.newImage(), is it possible to change the filepath for that image?”

c. [import]uid: 24 topic_id: 4430 reply_id: 13908[/import]

Thanks jmp909 and carlos.

@carlos: I’m used to dev environments where images are discrete objects, essentially display objects, whose filenames can be changed, and thus the content they display gets updated. So I’m trying to understand how Corona is handling/managing images and how to best work with it.

I’m no low-level programmer for sure, but it seems like it could be more efficient to be able to establish an image once, and allow it to act as a display container with changeable content, rather than having to remove the image and create a new one every time I want to display something new in the same location.

Regarding removeSelf(), I found this among the examples:
local sun = solarSystem.sun
sun.parent:remove( sun ) – remove image from hierarchy
solarSystem.sun = nil – remove sun as a property of solarSystem

Is there a separate removeSelf function or were you referencing a generic function that would do the above?

Thanks again for the pointers.

  • Scott [import]uid: 6756 topic_id: 4430 reply_id: 13923[/import]

i don’t quite follow “once you’ve created an image instance, ie display.newImage(), is it possible to change the filepath for that image?”

Carlos he means in javascript for instance you can set

[javascript]
myImageInstance.src = “myNewImage.png” // change from current “myImage.png”
[/javascript]
[import]uid: 6645 topic_id: 4430 reply_id: 13924[/import]

Ah.

Nope. Not allowed in Corona.

Carlos. [import]uid: 24 topic_id: 4430 reply_id: 13925[/import]

Hey netdzynr,

You cannot change the image property of a display object.

To make something like a button, with an up state/over state, you can use the Movieclip class.
(it’s not something built into Corona, but a separate file you need to download. Let me know
if you cannot find it on the site and I can email it to you.)

You would use it like this:

local myButton = movieclip.newAnim{image1.png, image2.png}  

And then in your button code, you would call something like this:

myButton.stopAtFrame(2) -- over state  
myButton.stopAtFrame(1) -- regular state  

An even better way is to use a sprite sheet, and just shift the image to the appropriate spot.
That way you only load in the image once.

I am still using movieclips however, as it’s easier for me to manage. The code’s a little simpler.

There is a library that merges the two (the performance of a sprite sheet, with the code simplicity of a movieclip) on the shared code page, that might be worth checking out too.

Joe
[import]uid: 8444 topic_id: 4430 reply_id: 13929[/import]

Thanks FMG. Those are good options to know but I need to be able randomly access any of 20 full screen images, one at a time, so I better stick with the load and destroy method to keep memory requirements down. I think. [import]uid: 6756 topic_id: 4430 reply_id: 13936[/import]

New to Corona myself, just bought into recently and trying to switch from GS.
This post alone was helpful :slight_smile:

I’m trying to grasp the simple concept of changing a scene to the next scene or image to image after a tap.
or after 3 seconds then change picture.

This seems to be pretty helpful i think - http://developer.anscamobile.com/code/director-class-10

Anyone care to create a document that shows crossover examples from GS to Corona ? :slight_smile:

like Change Attribute game.random - random (0,50)

Rule if game.random = 5
spawn actor or show image.

Really liking how fast Corona is and just the depth of features available, just wish i knew how to use them.
But just like i did with GS, i should be able to learn this.

[import]uid: 10758 topic_id: 4430 reply_id: 14018[/import]