You've set Timer1's Interval property to "300".
A lower value (like "50") would not only speed things up but
greatly reduce the choppiness.
Be aware, though, that DrawImage can be slower than using
texturebrush code (as shown in the "SpriteSheetAnimation.zip" attachment
that passel attached to
post #15 of your
"Copy Tiles from a Sheet" thread).
Edit:
Also - you know you don't really need a non-visible picSource as a backbuffer?
You are already have already created a in-memory backbuffer with this line:
Code:
Dim src_Image As Bitmap = New Bitmap(Application.StartupPath & "\Basis.png", True)
So these lines are really not needed:
Code:
' Display tiles in picSource picturebox
picSource.Image = src_Image
All that has to be done is change the dim-ming (scoping) of "src_Image" from
locally (inside the Form Load event), up to a Form level declaration.
To do that, change this:
Code:
Private srcRect As Rectangle = New Rectangle(0, 0, 32, 32) 'Use to select a tile from the source
Private dstRect As Rectangle = New Rectangle(0, 0, 32, 32) 'Use to place a tile on the game map
Private DestBmp As Bitmap 'Persistent place to hold our output map
Public MapWidth As Integer
Public MapHeight As Integer
Private AniTileX As Integer
Private Reduce As Boolean
..to this (***see note below):
Code:
Dim srcRect As Rectangle = New Rectangle(0, 0, 32, 32) 'Use to select a tile from the source
Dim dstRect As Rectangle = New Rectangle(0, 0, 32, 32) 'Use to place a tile on the game map
Dim DestBmp As Bitmap 'Persistent place to hold our output map
Dim MapWidth As Integer
Dim MapHeight As Integer
Dim AniTileX As Integer
Dim Reduce As Boolean
Dim src_Image As Bitmap = Nothing '<----line added
Then you can change this:
Code:
' Holds the source tiles bitmap to be used to select tiles from
Dim src_Image As Bitmap = New Bitmap(Application.StartupPath & "\Basis.png", True)
..to this:
Code:
src_Image = New Bitmap(Application.StartupPath & "\Basis.png", True)
..and this line (in the Form Load event) can be commented out:
Code:
'picSource.Image = src_Image
After that you can use Edit menu -> Quick Replace (Ctrl + H) to change all occurrences of "picSource.Image" to "src_Image"
So this:
Code:
' Draw water tiles to picDest
gr.DrawImage(picSource.Image, dstRect, MysrcRect, GraphicsUnit.Pixel)
..becomes:
Code:
' Draw water tiles to picDest
gr.DrawImage(src_Image, dstRect, MysrcRect, GraphicsUnit.Pixel)
..and this:
Code:
' Draw selected tile to picDest
gr.DrawImage(picSource.Image, dstRect, MysrcRect, GraphicsUnit.Pixel)
..becomes:
Code:
' Draw selected tile to picDest
gr.DrawImage(src_Image, dstRect, MysrcRect, GraphicsUnit.Pixel)
..and the picSource control can be deleted.
I know it doesn't really effect your animation issue,
but why use controls for backbuffers
when they are not needed for that purpose.
***Oh..and if you weren't aware of this..
I believe if you don't specify an access modifier when Dim-ing,
it will be Private by default at the Form declaration level,
(there's a
stackoverthread thread dealing with this - tends to confuse C# developers).
Generally "Public" isn't used as a Form level declaration unless the
variable needs to be shared with another form or module
(and even then you've got the option of "Friend" scoping).
The "guideline" (not a hard and fast rule) is given in this MSDN article: "Variable and Method Scope in Microsoft .NET":
Quote:
|
A general guideline for scoping variables is that you want to keep the scope of variables as local as possible.
|
It also mentions:
Quote:
Use "m" as the prefix to indicate that this variable is scoped at the module level.
This Private variable can now be accessed by any procedure in this module.
|
Personally I like to use "m_" as a prefix for form level variables so I know what I'm dealing with
and can quickly scroll up and find them in the .Net IDE form code window.
However it's just a guideline I use..nothing more.
I think it's more important to be consistent,
than to be hung up on naming convention dogma.
You can read through the following
stackoverflow thread and see what you think.