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..

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?)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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)

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....

Looks like a job for spriteInstance.currentFrame to me. See if this looks like what you need. Just advance the frame as needed.

Could you cite some examples where i can get in more details regarding this?I have a bit of hesitation in using sprites..

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

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.

Just threw this together, very simple demonstration;

http://techority.com/spritedemo.zip

Peach :)

views:1598 update:2011/12/30 9:10:41
corona forums © 2003-2011