# Iso grid snap

## Recommended Posts

Hello, im trying to create a iso grid snap, but it doesnt seem to work 100%, it creates a 'Checkered board pattern' as in you can olny place the object(im using this for the level editor) on every other square, here is what iv got
MVec newo;
newo.x=round((Cam.x+mouseX)/GRID_SPACEX,0)*GRID_SPACEX;
newo.y=round((Cam.y+mouseY)/GRID_SPACEY,0)*GRID_SPACEY;

NewMObject(newo,selected_object);

MVec is a custom class that holds a float x,y; GRID_SPACEX is the size of the tiles X GRID_SPACEY is the size of the tiles Y(1/2 of the X) and 'round' rounds the number to the nearest whole number but like i said this creats a checkerboard pattern were items cant be placed, any ideas? Edit: and one more thing, kinda off topic but i was just thinking about it, if the tile size y is x/2, does that mean that the yspeed for an object is equal to half of what it would be if it was x? Eg Xspeed=10; Yspeed=10; X+=xspeed; Y+=yspeed; Or Y+=yspeed/2; ??

##### Share on other sites
Oh boy. Let me tell you how hard iso is. Took me a good few weeks to get mine to work. Anyways I have some useful code I could share if you are intrested in seeing how I did it. Just let me know. I can tell you the main parts of what you need to be looking at. It's in SDL btw.

##### Share on other sites
Quote:
 Original post by Drew_BentonOh boy. Let me tell you how hard iso is. Took me a good few weeks to get mine to work. Anyways I have some useful code I could share if you are intrested in seeing how I did it. Just let me know. I can tell you the main parts of what you need to be looking at. It's in SDL btw.
ok that would be great, my email is kc_0045@hotmail.com or just post it here if you dont mind everyone seeing it

##### Share on other sites
Not a problem at all. Here is the project. Not the last time I worked on this as around Nov 2004. It was just more of an experiment and such. You should notice the images [lol]. Run the .exe to see how it looks to begin with.

What you need to take a look at is:

void RTS_Map::Draw() - Line 32 - RTS_Map.cpp
void RTS_Map::MouseToTile(int x, int y) - Line 731 - RTS_Map.cpp
void RTS_Map::DrawTileCursor(int x,int y) - Line 867 - RTS_Map.cpp

That is the most of it, feel free to look at the rest. You will see my algoritm to get the correct mouse tile using a tile map on the mousetotile function. It may take a bit to understand how it works, but once you do, you will see how marvelous it is [smile]. I did not come up with the original theorey, but I did make the code for it, so if you have any questions, I should be able to answer them, but I may be a bit rusty. Hope this helps.

- Drew Benton

PS I do plan on finishing this project some time in the future [lol] I just have to wait till I have the time b/c I will be writing a tutorial with it.

[Edited by - Drew_Benton on February 20, 2005 4:05:53 PM]

##### Share on other sites
The whole thing gets about a hundred times more complicated if the different tiles have different heights as in Tactics Ogre or Final Fantasy Tactics. I believe that the articles section here on GameDev has some good information on general iso math and concepts that might be able to aid you.

##### Share on other sites
Error Code 404: Missing File

##### Share on other sites
Quote:
 Original post by kc_0045Error Code 404: Missing Fileerr seems to be a bad link

I'm sorry. I killed my link! I have fixed it now, I forgot to append the filename [lol]. Sorry for the delay [embarrass]!

- Drew

##### Share on other sites
Quote:
Original post by Drew_Benton
Quote:
 Original post by kc_0045Error Code 404: Missing Fileerr seems to be a bad link

I'm sorry. I killed my link! I have fixed it now, I forgot to append the filename [lol]. Sorry for the delay [embarrass]!

- Drew

hey your code works and all but what does it do? it places 1 tile on the left and over laps it. is it supose to do anything else?

##### Share on other sites
My code shows how to go about using the ISO design for placing tiles and then tracking then snapping the mouse to them - as per the OP requested. If you move the mouse around, you will see how it accuratley goes into the right grid spot. If you modify the images and add a black border around them, you will see the accuracy. This was done based on a few tutorials featured on GameDev about using a BMP image to mousemap. However, it was not written in C++ so the challenge was implementing it. Here's a screenshot (of which is bad quality b/c jpeg):

Does that answer your question, or do you still need more? There is not much other functionality with it because it is not finished. It was more of a demo to get the mouse mapping correct. Here is the list of avaliable articles for reference.

- Drew

##### Share on other sites
okay cool. i just wanted to know whether you uploaded the right file or not. but yeah i see the purpose of this demo

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628281
• Total Posts
2981800

• 10
• 11
• 17
• 14
• 9