Jump to content
  • Advertisement
Sign in to follow this  
blow

Draw an object moving fast

This topic is 4352 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

Hi all im new in this forum! I have a little problem, i have to draw a fast object. Now to move an object i use this tecnique: x+=dx where dx is pixel covered distance in a process. When dx is little the aniamtion is smootly, but when the dx is too big the animation is bad and not smootly, how can i resolve it?

Share this post


Link to post
Share on other sites
Advertisement
You could use motion blur.

If you use DirectX:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/PixelMotionBlur_Sample.asp

You can do something similar for the API of your choice.

I'd also like to add that you may want to do the animation time_based in stead of frame based, if you are not already doing so. (Calculate the time passed between consecutive frames and multiply that by a dx, so the movement is greater if the frame took longer).

Greetings.

Share this post


Link to post
Share on other sites
Thank you!
Im using java and i cant use directx...
Can yout link me some useful article of time based and frame based animation?

Share this post


Link to post
Share on other sites
Quote:
Original post by bytecoder
If you update your game more times per second you can make it smaller without decreasing it's speed.


Yes but the update cicle occupies a lot of cpu if im reduce dt time.

Share this post


Link to post
Share on other sites
Quote:
Original post by blow
Yes but the update cicle occupies a lot of cpu if im reduce dt time.


Games typically aim for using 100% of the CPU. So go ahead and use it, unless it's some windowed application that's supposed to play nice with other applications.

-me

Share this post


Link to post
Share on other sites
Quote:
Original post by blow
Thank you!
Im using java and i cant use directx...
Can yout link me some useful article of time based and frame based animation?


How are you doing graphics with Java? Regular Java2D, JOGL, etc?

You can find the current time in java using System.currentTimeMillis(). Then between updates you can determine the elapsed time by storing the time at your last frame and checking what time it is now (and then making that time the new "previous time").

Then use the elapsed time in your calculations, so instead of x += dx, you have x += (dx*elapsed_time), which links the moving speed to real time (windows only seems to be accurate within like 16-20 milliseconds) rather than frame rate, which can smooth things out if the frame rate lags or something (still jitters, but not as much).

...or you can take a bunch of average elapsed times, so when the frame rate slows down significantly, it won't jitter as much.




//...
//make sure to initialize to something
long last = System.currentTimeMillis();
long current;

// finds the time since the last time this was called!
public long findElapsedTime() {
// stores elapsed time
long elapsed;

// gets the new current time
current = System.currentTimeMillis();

// find the time since our last calculation
elapsed = current - last;

// make our current time now the one to use next time
last = current;

// spit out our elapsed time
return elapsed;
}

Share this post


Link to post
Share on other sites
Ok now i want use 100% cpu.
When a game is frame-based end when is time-based? tick-based is sinonimus of frame-based?
Im programming 2D game, what mode you suggest me?

Share this post


Link to post
Share on other sites
Quote:
You can find the current time in java using System.currentTimeMillis().
If you're using Java 1.5, you should use System.nanoTime() instead, it has a much higher resolution.

Share this post


Link to post
Share on other sites
Quote:
Original post by mako_5
Quote:
Original post by blow
Thank you!
Im using java and i cant use directx...
Can yout link me some useful article of time based and frame based animation?


How are you doing graphics with Java? Regular Java2D, JOGL, etc?

You can find the current time in java using System.currentTimeMillis(). Then between updates you can determine the elapsed time by storing the time at your last frame and checking what time it is now (and then making that time the new "previous time").

Then use the elapsed time in your calculations, so instead of x += dx, you have x += (dx*elapsed_time), which links the moving speed to real time (windows only seems to be accurate within like 16-20 milliseconds) rather than frame rate, which can smooth things out if the frame rate lags or something (still jitters, but not as much).

...or you can take a bunch of average elapsed times, so when the frame rate slows down significantly, it won't jitter as much.


*** Source Snippet Removed ***

Thank you! in this case the gameLoop is a thread whit no pause?
like this:
Thread gameLoop=new Thread("GameLoop"){
public void run(){
while(gamePlay){
processPosition(elapsedTime);
}
}
};


In processPosition method i have x+=dx+elapsedTime;
Is good code?

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!