Touch is pressed VS is down?
raze_struck
Member, PRO Posts: 141
Hello all,
I'm having a small issue with attacking, when touch is pressed on a certain button on the screen, game.attk is true and my player attacks with the appropriate animation, on the attack button I have a timer saying after 0.5s change game.attk to false, run to completion, but if the player decides to hold down the button and not let go, my actor freezes on the last frame through the animation cycle and stays like that until the player lets go of the button.
How do I change it so that you can only tap the button and not hold it down. Ive tried doing this;
When game.attk is false
touch is pressed
change game.attk to true
after 0.5s change game.attk to false
doesn't work, actor can still hold down the button ?
Comments
Did you try a timer for "FOR" instead?
So, player can only attack FOR 0.5 seconds.
Do you have your animation set to LOOP?
Is your attack cycle an animation, too, or just a single change image?
Is your Main Actor animating all the time, or just when walking / attacking?
If your attack cycle is on animation, is the animation on loop, and also, is the return image set to go back to its normal pose? Do you have "restore actor image when done" checked?
It's hard to say without seeing your code. I see where the hardcore forum members are coming from now. Go through that list and see what you can figure out! Best of luck!!
I did not try for yet, that's a good idea though. The animation is not a loop, just a frame attack, there are several animations, idle, walk, jump, dash, duck and they all communicate through booleans. No restore actor image needed on anything, because the dudes practically just idling if nothings happening. So hes always animating basically.
Thanks BTW
@JodyMitoma sounds like a decent plan..
You could also try adding another attribute into the mix... i.e a new self attribute called 'pressed'.
rule.1
if touch is pressed change self.pressed to 1
(otherwise change self.pressed to 0).
rule.2
if self pressed =1
change attribute game.attk to 1.
after .5 seconds change game.attk to 0.
That way game.attk should return to 0 even if the touch is still being pressed...
Nice call, need to try it when I get home from work, either option ill play around with it
Last question. I have a double jump in my game that set up as an integer value with a count to count the number of times the player jumps and all is well, but when I put a jump through platform in the game, and jump on it and change collide to true when his pos is over the plat and is colliding with it. my character jumps on the platform, and then goes completely crazy and starts flying all over the screen, lol
Any thoughts. Also to note, I have game.jump as a boolean that's set to true when you press the jump button, and set to false when you land on the ground.
So it kind of worked, Im no longer able to hold down the attack button anymore, however if i spam the attack button, because self.pressed immediately goes to false, it changes self.pressed to 1 again and the second rule is executed again, over and over
it keeps changing the value to true, which it shouldn't dammit ! and if I put a;
if game.attk is false and touch pressed change , your allowed to hold it down, ahhh
bump
bump
Hi, I’m not sure if you managed to resolve the issue but I ran into something very similar. I’ll write how I resolved it so maybe it will help someone in the future.
In my case a player is supposed to score when they touch an object. Naturally I put my scoring logic within a touch/press condition. But then when the object was touched/pressed continuously it would also keep scoring which I didn’t want. So I put a flag that would get set after the first touch and would prevent executing the touch condition after that. However, this was not good enough. The condition would still get executed twice when continuously pressed.
(Initially I fought it was about the timing, the press event firing rapidly, before the flag has time to set. But now I think it’s about the recursive order in which GS executes nested statements, which is very bad in my opinion)
The way I resolved the issue was that I put a short “after” timer (0.05s) inside the press/flag condition and then put the scoring inside the timer. It works properly now but I still think the way GS processes events and conditions is a bug.