当我点击最大化窗口时,我的应用程序因大工作空间(1080x1900)而变慢;
帮我解决这个问题;
我的游戏循环是正确还是不正确?感谢;
ubuntu 12.04 KDE4 Qt5.1
// ########## ########## main.qml 导入QtQuick 2.0
Rectangle {
width: 360
height: 360
focus: true
Tank{id: myTank; objectName: "myTank"; x: 100; y: 100}
Timer {
running: true
repeat: true
interval: 16
onTriggered: {
myTank.move();
}
}
Keys.onUpPressed: { myTank.moveUp = true}
Keys.onDownPressed: { myTank.moveDown = true }
Keys.onLeftPressed: { myTank.rotateLeft = true }
Keys.onRightPressed: { myTank.rotateRight = true }
Keys.onReleased: {
switch(event.key) {
case Qt.Key_Up:
myTank.moveUp = false
break
case Qt.Key_Down:
myTank.moveDown = false
break
case Qt.Key_Left:
myTank.rotateLeft = false
break
case Qt.Key_Right:
myTank.rotateRight = false
}
}
}
// ########## ########## Tank.qml 导入QtQuick 2.0
Item {
width: 30
height: 30
property bool rotateLeft: false
property bool moveUp: false
property bool rotateRight: false
property bool moveDown: false
property double xpos: x
property double ypos: y
property double rspeed: 3
property double speed: 3
rotation: 120
function move() {
if(rotateLeft) rotation -= rspeed
else if(rotateRight) rotation += rspeed
var diffX = speed * Math.sin(rotation * 0.0174532925);
var diffY = speed * Math.cos(rotation * 0.0174532925)
if(moveUp) {
xpos += diffX
ypos -= diffY
} else if(moveDown) {
xpos -= diffX
ypos += diffY
}
x = xpos
y = ypos
}
Image {
anchors.fill: parent
source: "qrc:///Battle_City_Tank_Player1.png"
}
}
答案 0 :(得分:0)
尝试在计时器对象中设置更大的间隔