Forums

OverviewV-Play 2 Support (Qt 5)Camera movement and zoom › Reply To: Camera movement and zoom

OverviewV-Play 2 Support (Qt 5)Camera movement and zoom › Reply To: Camera movement and zoom
#10443

Phil

Ok, so now I want to toggle the position of the camera between the two objects using a button. I’ve posted my attempt below but it doesn’t work as I expected. What code should I use instead? Thanks, Phil

 

import QtQuick 2.0
import VPlay 2.0

GameWindow{
    id: window

    // this will be our game scene
    Scene {

        //...

        property bool playerFocus: true

        //...

    }

    Scene {
        id: hudScene

        //...

        // button to toggle camera focus
        Rectangle {
            id: cameraButton
            x: 10
            y: 60
            width: 100
            height: 40
            radius: 3
            color: "black"
            opacity: 0.2
            Text {
                anchors.centerIn: parent
                font.pixelSize: 30
                text: "camera"
            }
            MouseArea {
                anchors.fill: parent
                hoverEnabled: true
                onEntered: parent.opacity = 0.3
                onExited: parent.opacity = 0.2
                onClicked: {
                    if(scene.playerFocus){
                        scene.x = scene.width/2 - entityBase2.x
                        scene.y = scene.height/2 - entityBase2.y
                    }
                    else{
                        scene.x = scene.width/2 - entityBase.x
                        scene.y = scene.height/2 - entityBase.y
                    }
                    scene.playerFocus = !scene.playerFocus
                }
            }
        }
    }
}      

 

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