PDA

View Full Version : game slows down when I click on maximize window



qwe522y
22nd September 2013, 14:56
hello;
When I click on maximize window my app slows down becose of large workspace(1080x1900);
help me to solve this problem;
my gameloop is correct or no? thanks;
ubuntu 12.04 KDE4 Qt5.1


###########main.qml##############
import 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##############
import 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"
}
}