I am attempting (key word there is "attempting") to make a map editor for other games I make in the future. Along the way, I have encountered the most odd bug I have ever seen.
So my program has the ability to scroll left and right with the arrow keys. When I launch my program, I can click and drag to draw the tiles, and everything is quite smooth. But after I scroll the map even a tiny bit, everything gets screwed up. It appears as if when I click to draw the tiles, everything is drawn correctly. Although when I draw, other tiles start to disappear! The tiles disappear in a pattern. The pattern it goes in is like this:
I scroll over a specific amount, I will choose 65 (pixels).
I draw some tiles.
The tiles are correctly draw, although the tile in the tile location exactly 65 pixels left of where I draw disappears.
Sorry if this is kind of confusing, post if you don't understand. I really need some help on this
When you are indexing into map[][], it looks like you're using the tiles screen position instead of world position. Also, you don't need to be storing positions in your tiles if your tiles are in a grid. You should be doing something like this when you lay a tile (assuming origin is in the top left and the cameras position is considered the top left of the camera's rectangle):
int Sys::getCloseX()
{
int x = 0, y = 0;
SDL_GetMouseState(&x,&y);
x += camera.x;
double temp = x / 32;
temp = floor(temp);
return (int)(temp * 32);
}
int Sys::getCloseY()
{
int x = 0, y = 0;
SDL_GetMouseState(&x,&y);
y += camera.y;
double temp = y;
temp = temp / 32;
temp = floor(temp);
return (int)(temp * 32)+4; //+4 compensates for banner
}
These get the coordinates in relation to the whole world. It also rounds down to the nearest 32. (For the gridding)
Your code doesn't really seem to work. Why is it camera.x for the width, but camera.h for the height? And I don't see the problem with my for loop starting at 0 and ending at the finish of my array. One more thing, is TILE_SIZE the map size or the tile width/height? When I tried your method nearly none of the tiles applied, and when they did show up, they were not in the correct spot.
Yep sorry, should have been camera.y. There is no problem starting the for loop at 0 when rendering, it's just inefficient and easily made more efficient. I changed it because I had to change the rendering loop anyway in the code I posted. In my sample TILE_SIZE is the width/height of a single tile. There was infact a bug in the code I posted, I edited it above , it should work now.
X Abstract X wrote:Yep sorry, should have been camera.y. There is no problem starting the for loop at 0 when rendering, it's just inefficient and easily made more efficient. I changed it because I had to change the rendering loop anyway in the code I posted. In my sample TILE_SIZE is the width/height of a single tile. There was infact a bug in the code I posted, I edited it above , it should work now.
I had to slightly alter your code still, although I am in such an ecstatic state at the moment I can't quite remember if it was from bugs or just for personal needs. If you haven't noticed, I fixed this pathetic bug. Needless to say, the problem I had was I was compensating for the camera offsets in two different spots, therefore resulting in tiles displace by the offset. Thank you for your help though, it made my code far more neat and easier to read