Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Press vs Press-and-hold?

Author
Message
Fluorescent
FPSC Reloaded TGC Backer
19
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 1st Jan 2016 09:23
I'm trying to work something out where I want to be able to either click or click and hold on a sprite. I'm currently using GetPointerPressed and GetPointerState, just in case I want to put my little game on a touch screen device. But I'm starting to think that it's not going to work. Do I have to start a timer on GetPointerPressed to see if the player is holding the button down perhaps?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 1st Jan 2016 12:21
Use a float variable. When getPointerPressed() is detected, set it to Timer().
When you detect GetPointerReleased(), check the variable against the current Timer() value. Decide what is a suitable length of time for a click, anything greater than this is a hold.
You will probably want to reference this variable during a hold too, not just at the end of the hold. You will need to account for the fact that it isn't a hold until X milliseconds have passed, and make sure this doesn't interfere with the gameplay.
Don't forget to reset the variable to 0 after getPointerReleased(). Then you can use it to determine what state the pointer is in at any point in your game.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 1st Jan 2016 12:57 Edited at: 1st Jan 2016 13:05
example from me:
AGK (Steam) V2.0.16 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Fluorescent
FPSC Reloaded TGC Backer
19
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 1st Jan 2016 16:30
Thank you! That really helped!

Login to post a reply

Server time is: 2024-09-29 09:29:29
Your offset time is: 2024-09-29 09:29:29