Android Question How to respond to touch screen using LibGDX?

robbies

New Member
Licensed User
Longtime User
Hi, I am trying to get the coordinates of where the screen is touched using the lginputprocessor in the LibGDX library.
I am getting the X & Y location from the Sub IP_TouchDragged arguments and assigning those coordinates straight to the sprites X & Y. I knew it wouldn't be that easy, and as I suspected it didn't work.
The sprite does not follow my finger and up and down movements are inverted. I have searched the issue and it looks like I need to use Vector3 with the lgOrthographicCamera.unproject. There is no Vector3 that I can find?

If anybody can point me in the right direction (and my sprites!) on this I would really appreciate it.

Thanks in advance,
Rob

P.S. I've attached my code I'm using to test all this stuff...
 

Attachments

  • TestCode.txt
    2 KB · Views: 183

Informatix

Expert
Licensed User
Longtime User
The touch coordinates are given in screen coordinates. Your objects are positioned in world coordinates. All you have to do is the conversion between the two systems of coordinates. A simpler way is to use only the screen coordinates by initializing properly the camera. See the ParticlesPool example.
 
Upvote 0

robbies

New Member
Licensed User
Longtime User

Thanks for the advice - I'll check it out.
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Does anyone have a conversion function for this? As my touches are way out as well.

I used the same command in the ParticlesPool example and get missing parameter error?

I really don't care what method I use for now, I just need to detect where I tapped and intercept accordingly!

Malky
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…