changing image on collision

I want that my empty basket(that is a physics body) image should change to different image(say e.g.-basket1 then to basket2 and so on) on collision.Can anybody provide me a suitable solution for that?please… [import]uid: 82446 topic_id: 19131 reply_id: 319131[/import]

plug and play code, i hope it will help you
anyway, there’s plenty of ways to do that, this is just one of them and i doubt that its best of them, but still better than nothing right?)

[lua]local physics = require(“physics”)
physics.start()

local obj1 = display.newCircle(0,0,30)
physics.addBody(obj1)
obj1.x = 150
obj1.y = 50
obj1.name = “obj1”
local basket = display.newRect(0,0,60,60)
basket.x = 150
basket.y = 300
physics.addBody(basket, “static”)

local basket2 = display.newRect(0,0,30,30)
basket2.x = 150
basket2.y = 300
basket2.isVisible = false

local function onCollision(self, event)
if event.phase == “began” and event.other.name == “obj1” then

self:removeSelf()
self = nil

basket2.isVisible = true
local function one()
physics.addBody(basket2, “static”)
end
timer.performWithDelay(50, one,1)
end
end

basket.collision = onCollision
basket:addEventListener(“collision”, basket)[/lua]

[import]uid: 16142 topic_id: 19131 reply_id: 73738[/import]

Thanks for the reply .But the problem is that my object is moving .Now How can i have an moving object to change on collision?please help… [import]uid: 82446 topic_id: 19131 reply_id: 73740[/import]

Looks like a job for spriteInstance.currentFrame to me. See if this looks like what you need. Just advance the frame as needed. [import]uid: 21331 topic_id: 19131 reply_id: 73741[/import]

Could you cite some examples where i can get in more details regarding this?I have a bit of hesitation in using sprites… [import]uid: 82446 topic_id: 19131 reply_id: 73743[/import]

dont hesistate using sprites, they are great and easy to use
i would definetly reccomend using sprites, not only they great for what you need,but they can help you manage memory usage of device as well and performance [import]uid: 16142 topic_id: 19131 reply_id: 73748[/import]

Please provide me some samples example if you can except for the samples that are available in the Sample Code of corona if you can so that I can understand better. [import]uid: 82446 topic_id: 19131 reply_id: 73749[/import]

Just threw this together, very simple demonstration;

http://techority.com/spritedemo.zip

Peach :slight_smile: [import]uid: 52491 topic_id: 19131 reply_id: 73873[/import]