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.

Newcomers AppGameKit Corner / My mouse pointer is out of sinc with my screen... I want to be able to detect sprites on the screen, but it is very inaccurate using Getmousex(), Getmousey()

Author
Message
Mark Garrett
Reviewed AGK on Steam
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 28th Jan 2018 17:03 Edited at: 28th Jan 2018 17:10
I have done this before on programs I made before, but this time I cannot detect accurately the sprites on the screen with my mouse pointer.
Am I supposed to use 'World Mode' ? I don't know how to fix it. My mouse pointer is out of sync with my screen.

I did re-scale the sprites to 50% of their initial size, could that be why?

screen setup:



mouse pointer detection portion:

smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 28th Jan 2018 17:27
have you changed the view offset?
try SetSpritePosition(300,ScreenToWorldX(GetPointerX()),ScreenToWorldY(GetPointerY()))
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Mark Garrett
Reviewed AGK on Steam
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 28th Jan 2018 17:44 Edited at: 28th Jan 2018 18:31
No, it didn't work, thanks anyway.
I can detect the position of the mouse pointer sprite on the screen, and it actually shows a small black dot on the screen each time I press the left mouse button. But it won't print out the location if the mouse pointer sprite at the top or on the sides or on the bottom, just a large square in the middle.

And another program I just made works fine and has no such problem. So, I think when I put the sprites, after I put them I scaled them down to 40%, and maybe that's why?
Mark Garrett
Reviewed AGK on Steam
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 28th Jan 2018 19:43 Edited at: 28th Jan 2018 19:44
I think I found out.... In making the sprites (which are circle shaped), I used the command 'SetSpriteShapeCircle( a, 88, 88, 82)' when creating the sprites... So, perhaps that is a 3d command or something?
puzzler2018
User Banned
Posted: 28th Jan 2018 19:48
Ouch- it looks like your using Goto or Gosubs

Not good practice..
puzzler2018
User Banned
Posted: 28th Jan 2018 19:49
Try using the SetSpritePositionByOffset commands
Mark Garrett
Reviewed AGK on Steam
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 28th Jan 2018 20:06 Edited at: 28th Jan 2018 20:10
yes, your right, it was getting a little complicated the way I was doing it there.



But, a question on the side, I wondered, I have sprites that are 3 layers deep, so, if I want my mouse pointer sprite to detect a sprite, it will always detect the top one, right?
puzzler2018
User Banned
Posted: 28th Jan 2018 20:11
Yes - it will hit any sprites that are Visible unless you use the GetSpriteHitxxxxxxx functions- maybe

I havent gone into these before but think will do nicely for what you trying to do

Press F1 to see some examples
Mark Garrett
Reviewed AGK on Steam
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 28th Jan 2018 20:36 Edited at: 28th Jan 2018 20:37
Wow, I'm getting excited now, it's working good now with applying your information, thanks puzzler !
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 28th Jan 2018 20:53
try
SetSpriteShapeCircle( a, 0, 0, 82)
or
SetSpriteShape(id,1)
for your circles

if you turn on physics debug it will show lines/hollow blue shapes for your physics so you can easily see where the detection is for your sprites
SetPhysicsDebugOn()

also yes it's good to use SetSpriteGroup(id,#) and GetSpriteHitGroup(#,x,y) as this lets you process only the sprites you want.
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 31st Jan 2018 13:51
Also think about how setting a sprite collision shape to 'polygon' allows you to ignore the transparent parts of a sprite. This is useful (necessary even) if you use larger sprites for user interface. It is also important you set the correct sprite depth so the correct sprites will be detected, as sprites that are underneath others will be ignored from what I understand.

...unless setspritegroup or setspritehitgroup enables us to ignore sprites that cover others, you're going to need to set proper depth ( setspritedepth(id, int) , where int is ~10000 to 0, with 0 meaning sprite will be on top of everything if I recall correctly ).

Login to post a reply

Server time is: 2024-11-21 19:48:25
Your offset time is: 2024-11-21 19:48:25