Forums

OverviewV-Play 1 Support › event associated with entering a scene

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #6304

    Michael

    Hi

    I have a general question about how to detect when focus is given to a scene.

    I’m using the MultiSceneMultiLevel example as a starting point for my game. I’m not using the loader, since I only have one ‘level’ or game format at present. The game has a timer, and some other setups, so I thought since a user is likely to repeatedly enter this scene, I should trap some event to setup these things. I wonder if there is such a thing as onGetFocus. There seems to be OnFocus or OnActiveFocus, but these seem not to work (I think this is mentioned in the squaby source for dynamically loaded scenes). My scene I think is not dynamically loaded, since all scenes are created upon startup (and set to opacity 0). I thought of the following idea:

    SceneBase {
        id: gameScene
    
        // the name of the current level gets stored here
        property string activeLevelString
        // the current level gets stored here
        property variant activeLevel
    
        onOpacityChanged: {
            if (opacity === 1) {
                console.log("onOpacityChanged!!")
            }
        }

    i.e. use onOpacityChanged to get an event, but I found strangely the above situation will fire two events (i.e. I see 2 of the above console messages). I’m not an expert but in Corona, there are events like onCreateScene, onEnterScene, onExitScene. These seem handy. What is the V-play equivalent?

    Cheers, Michael.

    #6305

    Christian
    V-Play Team

    Hi Michael,

    thanks for bringing up this question, you discovered a minor bug in this template & example!

    To solve it, add the following to your PropertyChanges “explicit: true“.

    So it should look like this:

    states: [
        State {
          name: "menu"
          PropertyChanges {target: menuScene; opacity: 1}
          PropertyChanges {target: window; activeScene: menuScene; explicit: true;}
        },
        State {
          name: "selectLevel"
          PropertyChanges {target: selectLevelScene; opacity: 1}
          PropertyChanges {target: window; activeScene: selectLevelScene; explicit: true}
        },

     

    This prevents the property to bounce back when the state is left. Also, I would rather use onVisibleChanged to determine if the scene was entered which is abit more efficient than checking for each opacity change.

     

    Cheers, Chris

     

    #6311

    Michael

    Thanks Chris. it’s a big help. Though (perhaps not surprisingly) I see two firings of onVisitbleChanged (once upon initial arrival/display of the scene, and another when I go back from game to level select). I wonder if there is a way to distinguish, however I guess this can be done with the aid of a setup variable. I also noticed in the menu code, there is a script call:

            State {
                name: "game"
                PropertyChanges {target: gameScene; opacity: 1}
                PropertyChanges {target: window; activeScene: gameScene; explicit: true}
                StateChangeScript {
                    script: {
                        gameScene.setLevel(selectLevelScene.selectedLevel)

    which was a big help. I think calling a setup function is a good place to achieve my objective.

    I give a huge thanks to you & your team for providing these excellent examples. At first these examples seem like a blur, but time is needed to study these deeply to get the best benefit.

    Cheers, Michael.

    #6316

    Michael

    Hi Chris

    I am facing a minor misunderstanding with function call timing, and want to ask about when the following script: is called, i.e. (placed here for convenience)

                StateChangeScript {
                    script: {
                        gameScene.setLevel(selectLevelScene.selectedLevel)
                        gameScene.resetGame()
                    }
                }

    in relation to when other scripts in the objects within the actual game scene are called.

    To try to explain my situation, I call a function gameScene.resetGame() above which initiates a bunch of game setups. Within resetGame() it calls a function in an external Javascipt (associated with that GameScene QML only) that initialises an array with character data I use later. Like so:

    function resetGame() {
            // randomise the letters for buttons based on level no
            LetterLogic.buildLettersArray(activeLevel)

    Then in the GameScene I have some simplebutton with text that are assigned using an external JS function that pulls the character data I previously setup. Like so:

    SimpleButton { id: btnLetter1; width: 50; height: 50; color: "#C9A582"; text: LetterLogic.getLetter(0); onClicked: postpendLetter(text) }

    The problem is the char text for those simple buttons are coming up empty, even though I can see the data is being initialised, and that getter function is working.

    The solution I have so far is taking out the text: assignment above, and putting it in the resetGame(), like so:

        function resetGame() {
            LetterLogic.buildLettersArray(activeLevel)
            btnLetter1.text = LetterLogic.getLetter(0)

    This works fine now, but I wonder why it’s not possible to do text: LetterLogic.getLetter(0) method which seems more intuitive? Maybe it’s a code process/order issue that I don’t see right now.

    Cheers, Michael.

    #6319

    Christian
    V-Play Team

    Hi Michael,

    LetterLogic.getLetter(0) does not work as you expect, because it is not a property, thus you cannot bind to it (in fact it is just evaluated once).

    You can update a property based on your game logic and bind this property to the Text.text property, then the text element will update every time your property changes.

    Cheers, Chris

Viewing 5 posts - 1 through 5 (of 5 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