Java 2D World question

Posted by Munkybunky on Game Development See other posts from Game Development or by Munkybunky
Published on 2014-03-12T19:43:28Z Indexed on 2014/06/11 3:49 UTC
Read the original article Hit count: 209

Filed under:
|

I have a 2D world background made up of a Grid of graphics, which I display on screen with a viewport (800x600) and it all works.

My question is I have the following code to

convert the mouse co-ordinates to world co-ordinates

then

World co-ordinates to grid co-ordinates

then

grid co-ordinates to screen co-ordinates.

//Add camerax to mouse screen co-ords to convert to world co-ords.    
int cursorx_world=(int)camerax+(int)GameInput.mousex;
int cursorx_grid=(int)cursorx_world/blocksize;  // World Co-ords / gridsize give grid co-ords
int cursorx_screen=-(int)camerax+(cursorx_grid*blocksize);

So is there anyway I can convert straight from mouse screen co-ords to screen co-ordinates?

© Game Development or respective owner

Related posts about java

Related posts about 2d