Changing an objects image during runtime

So here is a little issue I've run in to.

The idea was to touch the screen and the players image would change.
So to start out we have something like;

1
player = display.newImage("rock.png")

You can set player.isVisible = true when you want to see it and set player.isVisible = false when you don't want to see it.

Do the same for the other 2 players based on which one you want to be seen.

Yeah that was the first thing we tried, however the player physics objects continue to bump in to each other even when not visible.

I think sprite sheets are definitely the best way to achieve this.

Haven't played with them much yet myself, but pretty sure you can set which frame is displayed and wire that up to change on touch.

Sorry I don't have any code for you.

I've a few things to iron out in the project I'm surrently working on before I start actually animating my hero, but will post some code in a few days if you haven't solved it by then.

Perhaps you could use a movieclip for the image and simply change the movie clip frame.

See http://developer.anscamobile.com/content/movieclips

1
2
3
4
5
6
7
player = movieclip.newAnim{ "playerImage1.png", "playerImage2.png", "playerImage3.png" }
 
...
 
-- Change the players image to "playerImage2.png"
 
player:stopAtFrame(2)

If you want to use an Image, you have to remove it and load a new one, there is no easy way to *swap* objects/images

cheers,

?:)

views:1571 update:2011/10/18 15:01:22
corona forums © 2003-2011