|
Tetris Troubles
I am making a tetris game with DirectDraw 7. I''m close to bieng finished, but I have a small problem....the framerate. I tried using the WM_TIMER message to tell the piece to fall, etc. But the result was a VERY choppy motion coming down. Could someone explain a better way of fixing this? Thanks in advance.
[source]#define Jesus 1[/source]
Aint no expert on this but I don't think you need to get Windows to tell an object to move. I think it's better that you move the object by a velocity of your choice. Like by two pixels each frame. Also you should lock your game loop into a certain frames per second so that on everyone's computer fast or slower than yours will move the block at the same speed.
e.g - Extract. Game loop
Dark Star
Edited by - Dark Star on May 8, 2001 11:20:53 AM
e.g - Extract. Game loop
|
Dark Star
Edited by - Dark Star on May 8, 2001 11:20:53 AM
---------------------------------------------You Only Live Once - Don't be afriad to take chances.
Aint no expert on this but I don''t think you need to get Windows to tell an object to move. I think it''s better that you move the object by a velocity of your choice. Like by two pixels each frame. Also you should lock your game loop into a certain frames per second so that on everyone''s computer fast or slower than yours will move the block at the same speed.
e.g - Extract. Game loop
at the end of the game loop the while loop is used to wait until a certain number of milliseconds has passed. You have to work out what frame rate you want. For windows games 30 fps is good (I have read). This way the game would run at 30 fps or whatever maximum on no matter what PC and the block would advance by such and such pixels in every frame.
I aint a Windows programmer but this is what I use for my games in DOS and it works well. The reason maybe that you are getting a cruddy movement is that the WM_TIMER event thingy might be working at large time intervals like 1 second (again I am not sure about Windows) and one second is too slow to be advancing a tetris block down a screen.
Also using my method you may be able to change the amount the block moves as the player advances in levels in the game. Just a thought huh?
I hope it helped. Buy forgive me if it does not...
Dark Star
e.g - Extract. Game loop
|
at the end of the game loop the while loop is used to wait until a certain number of milliseconds has passed. You have to work out what frame rate you want. For windows games 30 fps is good (I have read). This way the game would run at 30 fps or whatever maximum on no matter what PC and the block would advance by such and such pixels in every frame.
I aint a Windows programmer but this is what I use for my games in DOS and it works well. The reason maybe that you are getting a cruddy movement is that the WM_TIMER event thingy might be working at large time intervals like 1 second (again I am not sure about Windows) and one second is too slow to be advancing a tetris block down a screen.
Also using my method you may be able to change the amount the block moves as the player advances in levels in the game. Just a thought huh?
I hope it helped. Buy forgive me if it does not...
|
Dark Star
---------------------------------------------You Only Live Once - Don't be afriad to take chances.
Try putting this into your game loop. It makes sure that a set amount of time passes after the beginning of the loop, regardless of how long it takes to process the current frame:
{
DWORD timer;
timer = GetTickCount();
//
// all your code for the current frame goes here
//
// Sit and wait until it has been 33ms since the beginning of
// the frame
while(GetTickCount() - timer < 33)
;
}
Substitute whatever time value you want for the value 33; higher numbers will mean slower framerates, but make sure that the value is larger than the amount of time it takes to process each frame, or you won''t see any difference at all.
--Ben Carter
Romans 8:38-39
{
DWORD timer;
timer = GetTickCount();
//
// all your code for the current frame goes here
//
// Sit and wait until it has been 33ms since the beginning of
// the frame
while(GetTickCount() - timer < 33)
;
}
Substitute whatever time value you want for the value 33; higher numbers will mean slower framerates, but make sure that the value is larger than the amount of time it takes to process each frame, or you won''t see any difference at all.
--Ben Carter
Romans 8:38-39
--Ben CarterRomans 8:38-39
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement