Jump to content
  • Advertisement
Sign in to follow this  
osto

[.net] tilemap editor problem

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on some code to make a 2d tile based engine, but the problem is my editor. When i drag the mouse around it's blit the tile from image imgTileset but i soon realise that its start to get a little bit jerky after a lot of movement. how can I change the mousemovement method so it only paint the new area. I tried using invalidate but (note not in code below) but it doesn't work. can someone help? or is there any tilemap editor with source code out there in C# or VB.NET?
		void MapPicMouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
			mapPaint = true;
			tile[e.Y/16,e.X/16] = tileSelect;
			mapPic.Refresh();
		}
		
		void MapPicMouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {
			if(mapPaint) {
				if((e.Y > 0 && e.Y < this.mapPic.Height) && (e.X > 0 && e.X < this.mapPic.Width)) {
					tile[e.Y/16,e.X/16] = tileSelect;
				}
				
				mapPic.Refresh();
			}
		}
		void MapPicMouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
			mapPaint = false;
		}
		void MapPicPaint(object sender, System.Windows.Forms.PaintEventArgs e) {
			Graphics g = e.Graphics;
			Rectangle Rect = new Rectangle(0,0,16,16);
			
			for(int y=0; y < YMap; y++) {
				for(int x=0; x < XMap; x++) {
					Rect.X = x * 16;
					Rect.Y = y * 16;
					
					if(tile[y,x] >= 0)
					g.DrawImage(imgTileset,Rect,(tile[y,x]% 7) * 16, (int)(tile[y,x] / 7) * 16, 16, 16, GraphicsUnit.Pixel);
				}
			}
		}

Share this post


Link to post
Share on other sites
Advertisement
The jerkiness problem could be caused by a delay in the message queue for MouseMove events. Well, not a delay in the message queue itself, but a delay in the handling of those events. What you might try to do is to write a function with a time that is called after a MouseDown event, which polls every 100 (or so) milliseconds for a hit test and then repaints based off of that position rather than using the MouseMove event. Of course, you're going to have to test within this function for the mousedown event, but it might make the movement less jerky.

Share this post


Link to post
Share on other sites
i found the solution to my problem


void MapPicMouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {
if(mapPaint) {
if((e.Y > 0 && e.Y < this.mapPic.Height) && (e.X > 0 && e.X < this.mapPic.Width)) {
tile[e.Y/16,e.X/16] = tileSelect;
}

Rectangle RectClip = new Rectangle((int)e.X/16 * 16, (int)e.Y/16 * 16, 16, 16);

mapPic.Invalidate(RectClip);
}
}
void MapPicMouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
mapPaint = false;
}
void MapPicPaint(object sender, System.Windows.Forms.PaintEventArgs e) {
Graphics g = e.Graphics;
Rectangle Rect = new Rectangle(0,0,16,16);

if(e.ClipRectangle.Width == 16) {

g.DrawImage(imgTileset, e.ClipRectangle, (tile[e.ClipRectangle.Y / 16, e.ClipRectangle.X /16]% 7) * 16, (int)(tile[e.ClipRectangle.Y / 16, e.ClipRectangle.X /16] / 7) * 16, 16, 16, GraphicsUnit.Pixel);
}
else {
for(int y=0; y < YMap; y++) {
for(int x=0; x < XMap; x++) {
Rect.X = x * 16;
Rect.Y = y * 16;

if(tile[y,x] >= 0)
g.DrawImage(imgTileset,Rect,(tile[y,x]% 7) * 16, (int)(tile[y,x] / 7) * 16, 16, 16, GraphicsUnit.Pixel);
}
}
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!