local B1 = display.newCircle(0, 0, 40) B1:setFillColor(0.5) B1.x = 100 B1.y = 100 B1.anchorX, B1.anchorY =0.5, 0.5 function moveBullet(obj) if obj.y \> 0 then obj.y= obj.y + 6 obj:toBack() else obj:removeSelf() Runtime:removeEventListener("enterFrame",obj) obj = nil end end function Bullet() bullet = display.newCircle(0,0,5) bullet.x =200 bullet.y = 200 bullet.enterFrame = moveBullet Runtime:addEventListener("enterFrame",bullet) end function coolDown() B1:addEventListener("touch",shoot) end function shoot(e) if e.phase == "began" then Bullet() mShot = timer.performWithDelay(500,Bullet,0) elseif e.phase == "ended" then timer.cancel(mShot) B1:removeEventListener("touch",shoot) timer.performWithDelay(450,coolDown,1) end end B1:addEventListener("touch",shoot)
How to keep the same distance between the bullets and bullet?The performWithDelay of coolDown have problem.