Tile Editor :: Which Tile Selected in Scrolling Map?

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

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 on other sites
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 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 on other sites
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 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 on other sites
Sorry it took me so long to reply. But thank you all for your replies/suggestions/help! =) Happy New Year!

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).

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• Forum Statistics

• Total Topics
632959
• Total Posts
3009467
• Who's Online (See full list)

There are no registered users currently online

×