Public Group

# Tile Map

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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]

##### Share on other sites
Quote:
 Original post by four_star00My question is my map shows the tiles but us going diagonal

Can you show a screenshot or something to illustrate your point?

##### Share on other sites
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

##### Share on other sites
 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.

##### Share on other sites
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

##### Share on other sites
You'll want to change
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.

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633661
• Total Posts
3013226
×