문제

Trying to build a little fotball game as an project in school but I'm having some issues. So when I run the code it says that ReferenceError: Screen is not defined, but accordign to me I have defined it.

This code is just a prototype, going to change the keys to buttons later on so that it can actually work on a phone.

import QtQuick 2.0

Item {
    id:root

    width:Screen.width
    height:Screen.height-10
    focus:true

    Keys.onPressed: {

        if(event.key===Qt.Key_Up)
        {
            event.accepted = true;
            player.y=(player.y) - 40

        }
        if(event.Key === Qt.Key_Down){
            event.accepted = true;
            player.y = (player.y)+ 40
           }
        if (event.key === Qt.Key_Right)
         { event.accepted=true;
            player.x=(player.x)-40

        }
   if (event.key === Qt.Key_Left)
{event.accepted = true;
       player.x=(player.x) +40
   }

    }

Flickable {
    width:Screen.width
    height:Screen.height
    contentHeight: Screen.height*4
    contentWidth:Screen.width
    interactive:true
    boundsBehavior: Flickable.StopAtBounds

    Image{
        id: feild
        anchors.fill:parent
        source:"Namnlös.png"
        sourceSize.height:Screen.height*4
        sourceSize.width:Screen.width
        }

    Image {
        id: player
        source:"asd.png"
        x:Screen.width/2
        y:Screen.height/2
    }
}

}

So if you run this code you'll only get the player showing up, and then disapear instantly, the field is not shown.

도움이 되었습니까?

해결책

You lack the Screen import.

import QtQuick.Window 2.1

Screen docs

다른 팁

Resizing items to screen is abnormal, you should simply use resizeMode property and anchor all child items inside root item.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top