In my code I have a couple rats that when they get hit by an object, they change frame and get a score based on how hard they are hit. The harder hit removes them, frame three is a puff of smoke.
Did I do this correct? It does work.
My other question is the commented out destructionScore. I would like the score received to pop up angry birds like over the rat. But since I have multiple rats in different locations, I can’t figure out how to retrieve their x, y locations with out creating a different onRatCollision function for each rat. I don’t want to do that because I do have a bunch of other objects that I will be doing this type of onCollision to and it could end up being a lot of code.
Thanks
Dan
[code]
local Rathita = 0
local function onRatCollision ( self, event )
if Rathita == 0 then
if ( event.force > 30.0 ) then
self:stopAtFrame(2)
Rathita = 1
score = score + 15
t.text=score
end
end
if Rathita == 1 then
if ( event.force > 45.0 ) then
self:stopAtFrame(3)
self:removeEventListener( “postCollision”, self )
local function removeRat( event )
self:removeSelf()
end
timer.performWithDelay( 200, removeRat)
score = score + 150
t.text=score
– local destructionScore = display.newText(score, x, y, native.systemFont, 10 )
– destructionScore:setTextColor( 255, 0, 0)
– game:insert( destructionScore )
end
end
end
Rat1.postCollision = onRatCollision
Rat1:addEventListener( “postCollision”, Rat1 )
Rat2.postCollision = onRatCollision
Rat2:addEventListener( “postCollision”, Rat2 )
[/code] [import]uid: 78446 topic_id: 14080 reply_id: 314080[/import]

