Long press button
sawkastee
Member Posts: 184
I've got a button that "when touch is pressed" it performs a behavior. I want to use the same button to initiate a behavior when it is pressed for 3 seconds or longer. Anyone know how to achieve this? I tried several things but the 1st rule gets initiated when I don't want it too.
Comments
I haven't tried it but I'm thinking you could do something like this:
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
The only thing I can think of is to make whatever behavior you want to perform, say, a bullet to shoot, a boolean. So you'd say when touch is pressed > (using a timer rule) after 3 seconds > run to completion > change attribute > game.bullet to true.
I made a template to show what I mean using an quick & easy appearing block actor when touch is pressed after 3 seconds.
https://www.dropbox.com/s/npv11nihwal9z3j/appearing actor.zip
Hope this helps! :)
The first rule still runs...hmmmm. There's got to be a way to keep the first, when touch is pressed rule from running.
Try this:
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Isn't this the same as . . .
When touch is pressed
Timer, after 3 seconds . . .
?
It's impossible, not just technically impossible in GameSalad, but logically impossible.
@Socks
Hmm, yes I suppose it is. Lol... I need more sleep.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Ok, I guess I'll just think of another way to do this without a long press.
You have two solutions for one question and you're giving up? Did you try either of them?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Yeah, but @tatiang just wanted to make it sound a little smarter and complex.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
He should've used tables + trigonometry + modulus and the word 'flappy' at least 3 or 4 times.
Neither of them address the whole question, they both just address the 'after 3 seconds something happens' part, he also wants something to happen when the button / actor is first touched ('when touch is pressed'), but that initial action doesn't happen when you go for the 'after 3 seconds' option . . . . . like I say it's impossible (logically impossible) as 'when touch is pressed' will always trigger whether you press the button very briefly or whether you hold it for 3 seconds.
You could drop the 'when touch us pressed' part and make that 'when touch is released'.
So, the first rule gets initiated when the player releases the button after having pressed it, but if they hold it for 3 seconds or more the second rule gets initiated instead.
?
@tatiang
I tried them both and they didn't work. @Socks I also tried the "when touch is released", it works the best but I'd like to see "when touch is pressed" so I don't have the slight lag of waiting for the button release.
I want an implementation similar to that of an iOS app icon. If you touch, it opens the app, but when you touch and hold the app icon jiggles so you can move them. In my app the touch would go to the next card and touch and hold would open a settings menu.
That would be "when touch is released" then. Even iOS can't possibly know your intention (to just tap, or touch and hold) before you actually complete the action.
If it's still not working as intended, try starting a timer when the user initiates the touch. Then, on release, check the length of time that the button was touched. If it's less than 3 seconds, go to the next card. If it's 3 seconds or more, open the settings menu. This way, only one of those behaviors can fire at a time.
Try something like this:
Works! Thanks!
Glad its working for you! You are welcome.