Graphics draw speed very slow.

09-18-2006, 04:21 PM
Hi Everyone,

for about the last 6 weeks or so i have been working on a Hex tile based game and through some help from Iceplug i have gotten it to a point i am quite comfirtable with, however, the grapics component (draw() ) is really very very slow to update. (did i say very? :P)

i think my problem lies in the fact that im actually doing several draws. (and a draw to the background?) let me paste some code for you all. i really look forward to your ideas and thoughts as to how to make it faster.

thanks again.

Extract.txt included to show code sample.

09-18-2006, 04:52 PM
You can definately improve on the speed here, the Graphics object is far from being a fast renderer, but with some optimisations there could be some reasonably significant speed gains for you.

The first thing that jumps out at me is the fact that you have the following code in each of the 4 drawing subs.
picturebox1GFX.DrawImage(Backup, Me.ClientRectangle())
PictureBox1.Image = Backup
As far as I can make out this basically just updates the screen, something which doesn't need to be done untill the end of the drawing process. As such you should be able to remove these two lines of code from the 4 methods, and add it in to the Graphics_draw method after calling E_unit_draw(). Each call to DrawImage is expensive so it is best to call it as few times as possible. I'm assuming you probably get flickering at the moment (unless the applications in a tight enough loop not to update the UI)?

I have a few other ideas, which mainly revolve around being more selective when deciding not to draw. It would help if you show where the Graphics objects are Initialised, as at the moment I'm making educated guesses as to which Bitmap is loaded into what.

Also having not followed any conversations between yourself and the ever helpful Iceplug, I am unaware of the details of your game. Is the game realtime or turn based? The reason I ask is the Graphics object is more efficient at drawing a large image than it is at drawing lots of small images. Therefore the less times you can draw the entire map the better.

I probably won't get back to this untill tomorrow evening, but if you haven't recieved enough help by then I'll be happy to see what further assistance I can be.

09-18-2006, 05:49 PM
No need to quote the entire previous message.Thanks for the very prompt response Cags, its really much appreciated. :)

Its funny but I was kind of thinking about the code some more and you posted exactly what I was thinking of doing, your clearly one step ahead of me :)

By having that in only the last Sub then it really has sped up significantly to be about perhaps now a 200-400 ms delay after calling an image redraw.

Some details of the game are as follows: It’s a real time based top down tile based game where players control unit on the hex “board” as players move their pieces around the X/Y location data is saved into a database. Its based on a classic old tabletop wargame called “battletech”. The map itself is made up of hexagons 60 pixels wide. There is at a maximum 100 Hexes wide by 100 hexes High. Each side has a unit which is a square icon about 30 pixels wide which sit inside the hexes.

These are intialised with a:
F_IMG = New Bitmap(dataloc & "\" & Fimage)
Me.CharacterLocation = New Point(Funit.Unit_X, Funit.Unit_Y)

The main idea that I had was to only draw the actual unit icons instead of redrawing the terrain and terrain_detail subs. However what happens there is that a “shadow” is left behind of where the old unit used to be, so the only way to get around this so far has been to redraw the whole map again. So perhaps I was thinking of that as a way to sort of improve the draw time?

Once again I really appreciate your help I have such a long way to go.

PS is the name of the game

09-22-2006, 07:02 PM
Or just redraw the region affected (i.e. the tile that the unit was on)

09-24-2006, 05:41 PM
Or just redraw the region affected (i.e. the tile that the unit was on)

Yes indeed that is the best way as far as i can see, to do 2 things,

1. redraw the new Hexagon witht he unit now placed in it.
2. redraw the hexagon that the unit has left with its terrain.

boy that really sounds a lot easier than it is to code.

Also Iceplug, a very big thank you to you for some help i got out of an article that you did a fair while ago, about Hex based tile games etc.

once i figure it out (more like find the time to do it :P) ill post the outcome here.

Thanks again.


10-19-2006, 07:38 PM
Hi Everyone, ok sorry for the Bump in the post but i am a little bit stuck,

i have got the co-ordinantes of the two tiles which i need to redraw, and i have even come up with the new look of the bitmap that will be redrawn, but how do i overlay this over the old Bitmap?

currently im just replacing the bitmap witht he new one, which doesnt work so well :/

Many thanks

PS thanks to all posters in here i have gotten so much help just from reading these forums they really are an awesome resource!

10-20-2006, 04:48 AM
By using the graphics .drawimage function overload that takes two integers, and a rectangle.

GFX.DrawImage(Pic, SrcX, SrcY, New Rectangle(DestX, DestY, DestW, DestH), GraphicsUnit.Pixel)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum