Tile Map
I am making a 2d tile map using C# in the .Net platform.
My question is my map shows the tiles but us going diagonal
Any Help
also any info on the relationship between the array and the coordinates and size of the image would help too.
byte[,] myPic = new byte[102, 101];
for (int y = 0; y < 102; y++)
{
for (int x = 0; x < 101; x++)
{
myPic[x, y] = 0;
Graphics dc = this.CreateGraphics();
this.Show();
Image myImage = Image.FromFile(@"c:\\Stone.bmp");
dc.DrawImage(myImage, x+=20, y+=4, 20, 20);
}
}
[Edited by - four_star00 on September 24, 2005 5:45:36 PM]
Quote:Original post by four_star00
My question is my map shows the tiles but us going diagonal
Can you show a screenshot or something to illustrate your point?
I can describe it
using the numbers in the above code,
when I rum my form
my map goes diagonal down
I have noticed by playing around with the numbers
the tiles overlap or spread apart and go diagonal
using the numbers in the above code,
when I rum my form
my map goes diagonal down
I have noticed by playing around with the numbers
the tiles overlap or spread apart and go diagonal
dc.DrawImage(myImage, x+=20, y+=4, 20, 20)
This would appear to be the problem. Correct me if I'm wrong, but wouldn't you want x + 20, y + 4 instead ? What you're doing here is incrementing the variables themselves, instead of using the values and adding to them to create a new number.
I made the corrections and it fixed the diagnal problem but the tiles are overlapping each other instead of each tile being seen fully
Any pointers
Any pointers
You'll want to change
(I'm assuming 20, 20 is the size of the image)
This will make it so the loop supplies the x and y coordinates of the tile and then places them in the correct position on the screen for those coordinates rather than just moving across 1 each time like with the addition.
dc.DrawImage(myImage, x+=20, y+=4, 20, 20)
to be dc.DrawImage(myImage, x * 20, y * 20, 20, 20)
(I'm assuming 20, 20 is the size of the image)
This will make it so the loop supplies the x and y coordinates of the tile and then places them in the correct position on the screen for those coordinates rather than just moving across 1 each time like with the addition.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement