I know this is because of my poor coding skills but can someone help me,I’m trying to make it when the player collides with object2, 15 bonus objects will spawn. But I’m doing something wrong >:(
[code]
function objectSpawn()
object = display.newImage(“object.png”)
object.x = 510
object.y = math.random(0,280)
localGroup:insert(object)
transition.to (object, {time=3500, x=-50})
physics.addBody(object, {bounce=0.6})
object.angularVelocity = math.random(-200,200)
object.myName = “object”
object.collision = onobjectCollision
object:addEventListener(“collision”, object)
end
function onobjectCollision ( self,event )
if ( event.phase == “began” ) then
if ( self.myName == “object” ) then
if ( event.other.myName == “player” ) then
playGood()
score.setScore( score.getScore() + 25 )
self:removeSelf()
elseif (event.other.myName == “leftwall”) then
self:removeSelf()
end
end
end
end
timer1 = timer.performWithDelay( 1000, objectSpawn, 0 )
function object2Spawn()
object2 = display.newImage(“object2.png”)
object2.x = 510
object2.y = math.random(0,280)
localGroup:insert(object2)
transition.to (object2, {time=3500, x=-50})
physics.addBody(object2, {bounce=0.6})
object2.angularVelocity = math.random(-200,200)
object2.myName = “object2”
object2.collision = onobject2Collision
object2:addEventListener(“collision”, object2)
end
function onobject2Collision ( self,event )
if ( event.phase == “began” ) then
if ( self.myName == “object2” ) then
if ( event.other.myName == “player” ) then
playGood()
self:removeSelf()
– Bonus Object
function bonusspawn(event)
bonus = display.newImage(“bonusobject.png”)
bonus.x = 510
bonus.y = math.random(0,280)
localGroup:insert(bonus)
transition.to (bonus,{timer=3500, x=-50})
physics.addBody (bonus, {bounce=0.6})
bonus.angularVelocity -math.random(-200,200)
bonus.myName = “bonus”
bonus.collision = onBonusCollision
bonus:addEventListener(“collision”, bonus)
end
function onBonusCollision (self,event)
if event.phase == “began” then
if self.myName == “bonus” then
if event.other.myName == “player” then
playGood()
score.setScore( score.getScore() + 50 )
self:removeSelf()
elseif event.other.myName == “leftwall” then
self:removeSelf()
end
end
end
end
bonustimer = timer.performWithDelay( 300, bonusspawn, 15 )
elseif (event.other.myName == “leftwall”) then
self:removeSelf()
end
end
end
end
timer2 = timer.performWithDelay( 1000, object2Spawn, 0 ) [import]uid: 114389 topic_id: 26494 reply_id: 326494[/import]
[import]uid: 52491 topic_id: 26494 reply_id: 107574[/import]