I’m working on a side scrolling game and having so problems with the objects. So far, I have 3 objects. Object and Object2 move fine across the screen at a decent speed. But object3 moves at lightening speed. I don’t know why, I’m pretty sure it has the same coding as the first two? And if I add an Object4, that too will move across the screen at 100mph. I am very confused. Can anyone help?
[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
playBad()
score.setScore( score.getScore() + 25 )
self:removeSelf()
elseif (event.other.myName == “leftwall”) then
self:removeSelf()
elseif (event.other.myName == “rightwall”) then
self:removeSelf()
end
end
end
end
timer1 = timer.performWithDelay(1600, 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
playBad()
score.setScore( score.getScore() + 25 )
self:removeSelf()
elseif (event.other.myName == “leftwall”) then
self:removeSelf()
elseif (event.other.myName == “rightwall”) then
self:removeSelf()
end
end
end
end
timer1 = timer.performWithDelay(1800, object2Spawn, 0 )
function object3Spawn()
object3 = display.newImage(“object3.png”)
object3.x = 510
object3.y = math.random(0,280)
localGroup:insert(object3)
transition.to (object3, {time=3500, x=-50})
physics.addBody(object3, {bounce=0.6})
object3.angularVelocity = math.random(-200,200)
object3.myName = “object3”
object3.collision = onobject3Collision
object3:addEventListener(“collision”, object3)
end
function onobject3Collision ( self,event )
if ( event.phase == “began” ) then
if ( self.myName == “object3” ) then
if ( event.other.myName == “player” ) then
playBad()
score.setScore( score.getScore() + 25 )
self:removeSelf()
elseif (event.other.myName == “leftwall”) then
self:removeSelf()
elseif (event.other.myName == “rightwall”) then
self:removeSelf()
end
end
end
end
timer1 = timer.performWithDelay(2000, object3Spawn, 0 ) [import]uid: 114389 topic_id: 26296 reply_id: 326296[/import]