Game Tile Animation
Game Tile Animation
Game Tile Animation
Game Tile Animation
Game Tile Animation
Game Tile Animation Game Tile Animation Game Tile Animation Game Tile Animation Game Tile Animation Game Tile Animation Game Tile Animation Game Tile Animation
Game Tile Animation Game Tile Animation
Game Tile Animation
Go Back  Xtreme Visual Basic Talk > > > Game Tile Animation


Reply
 
Thread Tools Display Modes
  #1  
Old 08-10-2012, 04:04 AM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default Game Tile Animation


I've been searching around here for about 3 hours and
i haven't found anything good about doing game tile animations.

I did it in VB6 with some help from people here and since VB6
wasn't a multithread program, the animations were a bit choppy
and character movements froze during mid step. I guess the animating
was eating up the processing time and slowed things down.

Now that i'm using VB net 2010, this is a multithreaded program
and it should handle animations much better.

I was wondering if there is any sample code around here or an
animation class that uses mutithreading. I've never done that before,
so i don't know how to start.

I wanted to do a test run using 32x32 tiles, with the map being 20x15.
These are all water tiles that have 3 tiles that make up the animation.
I suppose the sequence would be 1, 2, 3 - 3, 2, 1 - 1, 2, 3

20 tiles across and 15 tiles down is 300 animating tiles. I just want to
see how VB handles all the animations.
Reply With Quote
  #2  
Old 08-10-2012, 06:35 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default Tile animations

Quote:
Originally Posted by VB_Alien
I've been searching around here for about 3 hours and
i haven't found anything good about doing game tile animations.
Three hours..really?

I made up a sample water tile animation test in about 5 minutes.

In case you didn't know it...unlike VB6, VB.Net supports gif animations natively.
Here is an example.

There is no multi-threading needed.

If you want to get fancy you can use the ImageAnimator Class.
Sample code here.

However, as the attached tile animation test shows,
the ImageAnimator Class is not really needed.
Attached Images
File Type: jpg screenshot_water_tile_animation_test.JPG (7.9 KB, 12 views)
Attached Files
File Type: zip _water_tile_animation_test.zip (29.9 KB, 20 views)
Reply With Quote
  #3  
Old 08-10-2012, 10:01 PM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default

I am drawing more than one tile in a picturebox, so
that code will not work for me.

Your loading a gif into a picturebox, where-as i am
drawing one from a sprite sheet to a picturebox....

Thanks anyway
Reply With Quote
  #4  
Old 08-11-2012, 02:56 PM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default

Here is a sample of what i'd like to do
as far as animating game tiles.

The problem with the way i do it, is that
the animations look choppy. I'd like to know
if there is a smoother way to animate tiles.
Attached Files
File Type: zip Animation.zip (142.2 KB, 11 views)
Reply With Quote
  #5  
Old 08-11-2012, 03:17 PM
hDC_0Game Tile Animation hDC_0 is offline
Contributor

* Expert *
 
Join Date: Feb 2004
Posts: 559
Default Drawimage and timer for tile animation

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.

Last edited by hDC_0; 08-11-2012 at 04:59 PM.
Reply With Quote
  #6  
Old 08-12-2012, 07:02 AM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default

Ya. About the picSource picturebox, i already knew
about storing that image in memory but in my haste to
make a demo, my brain resorts to using the old VB6
ways of doing things. I find this habit hard to break.

I fixed that problem and set all my variables to private
but i'm comfortable in my naming conventions. I'll keep
what i got. In fact, i never even knew that was a problem
until you mentioned it. To each his own, i guess.

Your right though, it did nothing to help with the animation
choppiness. Running the timer faster only speeds up the animation
and you really don't see each frame of it. Maybe this is just a
personal problem with my liking, i don't know.

I would appreciate it if passel or Iceplug (Our resident game creator) could way
in here and let me know what he thinks about my animation. Is it to choppy
to you? If so, is there a way for a smoother transition from one tile t the next?
Maybe the problem is that there just isn't enough water tile transitions to make
it look smoother. Maybe instead of 3 tiles, there could be 6.

After looking at passels "Sprite Sheet Animation" i tend to agree that DrawImage
does draw a lot slower than a texture brush does. I thought about that when i first
did this demo but frankly, i don't understand it, so i just used the easy way of doing it.

I'll look it over some more. Maybe i can package it up in a class that can be used
for any graphics animations.

Last edited by VB_Alien; 08-12-2012 at 02:15 PM.
Reply With Quote
Reply

Tags
animation, game tiles, maps


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Game Tile Animation
Game Tile Animation
Game Tile Animation Game Tile Animation
Game Tile Animation
Game Tile Animation
Game Tile Animation Game Tile Animation Game Tile Animation Game Tile Animation Game Tile Animation Game Tile Animation Game Tile Animation
Game Tile Animation
Game Tile Animation
 
Game Tile Animation
Game Tile Animation
 
-->