Skip to main content
gamedev.net
🔒 Locked

problem creating tiles

Started by Xpyder 7 replies 1.5k views
Original Post
Xpyder
Xpyder
hey - i am making a 2d isometric rts, and before, the tiles were rendered from left to right and down, so: 123 456 789 but the problem with this was that it looked very wrong - especially with the indent to fill the gaps. So i started to make an algorithm to draw them in a diamond shape, like: 7 4 1 8 5 2 9 6 3 when i used a function that drew them in the array manually, it worked fine, no errors : qTile[0][0] = CreateQuad((i*size_x) + 500, (j*size_y)-(j)+0,64, 32, tGrass, 0, 0); qTile[1][0] = CreateQuad((i*size_x) + 500 - 32, (j*size_y)-(j)+16,64, 32, tGrass, 0, 0); qTile[2][2] = CreateQuad((i*size_x) + 564 - 64, (j*size_y)-(j)+64,64, 32, tGrass, 0, 0); this sort of thing worked out fine, as stated before, but the problem was when i tried to put it into a loop: for (int j = 0;j<3;j++) for (int i = 0;i<3;i++) qTile[j] = CreateQuad((i*tile_move_x) + tile_start_x, (i*tile_move_y) + tile_start_y, 64, 32,tGrass,0,0); and for youre reference: const int screen_width = 1024; const int screen_height = 768; const int tile_width = 64; const int tile_height = 32; const int tile_move_x = 32; const int tile_move_y = 16; const int tile_start_x = screen_width/2; const int tile_start_y = screen_height; the problem is that when i try it with the loop it comes up with a blank screen - even though it works fine when i do it manually without a loop. I would appreciate any comments people may have to offer Xpy
JUST-CODE-IT.NETManaged DirectX & C# TutorialsForumsArticlesLinksSamples
the_moo
the_moo
hey Xpyder,
i can see one thing wrong that would make quite a big difference:
qTile[j] = CreateQuad((i*tile_move_x) + tile_start_x,
(i*tile_move_y) + tile_start_y, ***On this line there is an "i"***
64, 32,tGrass,0,0);

This "i" should be a "j", otherwise it will be adjusting according to the X coordinate.

that's all i can see. let us know if that fixes it :)
the_moo
Xpyder
Xpyder
well spotted- but i think thats just a typo as it still doesnt seem to help - anyways, it is not even displaying them wrong, it is not displaying them at all - thanks for spottin that btw anyways

Xpy
JUST-CODE-IT.NETManaged DirectX & C# TutorialsForumsArticlesLinksSamples
Xpyder
Xpyder
hey moo, i seen youre site with the iso editor - that looks great - what algorithm did you use, i mean to draw the tiles - if its a "trade secret" ignore me / pull my legs off.

Xpy
JUST-CODE-IT.NETManaged DirectX & C# TutorialsForumsArticlesLinksSamples
tjoink
tjoink
Well, you want to loop your x counter from 3 to 0, and start with tile_start_y=0 i.s.o. screen_height. You see, right now you're drawing from screen_height and down. Offscreen that is, so this is probably your problem. i*tile_move_x should be j*tile_move_x.

Along the lines of (too tired to check this thoroughly):

for (int j = 2;j>=0;j--)
for (int i = 0;i<3;i++)

qTile[j] = CreateQuad((j*tile_move_x) + tile_start_x,
(i*tile_move_y),
64, 32,tGrass,0,0);

and for youre reference:

const int screen_width = 1024;
const int screen_height = 768;
const int tile_width = 64;
const int tile_height = 32;
const int tile_move_x = 32;
const int tile_move_y = 16;
const int tile_start_x = screen_width/2;
//const int tile_start_y = 0;

Hope I'm clear, and of help.
8! bits.. wow..
Tarviathun
Tarviathun
That's your problem. As tjoink said, you're drawing your tiles off screen.

(i*tile_move_y) + tile_start_y,

That's wrong. It should be:

(i*tile_move_y) - tile_start_y,

I believe that should solve your problem. Hope it helps.
tjoink
tjoink
No, the tile_start_y must be 0. Otherwise, you're still offscreen, but at the top of the screen.
8! bits.. wow..
Tarviathun
Tarviathun
I assumed the tile positions were world-relative. If they're all onscreen natively, then that'd work.
Xpyder
Xpyder
oh right yea- thanks a lot guys

Xpy
JUST-CODE-IT.NETManaged DirectX & C# TutorialsForumsArticlesLinksSamples

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.