Hi guys,
I’m currently making a tap to shoot game (like the shooting mechanism from Ridiculous Fishing).
I’m wondering if there’s any way to create a delay for the touch eventlistener? Like let say a handgun will fire every 2 seconds while a machine gun fires every 500ms.
Here’s the code I’m currently using
function touchHandler(event) event.target.myLife = event.target.myLife - 1 print(string.format("Target Life : %d", event.target.myLife)) end function spawnObjects() fallingObjectsArray[fallingObjectsCount] = gameobjects:createFallingObject(choice) fallingObjectsArray[fallingObjectsCount].x = math.random(40, display.contentWidth / 2 - 40) fallingObjectsArray[fallingObjectsCount].y = 10 fallingObjectsArray[fallingObjectsCount]:addEventListener("touch", touchHandler) fallingObjects:insert(fallingObjectsArray[fallingObjectsCount]) end
I tried using timer.performWithDelay but it causes the game to go haywire.
If anyone has a better way of implementing the shooting function, please let me know. I noticed that in Ridiculous Fishing you need to tap (when using handguns) while you can touch and hold when using machine guns. I’m trying to replicate that.
Any help is very much appreciated. Thanks!