2d game design
2d game design
2d game design
2d game design
2d game design
2d game design 2d game design 2d game design 2d game design 2d game design 2d game design 2d game design 2d game design
2d game design 2d game design
2d game design
Go Back  Xtreme Visual Basic Talk > > > 2d game design


Reply
 
Thread Tools Display Modes
  #1  
Old 10-20-2005, 02:09 AM
Danio Danio is offline
Regular
 
Join Date: Aug 2004
Posts: 70
Default 2d game design


Hello,

I am creating a 2d fighting gane with characters constantly animating(either moving forward, back or in place) and I sometimes get small delays between frames.

My logic was :
Create a Class called fighter with a timer in the class looping through the bitmaps(frames). Every bitmap is placed in a rectangle and is read by a threaded function in the main form:
Do Until Done
Draw()
GameLoopThrd.Sleep(20)
Loop

In the Draw() function every rectangle(that contains 1 frame) from the fighter classes is drawn using double buffering:
GFX.DrawImageUnscaled(FighterBMP,FighterRect)
GFX.DrawImageUnscaled(FighterBMP2,FighterRect2)
and drawn to the form
FormGFX.DrawImage(Backbuffer, 0, 0)

The class timer is set to 40ms and the thread sleep time is set to half not to miss a frame outputted by the class time.

Is there perhaps a better more performance way of going about this? I'm rather new at this..

Thanks!
Reply With Quote
  #2  
Old 10-20-2005, 07:35 AM
elnerdo's Avatar
elnerdo elnerdo is offline
Contributor
 
Join Date: Jul 2004
Location: Northern New Jersey
Posts: 490
Default

You should never have more than one timer in a program.

The way I'd recommend to have your character animated would be like this:

In your fighter class, have an integer named 'Frame'
Depending on what the value of frame is when you draw the fighter's image, draw a certain image.

Frame should be incremented in your main game loop. like so:

Counter += 1
frame = counter mod (number of frames in the animation)
__________________
nerds unite!
Reply With Quote
  #3  
Old 10-25-2005, 03:06 AM
Danio Danio is offline
Regular
 
Join Date: Aug 2004
Posts: 70
Default

Thanks, your right it is better.
Reply With Quote
Reply


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
2d game design
2d game design
2d game design 2d game design
2d game design
2d game design
2d game design 2d game design 2d game design 2d game design 2d game design 2d game design 2d game design
2d game design
2d game design
 
2d game design
2d game design
 
-->