Jump to content

worldX is different on devices


Recommended Posts

Hi there,


I am trying to get touch position in the game at a given point within the world, although I am getting different results on different devices. Things to note are:


  • The game.world.scale x/y values are increased as I am trying to make it look like it is zoomed in
  • The game.renderer height/width is not the same as the game height/width (I am stretching the canvas to fill the screens height and centering it)
  • The x/y scale values are always the same
  • The camera is moving around the world

Here is the code I currently have to get the touch point  and covert it to the world position:

                var scale = game.world.scale.x;		var clickX = e.worldX / scale * (game.renderer.width / game.width) - game.camera.x / scale;		var clickY = e.worldY / scale * (game.renderer.height / game.height) - game.camera.y / scale;		return {			x: clickX,			y: clickY		};

The accuracy of this gets worse as I move away from the top left of the world. It is also worse on the iPhone 6+ compared to the Galaxy S6. I think this may have something to do with the offset? 


Not sure what the issue is, what exactly is WorldX supposed to return?




Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...