Changing Picture

How can I change a picture to another picture on collision? In my game, there is an object that is falling, and I want the object to change to another picture when it hits another object. I already have the collision set up, I just want to know what to type where the collision starts. Here is what I have:

[code]
–START PHYSICS
local physics = require(“physics”)
physics.start()

–CREATE OBJECTS
local ball = display.newImage(“ball.png”)
physics.addBody( ball, { density=0.9, friction=0.3, bounce=0.3} )

local object = display.newImage(“object.png”)

–COLLISION

local function onLocalCollision( self, event )
if ( event.phase == “began” ) then

–CHANGE BALL TO “otherball.png”

end
end

ball.collision = onLocalCollision
ball:addEventListener( “collision”, ball )

object.collision = onLocalCollision
object:addEventListener( “collision”, object )

[/code] [import]uid: 38001 topic_id: 11280 reply_id: 311280[/import]

You can’t change image once you have created image object, your only solution is to destroy current image object and create new object. [import]uid: 48521 topic_id: 11280 reply_id: 40946[/import]

On second thought, you can use sprite sheets to achieve what you want. You can change frames of sprite object on collision. [import]uid: 48521 topic_id: 11280 reply_id: 40948[/import]

Ok so how do I do that? Can you just write me a couple lines of code or something to show me? Thanks! [import]uid: 38001 topic_id: 11280 reply_id: 40951[/import]

You need to learn how to use spritesheets. It’s not easy to explain concept in few lines of code. Try going through sprites sample app. [import]uid: 48521 topic_id: 11280 reply_id: 40953[/import]

Have a look at movieClips first though, as I’m sure this can be done with them and the pain and suffering is greatly reduced :slight_smile:

– Chris [import]uid: 33866 topic_id: 11280 reply_id: 41014[/import]