A Question About GameLoops
Hello There Guys,
I am currently trying to create a game using Qt and it's rather nice graphics view item. I have the game pretty much setup but I would like to add in a game loop to make the npc's wonder around and such.
My current code is:
Code:
while (1)
{
update();
}
but this just crashes the game. I know a while loop works when low-level programming but it does not seem to work in this instance. Can somebody point me in the right direction on how to create a game loop or a better way around using the while loop in Qt?
Thanks in Advance,
Matt :P
Re: A Question About GameLoops
QThread
(and don't sub class it). You could use a QTimer instead of while(true). Don't use while(1) - it's just not classy and stinks of 'C'. You can use while(true) with no problems other than hogging cpu. If this causes a crash, then you have a problem elsewhere...
Re: A Question About GameLoops
I have tried while(true) and using a QThread but it all seems to yield the same result. I have checked over the rest of my code and nothing is out of place or anything that should cause it to crash - any suggestions?
Re: A Question About GameLoops
Re: A Question About GameLoops
Quote:
Originally Posted by
steadi
Hello There Guys,
I am currently trying to create a game using Qt and it's rather nice graphics view item. I have the game pretty much setup but I would like to add in a game loop to make the npc's wonder around and such.
My current code is:
Code:
while (1)
{
update();
}
but this just crashes the game. I know a while loop works when low-level programming but it does not seem to work in this instance. Can somebody point me in the right direction on how to create a game loop or a better way around using the while loop in Qt?
Instead of a while loop use a timer with timeout interval matching the game speed you want to obtain. Also please take care of avoiding naming your methods the same as already existing methods in Qt.