Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › Physics bug

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #8510

    Heini

    Hi,

    recently I ran into some trouble with the psysics system in conjunction with loading the scenes dynamically. I load my different scenes with a Loader element. So for example I have a scene for my menu and another one for my game. Please try the following code (using a main.qml, whith the Loader element inside):

    MenuScene.qml:

    import QtQuick 2.0
    import Felgo 3.0
    
    Scene {
        width: 480
        height: 320
    
        Text{
            anchors.horizontalCenter: parent.horizontalCenter
            text: "Mainmenu"
        }
    
        SimpleButton{
            anchors.centerIn: parent
            text: "To GameScene"
            onClicked:{
                loader.source = "GameScene.qml"
            }
        }
    }

     

    GameScene.qml:

    import QtQuick 2.0
    import Felgo 3.0
    
    Scene {
        id: scene
        width: 480
        height: 320
    
        EntityManager{
            id: entityManager
            entityContainer: scene
        }
    
    
        PhysicsWorld{
            id: physicsWorld
            gravity.y: -9.81
            anchors.fill: parent
    
        }
    
        EntityWithCollider{
            id: entity
            x: 100
            y: 100
        }
    
        Text{
            text: "Gamescene"
            anchors.horizontalCenter: parent.horizontalCenter
        }
    
        SimpleButton{
            text: "Back"
            anchors.centerIn: parent
            onClicked:{
    
                loader.source = "MenuScene.qml"
            }
        }
    }

     

    Start now by loading the MenuScene.qml. When you load then the “gamescene”, everything seems to be ok. Go back to the mainmenu and enter the gamescene again. Now the game is hanging up immediately. It seems to fail the initialize process of the physics world. The last debug output I get is:
    Box2DWorld: set gravity to QPointF(0, 0)
    Box2DWorld: set gravity to QPointF(0, -9.81)

    This seems to be a VPlay 2 bug – VPlay 1 does not show that behavior.

     

    Cheers,

    Heini

    • This topic was modified 9 years, 5 months ago by  Guybrush.
    #8512

    Christian
    Felgo Team

    Hi Heini,

    thanks for reporting this bug!

    You can change the Back button handling in GameScene temporarily to this code:

      SimpleButton{
        text: "Back"
        anchors.centerIn: parent
        onClicked:{
          physicsWorld.invalidateContextProperty()
          loader.source = "MenuScene.qml"
        }
      }

    The issue will be fixed with the next Felgo version.

    However, I would not recommend to remove the whole EntityManager and PhysicsWorld, as you then prevent pooling of entities. So it is best to instantiate the GameScene without a loader, and the remaining scenes with a loader if you want to reduce loading times.

    Cheers, Chris

    #8514

    Heini

    Hi Chris,

    I am not using entity pooling in my case, because I would like to keep memory consuption as low as possible. That´s also the reason I load the scenes dynamically. Keeping the whole gamescene in memory all the time would be to expensive and drive my app unstable.

     

    Cheers,

    Heini

Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded