Results 1 to 5 of 5

Thread: A Question About GameLoops

  1. #1
    Join Date
    Oct 2012
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question 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:
    Qt Code:
    1. while (1)
    2. {
    3. update();
    4. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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...
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Oct 2012
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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?

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A Question About GameLoops

    read my sig.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: A Question About GameLoops

    Quote Originally Posted by steadi View Post
    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:
    Qt Code:
    1. while (1)
    2. {
    3. update();
    4. }
    To copy to clipboard, switch view to plain text mode 

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Question about Qt+VTK...
    By Patrick Sorcery in forum Qt Programming
    Replies: 0
    Last Post: 11th October 2010, 11:20
  2. more of a C++ question
    By jajdoo in forum Newbie
    Replies: 6
    Last Post: 17th August 2010, 20:40
  3. Question regarding QT ui
    By bostero22 in forum Qt Programming
    Replies: 3
    Last Post: 5th June 2010, 18:02
  4. rcc question
    By mojo2000 in forum Newbie
    Replies: 13
    Last Post: 18th November 2009, 22:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.