Archived

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

omegasyphon

my draw loop psedo code question

Recommended Posts

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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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?"

Share this post


Link to post
Share on other sites
thanks for the help i got it to work right. it was drawing weird tiles because i had my map file numbers set up like 08 instead of just 8 ive also decided to divide my bitmaps into quarters
and draw them on the screen as if they were 64 tiles

Share this post


Link to post
Share on other sites