Register
Site Login
Site Search
Forums
Advertisement
Welcome to PocketMatrix. PocketMatrix is dedicated to providing the best online community for mobile device developers and enthusiests. What's new?

Smooth Game Animation - GAPIDRAW APPROACH


Smooth Game Animation - GAPIDRAW APPROACH

Postby denthorq » Aug 23, 2004 @ 7:21am

Hi There,

I've read thousand posts regarding animations. So I decided to post my approach on GapiDraw. Can you make this as an sticky Johan? Hope this will enlighten our budding programmers out there.

I will assume that you're already using GapiDraw ;-)

1. Framerate Time/Ratio Animation
- this means that you have to maintain your increment ratio based on the target framerate / current framerate. so if your target and current is 40/40 then x increments by 5 * 1 which is equal to 5. if the framerate drops at 20fps the the ratio is 40/20 = 2 so x will increment by 5 * 2 which is equal to 10 etc

Code: Select all









10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
#define TARGET_FPS 40
#define MINIMUM_FPS 20

FLOAT m_FrameRate;
FLOAT m_SyncSpeed;

HRESULT CMyApplication::ProcessNextFrame(CGapiSurface* pBackBuffer, DWORD dwFlags)
{
    OnSyncSpeed();

        // all you need to do here is multiply everything that moves with the variable 'm_SyncSpeed'

        // example

        static int x = 0;  //or float/fixed

        x = x + 5 * m_SyncSpeed;

        // just dont forget to cast your variables (int) x or use FIXED or FLOAT to avoid rounding off a lot.

    return S_OK;
}

void CMyApplication::OnSyncSpeed()
{
    m_pTimer->GetActualFrameRate(&m_FrameRate);

    if (m_FrameRate > TARGET_FPS)
    {
        m_FrameRate = TARGET_FPS;
    }
    if (m_FrameRate < MINIMUM_FPS)
    {
        m_FrameRate = MINIMUM_FPS;
    }

    m_SyncSpeed = TARGET_FPS/m_FrameRate;
}

39 lines; 8 keywds; 4 nums; 48 ops; 0 strs; 4 coms    Syntactic Coloring v0.4 - Dan East  


2. Time Based Animation
- this means that you only need the increment x after 1 sec. so if you want to increment the x after every 5 secs then add 5000 instead.

Code: Select all









10 
int m_Timer;

if (m_Timer < (int) GetTickCount())
{ // this must be in the game loop

   m_Timer = GetTickCount() + 1000; // 1 sec

   x = x + 5;
}

10 lines; 3 keywds; 2 nums; 18 ops; 0 strs; 2 coms    Syntactic Coloring v0.4 - Dan East  


Animation is as simple as that ;-)

Good luck.

/special thanks to FASTRX for FLOAT/FIXED comments.
X-FIGHTER It's worth the wait...
User avatar
denthorq
pm Insider
 
Posts: 447
Joined: Apr 18, 2003 @ 9:15pm
Location: USA-PHILIPPINES


Return to GapiDraw


Forum Description

The Cross-platform Graphics SDK for Palms, Pocket PCs, Symbian Devices, and Stationary PCs.

Moderators:

sponge, Johan

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum