Forums

OverviewV-Play 2 Support (Qt 5)BoxCollider to RetryScene › Reply To: BoxCollider to RetryScene

OverviewV-Play 2 Support (Qt 5)BoxCollider to RetryScene › Reply To: BoxCollider to RetryScene
#9147

Michael

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 VPlay 2.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?

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