#### Archived

This topic is now archived and is closed to further replies.

# my draw loop psedo code question

## Recommended Posts

omegasyphon    100
ok i have my loop set up like this x2 and y2 are my starting variables set to 0,0 to start drawing my tiles. map is an array of 10x7 the problem is when i run it it puts tiles all over the place in where they should not be and it only draws about 3 out of the 7 i have to detect im not sure why also is this a good way to go about doing this?
  for x=0; x<=10;x++ { for y=0;y<=7;y++ { if map=1 draw tile 1 if map=2 draw tile 2 . . . x2=x2+64; if x2==640 x2=0 y2=y2+64; } } 

##### Share on other sites
Kayan    122
This is simple you just need two For loop like that

  for(int y=0;y<7;y++){ for(int x=0;x<10;x++) { /*put your drawing tile function here*/ x2+=64; } x2=0; y2+=64; }

##### Share on other sites
zedzeek    529
and i''ld go

drawTile(x*64,y*64)

theres no need for x2 + y2

##### Share on other sites
Coconut    122
If I am reading your code right, your tiles are 64x64. There are several problems here. First of all, you are assuming that the x coord will always end up on 640. If you are doing scrolling, you would have to scroll 64 pixels at a time and that would be VERY choppy. Another problem is the code makes the assumption that all tiles will only take up 1 base-tile-unit(one 64x64 square). I would also create a class that encompasses your tiles, map, and everything. That way, you would be able to make the code very versatile. If thats not very clear, tell me and Ill try to expand.

Brent Robinson
"What if this is as good as it gets?"