Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qml-引用错误:未定义屏幕_Qml - Fatal编程技术网

Qml-引用错误:未定义屏幕

Qml-引用错误:未定义屏幕,qml,Qml,我想在学校里做一个fotball小游戏,但我遇到了一些问题。因此,当我运行代码时,它说ReferenceError:Screen没有定义,但根据我的说法,我已经定义了它 这段代码只是一个原型,稍后会将按键更改为按钮,这样它就可以在手机上实际工作 import QtQuick 2.0 Item { id:root width:Screen.width height:Screen.height-10 focus:true Keys.onPressed:

我想在学校里做一个fotball小游戏,但我遇到了一些问题。因此,当我运行代码时,它说ReferenceError:Screen没有定义,但根据我的说法,我已经定义了它

这段代码只是一个原型,稍后会将按键更改为按钮,这样它就可以在手机上实际工作

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
    }
}

}

因此,如果你运行这段代码,你只会让玩家出现,然后立即消失,字段不会显示

您缺少屏幕导入

import QtQuick.Window 2.1

将项目调整到屏幕大小是不正常的,您只需使用
并将所有子项锚定在根项中。

以为我之前添加了这些项……呵呵!非常感谢!!:)