Hi all,
I tested the QML program below on an Android device (a tablet running Android 4.4.2). The problem is that, when rackets are not moving the ball moves smoothly (and it’s OK), but when I move either racket, it affects the speed of the ball, strangely, and reduces ball's speed! These two must be independent in terms of movement and speed, but in effect this issue takes place. I don’t know why.
Will you if possible test this code on your Android device too, to see if the problem exits there as well? If yes, what could be the source of the issue and how to remedy that, please?
main.qml:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5
Window {
id: window
visible: true
width: 1000; height: 800
color: "gray"
// The components
// --------------
Rectangle {
id: table
anchors.fill: parent
anchors.margins: 10
y: 10
anchors.horizontalCenter: parent.horizontalCenter
color: "royalblue"
}
Racket {
id: blackRacket
anchors.left: table.left
anchors.leftMargin: width * 2
y: table.height / 2
color: "black"
}
Racket {
id: redRacket
anchors.right: table.right
anchors.rightMargin: width * 2
y: table.height / 2
color: "red"
}
Ball {
id: ball
x: 150
y: 150
}
}
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5
Window {
id: window
visible: true
width: 1000; height: 800
color: "gray"
// The components
// --------------
Rectangle {
id: table
anchors.fill: parent
anchors.margins: 10
y: 10
anchors.horizontalCenter: parent.horizontalCenter
color: "royalblue"
}
Racket {
id: blackRacket
anchors.left: table.left
anchors.leftMargin: width * 2
y: table.height / 2
color: "black"
}
Racket {
id: redRacket
anchors.right: table.right
anchors.rightMargin: width * 2
y: table.height / 2
color: "red"
}
Ball {
id: ball
x: 150
y: 150
}
}
To copy to clipboard, switch view to plain text mode
Ball.qml:
import QtQuick 2.12
Rectangle {
width: 18; height: 18
color: "white"
radius: width/2
Timer { // This timer's job is merely moving the ball
id: timer
interval: 22; repeat: true; running: true
onTriggered: {
parent.x += 0.88
parent.y += 0.88
}
}
}
import QtQuick 2.12
Rectangle {
width: 18; height: 18
color: "white"
radius: width/2
Timer { // This timer's job is merely moving the ball
id: timer
interval: 22; repeat: true; running: true
onTriggered: {
parent.x += 0.88
parent.y += 0.88
}
}
}
To copy to clipboard, switch view to plain text mode
Racket.qml:
import QtQuick 2.12
Rectangle {
id: root
width: 15; height: 65
MouseArea {
anchors.fill: root
drag.target: root
drag.axis: Drag.YAxis
drag.minimumY: table.y
drag.maximumY: table.height - root.height - 10
}
}
import QtQuick 2.12
Rectangle {
id: root
width: 15; height: 65
MouseArea {
anchors.fill: root
drag.target: root
drag.axis: Drag.YAxis
drag.minimumY: table.y
drag.maximumY: table.height - root.height - 10
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks