Tile Editor :: Which Tile Selected in Scrolling Map?
Okay, I have decided to start working on a tile editor, for a game that I have some ideas for. I am probably going to use SDL, but I am also considering OpenGL with MFC.
Anyhow, I know that you get the tile position by dividing the mouse 'x' and 'y' by the tile size. But, when the map scrolls, how do I get the tile position? Since it is only going to scroll left and right, would I just subtract the amount scrolled from the 'mouseX / 32'? Or must I do it another way?
I just wanted to make sure before I actually started.
Thanks in advance,
Matt U.
I'd keep the tiles in world coordinates.
I.e when the camera scrolls a worldx,y increases/decreases etc... and then simply add this value to the clicked screen position. easy peasy. :D
Peace!
I.e when the camera scrolls a worldx,y increases/decreases etc... and then simply add this value to the clicked screen position. easy peasy. :D
Peace!
Keeping everthing in world co-ordinates will ensure you to control the calculation of the game logic. You could easily convert the world co-ordinates to screen coordinates in this case and then maintain your movement logic.
use algebra
if you equation to get from world to screen is
screenx = tilex * tilewidth - camerax
then by algebra you have
tilex = screenx/tilewidth + camerax/tilewidth
if you equation to get from world to screen is
screenx = tilex * tilewidth - camerax
then by algebra you have
tilex = screenx/tilewidth + camerax/tilewidth
Look at your units. Mouse X, Y is in pixels and tiles is in pixels/tile. You want your final number to be just tiles. So you you divide pixels by pixels/tile and are left with tiles. So what are your units for the scrolling? If its pixels then you add the scroll amount to the pixel corrdinate then divide by the tile dimention (width or height). If your scroll units is tile you divide your screen coordiates in pixels by the tile dimention then add the scroll value in tiles.
Sorry it took me so long to reply. But thank you all for your replies/suggestions/help! =) Happy New Year!
I'd suggest making a function to 'align' any points with the camera. Of course, this would only be applicable in the final drawing function, so it would not actually alter the coordinates of the object/shape/etc.
Ex:
Something simple like that, and you could make overloads for different forms of ponits (rectangles, etc).
Ex:
void DrawAlign(long &x,long &y) { x-=camera_x; y-=camera_y;}
Something simple like that, and you could make overloads for different forms of ponits (rectangles, etc).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement