Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. What's the best way to separate physics from graphics from game logic with Qt?
QtWS25 Last Chance

What's the best way to separate physics from graphics from game logic with Qt?

Scheduled Pinned Locked Moved Game Development
2 Posts 2 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BlastDV
    wrote on last edited by
    #1

    Hi! I think this may be a question that may be answered within any context, like C++ only. But since I've been using Qt for my college projects, including a videogame which I admit could have been a lot better, I think this may be a good place to start with.

    That game I just mentioned, was pretty simple, spaceships moving around shooting each other using inmediate OpenGL mode and basic collision detection. No threads, texturing or even shaders.

    Quickly, I found that I had lost the structure of my project since I didn't know where to write each function. For example, one thing that keeps annoying me is the fact that I can only draw OpenGL primitives within the glWidget (I'm almost sure this can be done differently, I may just need to read more), so if I have a subclass which needs to draw something in the OpenGL widget, it simply couldn't, forcing me to send its data to the glWidget in order to render it. This ended up by having a huge-overloaded glWidget, compaired to the other classes I had, to manage controls, game logic or colission detection.

    I'm pretty sure there should be a better way to do this, Could you point me in the right direction please? I could even post the whole game code if needed, so you could see more clearly what kind of mess I'm talking about,

    Thanks!

    (8) Just live your life blind like me (8)

    1 Reply Last reply
    0
    • F Offline
      F Offline
      feldifux
      wrote on last edited by feldifux
      #2

      Hi,
      the best way to separate physics from rendering, and also separate game logic from rendering is by using a component-based development approach.

      This means, your game entity is just a container of components each having one particular functionality. Should your entity interact with the physics system? Then add a physics component. Is it a sprite, a Rectangle, or whatever? Then add these visual components. Should the game logic be triggered every second? Then add a Timer component and add the logic there. Should the entity be controlled by an AI? Add the respective AI component.

      We have used this concept in V-Play, which comes with the source code of the QML game API in the SDK. You can download it for free and have a look at it.
      You also might find our tutorials and sample games useful to understand how component based systems work in practice.

      Cheers, Chris

      Founder of Felgo SDK - http://felgo.com/qt

      Felgo simplifies

      • Mobile App Dev with Qt esp. iOS & Android
      • Game Development with Qt

      What others say

      Felgo scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved