DirectDraw problem.. help

Started by
12 comments, last by Alec999 22 years, 1 month ago
Don''t use the offset by "1",just use more little number (for example 0.09)and use the Time reference to contral the speed and FPS.

goddess just one...
汇编语言不会编
Advertisement
initial_y >> can you be more specific .. what (offset by "1") do you mean?
The only easy day was yesterday.
Yes,I will say the "S" means speed of a ball.on the assumption that the ball moving just in its x direction and "X" is its position in x axis.I also assume "Delay" is the delay between Frames.
then the following formula is the method of smooth moving:

X=X+S*Delay

x''s units is pixel;
s''s units is pixel per millisecond;
Delay''s units is millisecond;

For example, I want the ball has a speed 20 pixels per second.Then the actual speed of the ball is:
S = 20/1000 = 0.02 (pixel per millisecond)

How to get the Delay?At the beginning os game loop Use the method GetTickCount() to get current tick count on millisecond---"t0".then before render next frame use this method again--"t1".
Delay = t1-t0
For example Delay = 1000 milliseconds
then X=X+0.02*1000

The offect of this frame is 20 pixels.

However there is a problem ,the frame rate.I will give you the method Sleep().I think you can work out it yourself.







goddess just one...
汇编语言不会编

  float PosX;  //Xpos of whatever you want to move.float SpeedInPixPerSecond = 20.0; //20 pixels pr. second.PosX += SpeedInPixPerSecond * ((float)TimeInMilliseconds/1000.0);  


Same applies for y-axis.


-------------Ban KalvinB !

This topic is closed to new replies.

Advertisement