Hi Alex,
Thanks for your answer. I looked at the tutorial again and ultimately decided to change my approach. Now I’m using the state machine so that in my game scene I have this function
function stopGame() {
scene.gameState = "gameOver"
}
and then in my state machine I’ve said
// menuScene is our first scene, so set the state to menu initially
state: "menu"
activeScene: menuScene
// state machine, takes care reversing the PropertyChanges when changing the state, like changing the opacity back to 0
states: [
State {
name: "menu"
PropertyChanges {target: menuScene; opacity: 1}
PropertyChanges {target: window; activeScene: menuScene}
},
State {
name: "selectLevel"
PropertyChanges {target: selectLevelScene; opacity: 1}
PropertyChanges {target: window; activeScene: selectLevelScene}
},
State {
name: "credits"
PropertyChanges {target: creditsScene; opacity: 1}
PropertyChanges {target: window; activeScene: creditsScene}
},
State {
name: "game"
PropertyChanges {target: gameScene; opacity: 1}
PropertyChanges {target: window; activeScene: gameScene}
},
State {
name: "gameOver"
PropertyChanges {target: retryScene; opacity: 1}
PropertyChanges {target: window; activeScene: retryScene}
}
]
I also have added a RetryScene.qml
import Felgo 3.0
import QtQuick 2.0
import "../common"
SceneBase {
id:retryScene
// background
Rectangle {
anchors.fill: parent.gameWindowAnchorItem
color: "darkred"
}
// back button to leave scene
MenuButton {
text: "Back"
// anchor the button to the gameWindowAnchorItem to be on the edge of the screen on any device
anchors.right: retryScene.gameWindowAnchorItem.right
anchors.rightMargin: 10
anchors.top: retryScene.gameWindowAnchorItem.top
anchors.topMargin: 10
onClicked: backButtonPressed()
}
// credits
Text {
text: "Game Over"
color: "white"
anchors.centerIn: parent
}
}
and listed it in the gamewindow of my main.qml
RetryScene {
id: retryScene
onBackButtonPressed: window.state = "selectLevel"
}
But when the stopGame function is called, nothing happens. Any ideas as to what’s happening?