Tap or Touch to Shoot Mechanism (Similar to Ridiculous Fishing)

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!

timer.performWithDelay is for scheduling something to be performed later, so that’s not really what you’re looking for.

I believe what you want to do is

  • Have a timestamp for the time when the last shot was fired

  • In the touch listener, only shoot (and renew the timestamp) if it’s been more than 2 seconds since the last firing, otherwise do nothing

Similar for the machinegun.

Trudat.

You could also link it to a graphic whereby a time bar fills when the tap occurs and slowly/quickly empties. The next shot will only take place if the bar has finished emptying.

@_memo @horacebury

Thanks for the tip. Will give it a shot. 

timer.performWithDelay is for scheduling something to be performed later, so that’s not really what you’re looking for.

I believe what you want to do is

  • Have a timestamp for the time when the last shot was fired

  • In the touch listener, only shoot (and renew the timestamp) if it’s been more than 2 seconds since the last firing, otherwise do nothing

Similar for the machinegun.

Trudat.

You could also link it to a graphic whereby a time bar fills when the tap occurs and slowly/quickly empties. The next shot will only take place if the bar has finished emptying.

@_memo @horacebury

Thanks for the tip. Will give it a shot.