【发布时间】:2014-04-27 10:03:08
【问题描述】:
尝试在学校创建一个小型足球游戏作为一个项目,但我遇到了一些问题。因此,当我运行代码时,它说 ReferenceError: Screen is not defined,但根据我的说法,我已经定义了它。
此代码只是一个原型,稍后会将按键更改为按钮,以便它可以在手机上实际工作。
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
}
}
}
因此,如果您运行此代码,您只会让播放器出现,然后立即消失,不会显示该字段。
【问题讨论】:
标签: qml