I have a problem when I release the button in the shoot function
local widget = require( "widget" ) \_W = display.contentWidth \_H = display.contentHeight player= display.newRect(110,110,70,40) local function moveBullet(obj) if obj.x \< \_W+20 then obj.x = obj.x + 8 obj:toBack() else obj:removeSelf() Runtime:removeEventListener("enterFrame",obj) obj = nil end end function mBullet() local bullet = display.newCircle(0,0,5) bullet.x =player.x + 20 bullet.y = player.y bullet.enterFrame = moveBullet Runtime:addEventListener("enterFrame",bullet) end function shoot(e) local function coolDown() B1:addEventListener("touch",B1.onEvent) end if e.phase == "began" then mBullet() mShot = timer.performWithDelay(500,mBullet,0) elseif e.phase == "ended" then timer.cancel(mShot) B1:removeEventListener("touch",B1.onEvent) coolDownTime = timer.performWithDelay(500,coolDown,1) end end B1 = widget.newButton { width = 80, height = 80, defaultFile = "shootButton.png", overFile = "shootButtonPress.png", onEvent = shoot } B1.x = \_W-55 B1.y = \_H-50 B1.anchorX, B1.anchorY =0.5, 0.5