[lua] function dartRotation (self,event)
self.rotation = self.rotation - self.roSpeed
end
enemyDartGroup = display.newGroup ()
–enemyGroup.anchorChildren = true
screenGroup:insert (enemyDartGroup)
function moveEnemy ()
for a = enemyDartGroup.numChildren, 1, -1 do
if ( enemyDartGroup[a].x > -120 ) then
enemyDartGroup[a].x = enemyDartGroup[a].x - 2
else
enemyDartGroup[a]:removeEventListener (“enterFrame”, dartRotation)
enemyDartGroup:remove (enemyDartGroup[a])
enemyDartGroup[a] = nil
end
end
end
function spawnDart ()
dart = display.newImageRect (“media/images/dart.png”, 40, 40)
dart.x = w * 0.5; dart.y = h * 0.5
physics.addBody (dart, “static”, physicsData:get(“dart”))
dart.roSpeed = 5
screenGroup:insert (dart)
enemyDartGroup:insert (dart)
screenGroup:insert (enemyDartGroup)
dart.enterFrame = dartRotation
Runtime:addEventListener (“enterFrame”, dart)
if dartMoving == false then
print (“dart is now moving”)
dartMoving = true
moveDartTmr = timer.performWithDelay ( 15, moveEnemy, -1 )
end
end[/lua]
I have something moving out from the screen, like flappy bird’s pipe
but, the thing was on the dartRotation function, and every time the thing is going to remove,
Attempt to perform arithmetic on field ‘rotation’ (a nil value) which is this lane
[lua] function dartRotation (self,event)
self.rotation = self.rotation - self.roSpeed
end
[lua]
After that, I added enemyDartGroup[a]:removeEventListener (“enterFrame”, dartRotation) to stop the rotation.
it doesn’t help also.
What i want to do is the dart will rotation after it spawns, and move the dart.x - 2.
When the dart is < -120 then remove itself and stop rotating.
but now when the dart is going to remove itself has a problem in dartRotation function
what am i do wrong here?