开发者

level editor's tiles don't change when I hold the mouse down?

Can someone tell me why my level editor's tiles don't change when I hold the mouse down? Full source: http://pastebin.com/U3KKSRT8

private void MapPanel_MouseDown(object sender, MouseEventArgs e)
        {
            map.tiles[(int)(System.Windows.Forms.Cursor.Position.X / map.tileSize)][(int)(System.Windows.Forms.Cursor.Position.Y / map.tileSize)] = 1;
            MapPanel.Refresh();
        }

And this is where the map is drawn.

 private void MapPanel_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            GraphicsUnit units = GraphicsUnit.Pixel;

            for (int i = 0; i < map.tiles.Length; i++)
            {
                for (int j = 0; j < map.tiles[i].Length; j++)
                {
                    Rectangle destRect = new Rectangle((i * map.tileSize) - hScrollValue, (j * map.tileSize) - vScrollValue, 30, 30);
  开发者_如何学Python                  g.DrawImage(tileMap, destRect, (map.tiles[i][j] * 50), 0, 50, 50, units);
                }
            }
        }


Did you check that the index into the map.tiles array is calculating to an expected value? I think that System.Windows.Forms.Cursor.Position is giving you screen coordinates and you probably want to work with client coordinates of MapPanel. Have your tried using X,Y properties of the MouseEventArgs class in your calculation?

I took a quick look at your code and you will also need to factor the scroll position into that calculation of the index. I say this based on the fact that your Paint routine is offsetting the rendered cells based on the scroll position.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜