1

My Form2 is in layman terms an external 'mini-map' off the actual 'mini-map' in-game.

As you can see on my Form2, my drawn red dot does not have the same location for my player when compared to the 'mini-map' in-game which is the yellow dot.

In the DebugView, you can see my characters X and Y location (charX & charY).

The coordinates are passed as int x & int y in a function to my Form2 class file.

The image in my pictureBox1 (which is the image in the current example picture above) is pulled from my server (url= "http://randomspam.co/MAP/103000000.img/miniMap.canvas.png").

Here is the following code with comments to my progress as of now.

Please take note that the pictureBox1 location is set to 0,0.

The errors are as follows;

1) The red dot location on my external mini-map != the location of my character in the mini-map in-game.

2) The red dot consistently flickers (appears & disappears)

3) The tooltip when shown on the pictureBox is really lagging in revealing and dis-revealing itself.

If anyone knows how to help out my current situation (as I am lost), please, anything is appreciated.

Thanks.

Andrew
  • 552
  • 2
  • 10
  • 29
  • X and Y values are already normalized when you call CUpdate? – tweellt Mar 11 '14 at 23:44
  • One thing that isn't simple to do but really improves performance is to use double buffering. If you search online I think you will find lots of sample code in C# for these sorts of things. I believe controls also have a flag for double buffering which might help. Hope this gives you some direction! – drew_w Mar 11 '14 at 23:50
  • @tweellt, what do you mean normalized? It just passes it to another int. – Andrew Mar 11 '14 at 23:53
  • @Andrew, I mean, are they already "converted" to the scale of the mini-map, something like PointToClient? – tweellt Mar 11 '14 at 23:56
  • @tweellt, No, I do not know how to do the scaling. These are raw x&y coordinates of my character in-game (picture shows what I mean). – Andrew Mar 11 '14 at 23:57
  • The dots not matching is really strange. Both images are the same size so no need for scalling. – γηράσκω δ' αεί πολλά διδασκόμε Mar 12 '14 at 00:57

2 Answers2

2

Ok, lets split this in topics:

1) Red Dot Location:

Here you have to match red dot position to the new size, this was answered several times before, see this -> How can I transform XY coordinates and height/width on a scaled image to an original sized image?

2) Double Buffer to stop Flickering:

public void DrawWhatever(Graphics graphics, int cx, int cy)
{
    Graphics g;
    Bitmap buffer = null;
    buffer = new Bitmap([image width], [image height], graphics);
    g = Graphics.FromImage(buffer);
    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

    // Draw a circle.
    Pen p = new Pen(Color.Red,1)
    g.DrawEllipse(p,cx,cy,30,30); //example values

    graphics.DrawImage(buffer, 0, 0);
    g.Dispose();
}

3) Tooltip:

Check double buffer algorithm and let me know

Community
  • 1
  • 1
tweellt
  • 2,171
  • 20
  • 28
1

Have a copy from the mini map:

Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Bitmap bmpClone = new Bitmap(pictureBox1.Width, pictureBox1.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

Graphics objGraphics = Graphics.FromImage(bmpClone);
objGraphics.DrawImage(pictureBox1.Image, 0, 0);
objGraphics.Dispose();

bmp = (Bitmap)bmpClone.Clone();
pictureBox1.Image = bmp;

Now before any invalidation do:

Graphics objGraphics = Graphics.FromImage(bmp);
objGraphics.SmoothingMode = SmoothingMode.HighQuality;
objGraphics.DrawImage(bmpClone, 0, 0);
objGraphics.FillEllipse(Brushes.Red, cx, cy, 5, 5)
objGraphics.Dispose();

pictureBox1.Invalidate();

You dont need anything inside pictureBox1_Paint

valter