Forums

OverviewV-Play 2 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 VPlay 2.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 VPlay 2.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 3 years, 11 months ago.
    #8512

    Christian
    V-Play 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 V-Play 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.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support