Camera x,y coordinates - Help!

Toke TToke T Member Posts: 26
edited July 2016 in Working with GS (Mac)

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

  • SocksSocks London, UK.Member Posts: 12,822

    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

  • Toke TToke T Member Posts: 26

    Thank you. That was very helpful.

    My Website:http://toket.dk

  • SocksSocks London, UK.Member Posts: 12,822

    @Toke T said:
    Thank you. That was very helpful.

    P.S . . . to access the camera controls (like scene.Camera.Origin.X) you will need to unlock your ball actor in the scene.

  • Toke TToke T Member Posts: 26

    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

Sign In or Register to comment.