I have a question in regards to holding the screen. I have a mobile game which requires A LOT of tapping, so I would like an ability that when activated, for 4 seconds you may hold the screen and all the places you hold the screen whether you’re dragging your fingers across the screen or not, constant taps are being simulated every 0.01 seconds. For in this game to “defeat enemies” you must tap them, so I would like a holding the screen ability which is AMAZING for this game.
However, after reading through these forums, I couldn’t innerstand how to actually extract what was in those discussions and apply it to my simple idea.
May someone please assist me? I would’ve thought holding the screen would be easy to code, but I think the fact I need to constantly register the hold as individual taps every 0.01 seconds for 4 seconds then deactivate until the ability is triggered again possibly is why I’m running into walls.
Thank you, we are very grateful, for anyone who chooses to help me!
The first frame when you click/touch on the screen the action.pressed field will be true. When the user releases the mouse button/finger the action.released field will be true.
If you set a flag when you get the action.pressed and clear the flag when you get a action.released you can use this flag in your other game logic to run some code to attack enemies.
Okay this is very interesting cause it proves the screen can be held, now I got to a similar outcome with some code that tracked that I was holding the screen, but there were two main issues there that I theorize may apply here which is, the location of the hold on the screen, has to be tracked as the tap is, and in the area of the hold, that action pressed is constantly being sent every 0.01 seconds. If that’s possible then maybe, you could repeat action pressed multiple times until you release the screen.
Is this possible? I tested out the example you sent and it really looks promising lol.
You get one pressed and one released event. You do not get any events in between, except if the player drags the finger across the screen in which case you get action.x and action.y updates but no pressed or released events.
If you want to call some code while the finger is held down you need to move that code to update (like in the example I shared) or perhaps use a repeating timer that you cancel once the released event is received.