Delays, and wait times...
What are some methods of creating pauses, and wait times? I tried to use the c++ system("PAUSE") but when I run an open gl program with that a cmd window pops up and just sits there, so im guessing you cant use it....
I wanna decrement a shapes y position. so as in tetris, I want the shape to drop...then wait about 1 second then drop then wait then drop then wait. I know how to get the figure to drop alrady, just need methods of delaying the drops. Thnx in advance.
to get this to work, you would use a timer, for example, in the top part of your code where the global variables are, make a variable like so:
int count=0;
and then in the drawing code:
count++;
if(count> (whatever you want the delay to be in frames) )
{
count=0;
yvalue++;
}
and that will make it drop at a set pace, (you can replace the whatever you want.... with a number like 100, the higher the number, the longer it takes them to fall)
bloodright.150m.com //For the latest on all of the IVGDA projects!
[edited by - jverkoey on February 11, 2003 11:05:28 PM]
int count=0;
and then in the drawing code:
count++;
if(count> (whatever you want the delay to be in frames) )
{
count=0;
yvalue++;
}
and that will make it drop at a set pace, (you can replace the whatever you want.... with a number like 100, the higher the number, the longer it takes them to fall)
bloodright.150m.com //For the latest on all of the IVGDA projects!
[edited by - jverkoey on February 11, 2003 11:05:28 PM]
That works, it''s just getting harder to do since the compiler will often optimize out empty loops, and since processors are getting so fast (i.e. you have to use a huge value to get a small delay). It''s also processor-speed-dependent.
This might work:
const int PieceDelay = 800; // 800 millisecond delay
while(!done){
...
while(GetTickCount() < (LastTime + PieceDelay);
LastTime = GetTickCount();
...
}
Note that you''ll have to include windows.h. There are also more standard solutions available, but most everyone here is working with Win32, so why not leverage it?
Later,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
This might work:
const int PieceDelay = 800; // 800 millisecond delay
while(!done){
...
while(GetTickCount() < (LastTime + PieceDelay);
LastTime = GetTickCount();
...
}
Note that you''ll have to include windows.h. There are also more standard solutions available, but most everyone here is working with Win32, so why not leverage it?
Later,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[twitter]warrenm[/twitter]
well, that might work for that, but what if he wants to have other graphix? with that 800 millisecond gap in between each frame, they''ll look kinda choppy, but then again, if it is just going to have tetris tiles moving down, i guess it doesn''t matter that much....
bloodright.150m.com //For the latest on all of the IVGDA projects!
bloodright.150m.com //For the latest on all of the IVGDA projects!
If the above was unclear, here''s a sample proggy.
#include <windows.h>#include <iostream> int main(){ const int PieceDelay = 800; // 800 millisecond delay bool done = false; int LastTime = GetTickCount(); while(!done) { while(GetTickCount() < unsigned(LastTime + PieceDelay)); LastTime = GetTickCount(); std::cout << "tick." << std::endl; } return 0;}
[twitter]warrenm[/twitter]
quote:
Original post by jverkoey
well, that might work for that, but what if he wants to have other graphix? with that 800 millisecond gap in between each frame, they''ll look kinda choppy, but then again, if it is just going to have tetris tiles moving down, i guess it doesn''t matter that much....
bloodright.150m.com //For the latest on all of the IVGDA projects!
Well you wouldn''t just have an empty delay loop; it would test to see if .8 seconds had passed, and if so, set LastTime to the current time AND move the pieces. But in this case, there isn''t going to be any logic performed except to move the blocks, so the blocking delay is of no consequence.
[twitter]warrenm[/twitter]
yah, that's what i meant, lol
if he has other graphix, then it'll be choppy, but like i said, and you said, lol, if it's just tetris blocks, it doesn't matter
bloodright.150m.com //For the latest on all of the IVGDA projects!
-EDIT-
do you mean he'd have the drawGLScene command inside the while loop?
[edited by - jverkoey on February 11, 2003 11:24:05 PM]
quote:
but what if he wants to have other graphix?
if he has other graphix, then it'll be choppy, but like i said, and you said, lol, if it's just tetris blocks, it doesn't matter
bloodright.150m.com //For the latest on all of the IVGDA projects!
-EDIT-
do you mean he'd have the drawGLScene command inside the while loop?
[edited by - jverkoey on February 11, 2003 11:24:05 PM]
aight ill try them both out and let yall know how they faired for me. Thnx again...just to clarify tho, zealeous your method works with the speed of thier processor and gets a correct drop without the processor making the loop go too fast right? J''s worked almost identical to what I remember a tetris drop''s delay is with a delay of 50.
//as he said......
int count=0;
//then in the drawing code:
count++;
if(count> 50)
{
count=0;
yvalue++;
}
//as he said......
int count=0;
//then in the drawing code:
count++;
if(count> 50)
{
count=0;
yvalue++;
}
One more question guys...
You know how in tetris, when you press left or right, it sort of "jumps" left instead of just flowing(like my program is doing right now)? How do I achive this type of effect?
so im saying when I hit left I want it to skip left instead of slide left...
You know how in tetris, when you press left or right, it sort of "jumps" left instead of just flowing(like my program is doing right now)? How do I achive this type of effect?
so im saying when I hit left I want it to skip left instead of slide left...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement