Hi all,
I’m new here and hope here will be helpful for me.
I’m also new in QML which is mostly JavaScript code and I try to explain the problem with one of my programs so that I can solve it with your help.
Here is a QML project on Qt Creator 4.8.1 on the Widows machine.
Here is 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
}
}
}
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
}
}
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
}
}
I tested that on my 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 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?
Thanks beforehand.