Jump to content
  • Advertisement
Sign in to follow this  
KaLick

the movement of sprite

This topic is 3713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I don't know how to draw a sprite that can move the same speed when the game run by other computer.i don't know how calculate the time between two frame to measure the movement of sprite .help me.please

Share this post


Link to post
Share on other sites
Advertisement
You could set up a timer, and move using delta time.

Here is how I move my camera in my 3D game:


Camera.Move(GetDeltaTime() * 0.1f);

Share this post


Link to post
Share on other sites
Quote:
Original post by KaLick
I don't know how to draw a sprite that can move the same speed when the game run by other computer.i don't know how calculate the time between two frame to measure the movement of sprite .help me.please

You can decide that each frame shall take a constant time step, based on how many frames per second (FPS) you want your sprite movement to be updated in. For example 30 times per second:

Timestep = 1.0 / 30.0

Then you can have a variable, TimeSinceLastMovement, that stores how much time that has elapsed since the last movement update, and do not update the sprite movement until that time has reached your constant Timestep.

If it has reached higher than the constant Timestep, update the movement once and subtract Timestep from TimeSinceLastMovement, repeat until TimeSinceLastMovement is less than Timestep.

So if you compute Timestep like above and wait with the sprite movement until TimeSinceLastMovement reaches Timestep, the sprite movement will only be updated 30 times per second, and will therefore be the same on different computers (since the time of a second is the same on different computers).

If you're programming for the Windows operating system, you can get/query how much time has elapsed between frames by using the QueryPerformanceCounter Function, and the QueryPerformanceFrequency Function.

Which operating system are you programming for?

Share this post


Link to post
Share on other sites
Figure out how much time has elapsed since the last game loop update, and multiply that with all speeds that affect motion and animation.

If you use floating point numbers, you'll have an easy time of it. If you use real numbers, such as int, short, long, etc, you'll have to do some tweaking to get something working well.

Share this post


Link to post
Share on other sites
Thanks everybody.
I'm using XP and DXSDK2007.
I write like that:i don't know the compution of sp_rate is right?
QueryPerformanceFrequency(&timerFreq);
while (!doing)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
if (msg.message==WM_QUIT)
doing=1;

TranslateMessage(&msg);
DispatchMessage(&msg);
}

QueryPerformanceCounter(&timeStart);

Game_Run(hWnd);
QueryPerformanceCounter(&timeEnd);
sp_rate=( (float)timeEnd.QuadPart - (float)timeStart.QuadPart )/ timerFreq.QuadPart;
}
and in Gam_Run funtion,I move the sprite following sprite.move+=number*sp_rate
Is it right?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!