Change an object's image file

Hello,

I have a problem with image files.

I create a display object (background) with an image file (image1.png). I make this object scroll and once it is out of the screen, I need to put it back at the top but with another image. For doing that, I use background:removeSelf() and then I display the object background with the second image file (image2.png). With this everything works fine, but once I test the game, I see that it slightly stops for some time while removing the file, and then continues. I am a bit afraid because the background is not moving smoothly.

Is there any other way to change the image file of an object?

P.S. If I don’t remove the object with removeSelf and display the image image2.png in the object directly, the first image (image1.png) does not remove (it is still displayed without movement). So I imagine it will take a lot of the device’s memory.

Thank you [import]uid: 40363 topic_id: 9848 reply_id: 309848[/import]

Without further information on what you’re trying to achieve, we can’t fully help you. But my advice would be to not remove and display the images but if it’s always gonna be the same two images, just hide one while you make the other one visible. [import]uid: 51516 topic_id: 9848 reply_id: 35898[/import]

You could try making the image name a variable which you could change/update. [import]uid: 33866 topic_id: 9848 reply_id: 35899[/import]

As long as it doesn’t use too much memory, you could try displaying the new image on top of the old one before removing the old one just after that. [import]uid: 27119 topic_id: 9848 reply_id: 35912[/import]

Hi,

thanks for the quick reply. I’ll try to explain what I am trying to do.

I manage 18 images as background to scroll randomly (full screen size) so I thought that having the 18 objects, even if the are hiden or outside the screen limits, it would take a lot of memory.

So I am working with two objects, background1 and background2. The scroll is going from the top of the screen to the bottom. When the first object (i.e. background1) gets out of the screen borders, I remove it and I create it again on top of background2, with a new image (randomly chosen).

If I could only change the image file without removing the object, I might not get the scroll stops while removing the object…

I hope I explained myself.

Thank you
[import]uid: 40363 topic_id: 9848 reply_id: 35914[/import]

cl-apps: Yes, I wanted to do that, but I have no idea how to code this. I would appreciate much if you could write a small example.

drewns: that would be great, but again I have no idea how to code your idea…

Thank you [import]uid: 40363 topic_id: 9848 reply_id: 35915[/import]