Draw an object moving fast

Started by
15 comments, last by blow 17 years, 8 months ago
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?
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.
If you update your game more times per second you can make it smaller without decreasing it's speed.
Thank you!
Im using java and i cant use directx...
Can yout link me some useful article of time based and frame based animation?
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.
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

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 somethinglong 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;}
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?
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.

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?

This topic is closed to new replies.

Advertisement