Administrator

Administrator

  • Tech Writer
  • 2.2k
  • 1.5m

GDI+ only interface scrolling

Mar 14 2003 1:54 PM
Ok, I know one answer to this question, "Use DirectX", but I was hoping I'd get another anwer. Here it goes! I am writing a simple turnbased strategygame for fun, and have just started with the interface. I use a WinForm Form, with FormBorderStyle.None to get an illusion of fullscreen. This Form is drawn exclusively using GDI+, no controls save the Form itself. The interface contains a thin frame with some buttons (not controls), and a big map in the middle. This map is of the size 2048*1536, I draw it to the "client" using the drawImage method, naturally it wont fit at once, and I want to scroll it when the mouse reaches the screenedge. All this is working, but not very fast. This is the method used: Bitmap map=new Bitmap(2048,1536); int topLeftX=0; int topLeftY=0; OnPaint(...) { Graphics g=Graphics.FromHWND(this.Handle); g.DrawImage(map,new System.Drawing.Rectangle(30,30,1245,989), topLeftX, topLeftY, 1245,989,System.Drawing.GraphicsUnit.Pixel,null); } OnMouseMove(MouseEventArgs mea) { if(mea.X<2) { topLeftX-=10; g.DrawImage(map,new System.Drawing.Rectangle(30,30,1245,989), topLeftX, topLeftY, 1245,989,System.Drawing.GraphicsUnit.Pixel,null); } } } This is just to show the method I use, but it is way too slow, I would need something that would be at least 10 times faster. The reason I use GDI+ is that I don't have the time to learn DirectX now, and GDI+ looks alot like Java2D wich I know. What I am hoping for is something like i Java2D where if you use the class Image instead of BufferedImage you get 10 times the speed. If you like and dare you can download the gameinterface at: http://www21.brinkster.com/xaake/ECEDOI.htm Thanks in advance /Rickard Haake

Answers (4)