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 / GetPointerX/Y()

Author
Message
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 4th Oct 2017 12:58
My program is returning sporadic results in connection with sensing pointer presses/clicks. I am using GetPointerX/Y() to determine where the pointer is being pressed on screen, but sometimes toward the middle of the screen, somehow the action is not getting read. See code snippet:



I checked and re-checked other parts of the code, but the problem somehow seems to be emanating from here.
https://forum.thegamecreators.com/images/emoticons/atari.gif
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 4th Oct 2017 14:04
i remember in past it was an invisible advertising block that eat the pointer state.
in your loop print(GetPointerState()) on screen, be also sure you not use sync multiple in main loop.
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.9.3) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Oct 2017 14:26
You should save the value of GetPointerX() / getPointerY() to variables.
You can only read them once per sync, then they get reset to 0.
I had this problem a couple of years ago in AppGameKit, and it was also in DarkBASIC Pro, I assume it is still a "feature"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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: 4th Oct 2017 14:50
Quote: "You should save the value of GetPointerX() / getPointerY() to variables.
You can only read them once per sync, then they get reset to 0."


x,y you can read as often as you want, maybe a bug feature in past.
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.9.3) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 4th Oct 2017 17:36
Sync() calls don't seem to be an issue here. I've already tried assigning GetPointerX() to variables but still ng. I just don't get it.
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 4th Oct 2017 17:47
Possibility related - Is there a way to know whether any[b] virtual button has been pressed, rather than having to check each one through every loop iteration? I have quite a few virtual buttons in my code.

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 4th Oct 2017 18:39 Edited at: 4th Oct 2017 18:40
what is before your elseif ?
do you set baseID & tankID maybe elsewhere?
x,y is float?
try with #option_explicit one at top of main.
u used advertising in game or not?
use the debugger or print values on screen.
you can make a function that check all virtual buttons in a for next loop and return the id.
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.9.3) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 5th Oct 2017 00:04

what is before your elseif ?



do you set baseID & tankID maybe elsewhere? no
x,y is float? they are now, though that didn't make any difference
try with #option_explicit one at top of main.
u used advertising in game or not? no
use the debugger or print values on screen.
you can make a function that check all virtual buttons in a for next loop and return the id. there is a function call within a do loop that checks each button with an if . . . elseif .
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 5th Oct 2017 00:15 Edited at: 5th Oct 2017 00:46
I usually use the nested if's with ands, like...




I used GetPointerState() in that example so the Text Printed would stay on the screen long enough to read it while you hold it down but a GetPointerPressed() would work for regular touch detection.

Below is a Swipe example that I am using in my current project... (it uses variables and a timer to tell if they are holding down on the screen and not accidentally tapping it)



That example is used to tilt/pan the camera in a 3d environment when you swipe the screen.

You can see that the original spot touched is the 0,0 point for the movement of the camera, regardless of where they move the finger while pressing down.

Just return the finger back to the starting point (or lift our finger up) to stop the camera movement. (note the 40 pixel buffer to make that spot bigger)

There is probably a better way to do it, but it works nicely for what I am doing. (i am also limiting the angle for panning too --> 18 or 5 in case anyone is wondering about that)

I hope this helps.

Quote: "i remember in past it was an invisible advertising block that eat the pointer state."


The only time I had a problem detecting the pointer was an invisible virtual button being in the way.

If you are hiding virtual buttons, then make sure it is not at that spot.

Maybe move its position off screen until you need it visible again, then move it back.

You could do that for any/all buttons when making them visible/invisible.

There is no GetVirtualButtonX() or Y command so you will need to hard code the locations, but...


Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 5th Oct 2017 00:50
I do have hidden virtual buttons. Wouldn't SetVirtualButtonActive() set to inactive take care of the problem?
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 5th Oct 2017 01:23 Edited at: 5th Oct 2017 01:32
Quote: "I do have hidden virtual buttons. Wouldn't SetVirtualButtonActive() set to inactive take care of the problem?"


I just tried it.

Yes, that works.

You will still need to do that when making it visible or invisible, so it is about the same as the re-positioning, but it's easier because you don't have to track the X's and Y's.

Better solution, so good call.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 5th Oct 2017 08:41
is there is not something which blocks the mouse input, and the conditions looks good try this
Quote: "
elseif GetPointerState()
print("HERE Pointerstate")
print(GetPointerX())
print(GetPointerY())
print(MaxWidth)
print(MaxHeight)
x = MinMax(0,MaxWidth-1,ScreenToWorldX(GetPointerX())) `MinMax is my routine for limiting the x/y result
y = MinMax(0,MaxHeight-1,ScreenToWorldY(GetPointerY()))
print(x)
print(y)

baseID = GetSpriteHitGroup( BaseGroup,x,y )
tankID = GetSpriteHitGroup( PlayerTankGroup,x,y )
print("baseID:"+str(baseID) )
print(tankID )
"

AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.9.3) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 5th Oct 2017 12:34
Hidden virtual buttons don't seem to be the issue, though I'm still investigating. I tried printing the pointer X/Y to the screen, but when the pointer is pressed in the middle area of the screen, nothing is printed. So it seems the pointer is not being read at all. Sometimes though an area that seemed "dead" a moment before, will then take a read. Its not an input device issue; I've tested with more than one.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 5th Oct 2017 18:49
Quote: " but when the pointer is pressed in the middle area of the screen, nothing is printed. "

virtual joystick or sprites there?
is there a text area?
what returns print(GetSpriteHit ( x, y ) )
you can make a Test Function and call it at different places, at the beginning, before loop, in loop etc. maybe you see a diffent where it works.
or remark some blocks of code with if 1=0 ... endif

AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.9.3) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 5th Oct 2017 20:57
What do you mean by "Text Area"? Do you mean CreateText()?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 5th Oct 2017 23:38
yes, i filtered the command list by "hit" and found GetTextHitTest ( iTextIndex, x, y )
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.9.3) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 6th Oct 2017 01:14
Well it looks as though the existence of hidden Virtual Buttons is really the culprit.
Thanks everyone for your helpful input

Login to post a reply

Server time is: 2024-04-20 13:53:10
Your offset time is: 2024-04-20 13:53:10