Camera x,y coordinates - Help!
Toke T
Member Posts: 26
Hello everyone!
I am having some problem with the x,y coordinates in my game. I use a touchpoint behaviour to move a ball around. This works fine when the coordinates for the camera is (0,0) but if i move my camera the x,y is getting offset( Stil works as if the coordinates was (0,0) - does it make sense? - Thank you.
My Website:http://toket.dk
Comments
When you touch a mobile device's screen a touch returns the position you have touched on your screen - so for example with a device that is 1024 x 768 px where you touch in the middle of the screen the touch position will be 512, 384 . . . . regardless of where the camera is in a large scene . . . so even if you have a 50,000 x 50,000 px scene and you move to the middle of it (so you are at 25,000 x 25,000) and then you touch the middle of the screen, the touch position will still be 512, 384 . . . because touch measures where on the screen you are touching, not where in the scene you are touching.
But of course to get to the middle of this large 50,000 x 50,000 scene you would have had to move the camera there . . . so to measure the touch position relative to the scene you would simply add the camera's position to the touch position.
So . . . if you are using touch to move a ball . . .
constrain ball x to mouse x + camera origin x
constrain ball y to mouse y + camera origin y
Thank you. That was very helpful.
My Website:http://toket.dk
P.S . . . to access the camera controls (like scene.Camera.Origin.X) you will need to unlock your ball actor in the scene.
Ha! Ha! Yes, it took me some time to figure that out. Still it was very nice to get that the explanation about coordinates . Thanks!
My Website:http://toket.dk