Forums

OverviewV-Play 1 Support › howto reset pressed keys on state-change

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #4477

    Thomas

    Hey,

     

    following Problem:

    while playing, i press keys and buttons to control my object to the finish-area. As soon as i reach it, i change the state and set the focus to false.

    But when i restart the level, the keys, which where pressed in the end, are still pressed, and the object is handling a “ghost”input. Same thing with the buttons.

    Also, the forces applied to the object at the end (force/torque), also get applied instantly at restart. how can i reset them?

    here is my “finished” state, if it helps anyone:

    State {
                    name: "finished"
                    PropertyChanges { target: mainMenu; visible: false}
                    PropertyChanges { target: level; visible: false}
                    PropertyChanges { target: level; levelSource:""}
                    PropertyChanges { target: finishMenu; visible: true}
                    PropertyChanges { target: buttonarea; visible: false}
                    PropertyChanges { target: scene; focus: false; }
                    PropertyChanges { target: scene; Keys.forwardTo: [scene]}
                    StateChangeScript {
                        script: {
                            Keys.enabled = false
                        }
                    }
                }

    and here is the game-state:

    State {
                    name: "game"
                    PropertyChanges {
                        target: level.space_ship
                        x: level.space_ship_x
                        y: level.space_ship_y
                    }
                    PropertyChanges { target: mainMenu; visible: false}
                    PropertyChanges { target: level; visible: true}
                    PropertyChanges { target: level; levelSource: "levels/Level02.qml"}
                    PropertyChanges { target: finishMenu; visible: false}
                    PropertyChanges { target: buttonarea; visible: true}
                    PropertyChanges { target: scene; focus: true; }
                    PropertyChanges { target: scene; Keys.forwardTo: [level.space_ship.controller]}
                    StateChangeScript {
                        script: {
                            // Pause the physicsWorld
                            //level.world.running = true
                        }
                    }
                },

     

    Hoping, someone has a solution for this… gonna check the demos once more, if i can find the solution..

     

    Cheers,

    TS

    #4482

    Thomas

    i solved one part of the problem by just calling the following script, which resets the object.

    function startGame(){
            spaceShip.x = space_ship_x
            spaceShip.y = space_ship_y
            spaceShip.controller.xAxis = 0;
            spaceShip.controller.yAxis = 0;
        }

    but still, the last impuls before finishing gets applied to the object at a restart.

    except for that, another problem is, that the game crashes, when a button is pressed at finishing and at restart, the object collides with another object.

     

    Cheers,

    TS

    #4501

    Thomas

    consider this as solved.

    Basically i used the script above and put my object into the specific level. now it works just nice, as the object also gets loaded with the level itself.

     

    Cheers,

    TS

    #4513

    Alex
    V-Play Team

    Glad you worked this out on your own! :)

    Cheers,

    Alex

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