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 8 years, 4 months ago by
Guybrush.