Hiding Images vs Removing Images

After spending some time watching a few tutorials, and reading through the api docs, I think I understand how to remove a displayed object:
Question, Is it removed from memory too?

local someImageDisplayed = display.newImage("pathToMyImage.png");  
  
function someImageDisplayed:touch(e)  
 self:removeSelf();  
end  
  
Runtime:addEventListener("touch", someImageDisplayed);  

So, that works well, and I’m wondering if there’s a way to just hide the image, besides removing it.
The only thing I could imagine was using object:toBack(); And if I wanted to display the image again, I’d move it to the front.

Is there a hide method I’m not seeing? [import]uid: 154122 topic_id: 27316 reply_id: 327316[/import]

Yes if you use display.remove (obj) or obj:removeSelf() then you do obj = nil, it will remove the object from memory

for instance
[lua]if obj then
display.remove (obj)
obj = nil
end[/lua]
that will remove the object from the display and remove the reference to it.

As for how to hide an object, there are two ways that i use.
1.) if the object is a touch object and you still want to be able to touch it and not see it then you can just set the alpha of the object really low i.e. obj.alpha = 0.01

2.) if you want to hide an object completely and hide its touch function also you can use .isVisible. For instance:

[lua]–Hide the Object
obj.isVisible = false

–Show the Object
obj.isVisible = true[/lua] [import]uid: 126161 topic_id: 27316 reply_id: 111004[/import]

So, obj = nil erases the reference to it completely, but if I don’t include it then the scripting just stops displaying the obj only?

I didn’t know obj.isVisible existed. Thanks!

This does make me wonder about loading several images into memory, and not displaying them right away. (I don’t need sprites for what i’m working with)
Currently here’s what I will do, unless you recommend differently:

local myImage1 = display.newImage("pathtoimage1.png");  
local myImage2 = display.newImage("pathtoimage2.png");  
  
myImage1.isVisible = false;  
myImage2.isVisible = false;  
  
--display hidden images later on, depending on touch events  

[import]uid: 154122 topic_id: 27316 reply_id: 111007[/import]

Yes you would need to remove the display object AND nil out the reference to it exactly as you said above.

Typically with win/lose/pause/inventory and really any screen that might be reused in a scene i load at the beginning of the scene and hide them with isVisible until i need them. i.e for a pause screen i would load them at the beginning of the scene and set their isVisible to true when the user pauses the game and then set their isVisible to false when the user continues the game.

One suggestion to look into that is unrelated to your question would be using newImageRect instead of newImage for the best image quality for all devices, its very good to learn at the beginning so you are not redoing all your art work to make your game look good on the new ipad. There is alot of info on this on the forum. [import]uid: 126161 topic_id: 27316 reply_id: 111010[/import]

You make a very good points about game development, and the scenes involved.
I’ll take your advice about newImageRect. It’s true, I’m not quite paying attention to image quality using the newImage method. [import]uid: 154122 topic_id: 27316 reply_id: 111012[/import]