I have the following objects in m app:-
1- Array of flyingObjects
2- SpaceShip Object
3- bounceObject (basically its a rocket moving on the screen)
I would like to perform variety of actions/functions based on each collision that would occur between any 2 objects as follow and would like to know how can i do that in my Runtime event listener (Runtime:addEventListener(“collision”, onCollision)
note: collision between flyingObject and BounceObject will not be counted (those are the enemies)
I have defined each object creation in a separate function as follow:-
- displaySpaceShip()
- dislayBounceObject()
- displayFlayingObject()
- displayBullet()
for each function i have added the following collision definition:-
For spaceShip:-
spaceShip.collision = onCollision
spaceShip:addEventListener( “collision”, spaceShip )
For flyingObject:-
flyingObject.collision = onCollision
flyingObject:addEventListener( “collision”, flyingObject )
For BounceObject:-
bounce.collision = onCollision
bounce:addEventListener( “collision”, bounce )
For BounceObject:-
bullet.collision = onCollision
bullet:addEventListener( “collision”, bullet )
I need to know whats wrong in the following code and if possible how it could be fixed:-
function onCollision( self,event )
print( "Collision: Self: “…self.objectName…” & Other: "…event.other.objectName)
ipointerX = event.other.x
ipointerY = event.other.y
if ( event.phase == “began” ) then
totalKilled =totalKilled + 1
nemesisObject.text = "Killed Nemesis: " … totalKilled
if ( event.other.objectName == “bullet” ) and ( self.objectName == “bounce” ) then
levelCounter[1] = levelCounter[1] + 1500
else
levelCounter[1] = levelCounter[1] + 100
end
scoreObject.text = "Score: "…levelCounter[1]
timer.performWithDelay(100, library.DisplayCounter,1)
if ( event.other.objectName == “spaceShip” ) then
event.other:play({loop=2, remove=true}) – stop spaceShip Animation
else
– remove the bullet
end
self:removeSelf() – flyingObject
if ((event.other.objectName == “spaceShip”) or (self.objectName == “spaceShip”)) then
if ( event.phase == “began” ) then
library.playBombAnimation()
remainingSouls = remainingSouls - 1
cancelTransition = true
Runtime:removeEventListener(“enterFrame”, library.shakeNemesis)
objectBackground:addEventListener(“touch”, resumeGame)
end
end
end
end
[import]uid: 11038 topic_id: 3907 reply_id: 303907[/import]

[import]uid: 11038 topic_id: 3907 reply_id: 12615[/import]