how to change file of an image in display.image

hi.
in my project i have an image i open it like this :

object = display.newImage( “pics/list/fog/grafity 2.png”)

i want to chenge the image to another image but don’t want to delete the object veriable (it will stop the event listener)
how can i change the file in the image without using display.remove then open it again …
somthing like
object:file (“your second file”)

does anybody know ?

thank you …

[import]uid: 173648 topic_id: 32568 reply_id: 332568[/import]

I did not find any way to do this so I actually tie my events to a display.newRect, put the image on top of this rectangle. When I need to change the image, I would do object.removeSelf() then object = display.newImage(…) [import]uid: 97768 topic_id: 32568 reply_id: 129470[/import]

There’s no way to change the image displayed by display.newImage() normally.

The simplest alternative is to use graphics.newImageSheet() and make sure the images you need to switch between are in the same file. Then you can use setFrame() to switch as needed. But obviously it’s not ideal. Sounds like you have an OK method too. [import]uid: 41884 topic_id: 32568 reply_id: 129474[/import]

I kinda wish Corona Labs hadn’t unblessed the old movieclip.lua module. You basically ended up with a display object with multiple images and you could choose to play which ever one you wanted or do simple multi-frame animations with it. I know image sheets are more efficient the new coolness, but I liked the simplicity that movieclip gave us.

You can probably google around and find the movieclip.lua file or find a version in the Community Code. [import]uid: 19626 topic_id: 32568 reply_id: 129477[/import]

I did not find any way to do this so I actually tie my events to a display.newRect, put the image on top of this rectangle. When I need to change the image, I would do object.removeSelf() then object = display.newImage(…) [import]uid: 97768 topic_id: 32568 reply_id: 129470[/import]

There’s no way to change the image displayed by display.newImage() normally.

The simplest alternative is to use graphics.newImageSheet() and make sure the images you need to switch between are in the same file. Then you can use setFrame() to switch as needed. But obviously it’s not ideal. Sounds like you have an OK method too. [import]uid: 41884 topic_id: 32568 reply_id: 129474[/import]

I kinda wish Corona Labs hadn’t unblessed the old movieclip.lua module. You basically ended up with a display object with multiple images and you could choose to play which ever one you wanted or do simple multi-frame animations with it. I know image sheets are more efficient the new coolness, but I liked the simplicity that movieclip gave us.

You can probably google around and find the movieclip.lua file or find a version in the Community Code. [import]uid: 19626 topic_id: 32568 reply_id: 129477[/import]

I think the “newSprite” method is fine for this now, especially since we no longer need to “require” in the outdated sprite library. A “newSprite” is effectively just a display object… closely related and initiated using image sheets… the only additional step being to create a table of sequence data. Once you have it, you can then switch “frames” just like you need to. Just discard the impression that it’s an “animated sprite”. :wink:

Brent [import]uid: 9747 topic_id: 32568 reply_id: 129611[/import]

Also I should note: @richard9 indicated that you can use “setFrame” on an image. This isn’t quite correct… the image must be a sprite for that function to work, because a sprite has a linked sequence which allows Corona to know its frame setup. I’ve seen this confusion occur several times in the forums, so it’s worth repeating here.

Brent [import]uid: 9747 topic_id: 32568 reply_id: 129612[/import]

I think the “newSprite” method is fine for this now, especially since we no longer need to “require” in the outdated sprite library. A “newSprite” is effectively just a display object… closely related and initiated using image sheets… the only additional step being to create a table of sequence data. Once you have it, you can then switch “frames” just like you need to. Just discard the impression that it’s an “animated sprite”. :wink:

Brent [import]uid: 9747 topic_id: 32568 reply_id: 129611[/import]

Also I should note: @richard9 indicated that you can use “setFrame” on an image. This isn’t quite correct… the image must be a sprite for that function to work, because a sprite has a linked sequence which allows Corona to know its frame setup. I’ve seen this confusion occur several times in the forums, so it’s worth repeating here.

Brent [import]uid: 9747 topic_id: 32568 reply_id: 129612[/import]