Ok,
I am now at the stage of pulling my hair out.
I have been plodding slowly and resolving issues as I go along but seem to have hit a wall.
I will try my best to describe the help I need.
I have an animated bird on screen. (main player)
I have a leaf which transitions across the screen and strikes the main player object.
I have set up a simple collision detection here:
local bird = display.newSprite( sheet, { name="bird", start=1, count=9, time=1000 } )
bird.x = display.contentWidth / 4 + 40
bird.y = baseline - 120 --set height from baseline
bird.xScale = 1
bird.yScale = 1
bird:play()
physics.addBody(bird, "dynamic")
physics.setGravity(0,0)
bird.myName = "bird"
ground.myName = "ground"
bird:addEventListener("collision", bird)
function bird:collision (event)
if event.other.myName == "ground" then
print "bird hit the ground!"
end
end
and this for the object:
--add leaf
local leaf = display.newImage( "images/leafs.png" )
physics.addBody(leaf, "dynamic")
local w,h = display.viewableContentWidth, display.viewableContentWidth
leaf.myName = "leaf"
leaf:addEventListener("collision", leaf)
function leaf:collision (event)
if event.other.myName == "bird" then
print "leaf hit the bird!"
end
end
transition.from( leaf, { time=4000, x=(w+400), y=(h-300), onComplete=function () leaf:removeSelf()end ;})
all this works nicely, I have also implemented an analogue joystick for the bird, and parallax scrolling the the background. The collision events are working in the terminal.
Question is can someone tell me how to on collision the leaf will destroy itself and replace itself with a new sprite (exploding stars).
It must be pretty simple and any help will be much appreciated, I would even consider a payment to someone so I can move forward with this.
Thanks
[import]uid: 127675 topic_id: 30147 reply_id: 330147[/import]