Right now I am making a simple game; there is a cannon that shoots machinegun bullets at the upcoming viruses. However, the problem is that I want to make the gun shoot continuously when the screen is pressed (towards that location). However, the cannon only seems to shoot bullets when the finger is moved (when the finger is stationary it doesn’t shoot at all). Here’s part of the code:
[code]
function touched( event )
if( event.phase == “began” ) then
Runtime:addEventListener(“enterFrame”, shootMachinegun)
if bulletType == normal then
createBullet(0.5 * sr)
end
end
if (event.phase == “ended”) then
if bulletType == machinegun then
Runtime:removeEventListener(“enterFrame”, shootMachinegun)
end
end
local function shootMachinegun()
– we set the aim to where we touched
aim.x = event.x
aim.y = event.y
– make the cannon face the right direction!
directionX = aim.x - cannon.x
directionY = aim.y - cannon.y
cannon.rotation = math.deg(math.atan2(directionY,directionX)) + 90
– if the bulletType is machineGun
if bulletType == machinegun then
– important, bulletDuration sets the speed of the bullet firing.
– for example, if bulletDuration = 3, one bullet is fired every 3 frames
if bulletDurationCheck == 3 then
createBullet(1 * sr)
bulletDurationCheck = 0
else bulletDurationCheck = bulletDurationCheck + 1
end
end
end
end
[/code] [import]uid: 73204 topic_id: 15687 reply_id: 315687[/import]
[import]uid: 3826 topic_id: 15687 reply_id: 57904[/import]