• Advertisement
Sign in to follow this  

Tile Editor :: Which Tile Selected in Scrolling Map?

This topic is 4400 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sorry it took me so long to reply. But thank you all for your replies/suggestions/help! =) Happy New Year!

Share this post


Link to post
Share on other sites
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:
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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement