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 / how to properly click on sprite and place sprite in any positions when setOffView is not 0,0 ?

Author
Message
2D Analyst
AGK Developer
19
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 31st Mar 2020 04:36
Below codes works fine for windows. I tried the same codes for my iphone and the codes functions fine when setOffView is 0,0. When the setOffView is not 0,0, the alignment is off. Any ideas?

Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 31st Mar 2020 07:44
It might be an idea, instead of using "GetPointer" to instead check if there is a Mouse Present... if it's not, then assume a Touch Display; and each loop populate your own "Pointer" Class that stores the information from the GetRaw Data.
You can use the "GetMouseExists" to essentially populate a Boolean (well Integer, but eh... treat it as a bool) that flips between GetRawMouse and GetRawTouch events.
Same with Clicking, Holding, blah blah blah

Mind it does sound like what you've come across is a bug
2D Analyst
AGK Developer
19
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 1st Apr 2020 04:57 Edited at: 1st Apr 2020 04:59
Thanks Raven, that's a good idea. I messed around with the codes and used GetRawFirstTouchEvent(), GetRawTouchCurrentX() and GetRawTouchCurrentY(). Using these didn't work, so I started comparing the alignment differences. Here's what I've concluded.

On windows, screenToWorldX(GetPointerX()) will give you the correct point when setOffView is not 0.




On touch screen device like iphone, ScreenToWorldX(x#) will not return the correct point when setOffView is not 0



You will need to factor in the setOffSetX and setOffSetY into the touch coordinates to work correctly. I wonder if anyone else experienced this issue?
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 1st Apr 2020 08:53
You know it could be the Device.
I just did a test on my Android Phone (Nokia One) and this code worked "Fine"



So yeah, might be your Device?
2D Analyst
AGK Developer
19
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 2nd Apr 2020 00:30
So, I tested the codes I had that works on my iphone XS MAX and the same codes does not work for iPad 2018 model. I'm at a point, where I think setOffView () and screenToWorldX() do not output consistent behavior. Now, I'm leaning toward to not use setOffView() and manage the tiles position via my own function. It just seem like whenever setOffView() is set outside of 0,0, screenToWorld() behaves differently. I haven't even tested on my kindle fire or any other android devices as I fear it will be insistent as well.

Raven - I looked at your codes and it looks like your setViewOffset() is called once. In my application, the setViewOffset() can be control by user to move the screen around.

2D Analyst
AGK Developer
19
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 2nd Apr 2020 04:59
Actually, I came up with a workaround. Initially, I was going to create my own function and manage the tiles myself.

The trick is not to use getSpriteHitTest() with setViewOffSet() because every devices behaves differently.

GetSpriteCollision() with setViewOffSet() seems to work consistent across different devices. So, I basically created a cursor using sprite and getPointer function works fine on windows, iphone, and iPad.

If anyone else experienced this issue, above solution guarantees to address the alignment issues.
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 2nd Apr 2020 05:05
It is only called once... but if there was an issue that was going to occur., merely changing it from Default would've caused some incorrect touch behaviour.
Anyhow, I checked both the iPhone XS and iPad 3rd Gen (Pro 11?) specifications... and I think I was onto something.

The iPhone XS just has a High Resolution, HDR Capable OLED ... while the iPad has a Retina Display.
While looking through the Help Files, I found "For example on Mac with a retina display the window size will be half of the pixel size"
Now it makes me wonder if either the GetPointerX or ScreenToWorldX aren't using the Window size as the basis instead of Display size.
This would mean that when it applies the Offset it's would be moved properly but only accounting for half the actual distance moved.

So you'd need to add something like X# + ( GetOffsetX( ) * 0.5 ) to the Pointer Position.
I don't have an iPad, only a Surface (and that just runs native as AppGameKit thinks it's Windows 10 Desktop) but could be the issue, no?
2D Analyst
AGK Developer
19
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 3rd Apr 2020 01:50
Those are good points you mentioned. I haven’t tried getXOffset but based on your logic that makes sense. For now, I’m good using getSpriteCollision() as it works fine with getPointers(). I will test it out on kindle fire this weekend.

Appreciate all the feedback! Working on any new games?

Login to post a reply

Server time is: 2024-04-18 06:38:17
Your offset time is: 2024-04-18 06:38:17