1

Part of my game includes a table in which there is a ball rotating. There are also two rectangles like rackets that a player can use for the game. At first I used a simple rectangle with a mouse area filling the racket and some drag properties. It was somewhat fine when I ran the program on my Desktop but on Android devices, touching (i,e. by finger) the rackets is:

  • hard making the game unpleasant and also moving the rackets affects
  • the movement of the ball!

So I searched the Web and faced MultiPointTouchArea. So I tried to use it in both rackets with that hope it solves the issues.

I used this code:

import QtQuick 2.9

Rectangle {
    id: root
    width: 15; height: 65
    property int oldY: y
    property bool yUwards: false
    property bool yDwards: false

       onYChanged: {
           if(y > oldY)  yDwards = true
           else if (y < oldY)  yUwards = true
           oldY = y
       }

       MultiPointTouchArea {
        anchors.fill: root
        mouseEnabled: true
        minimumTouchPoints: 1
        maximumTouchPoints: 1
        touchPoints: [
            TouchPoint { id: root }
        ]
        drag.target: root
        drag.axis: Drag.YAxis
        drag.minimumY: table.y
        drag.maximumY: table.height - height - 10
    }
}

But there are errors like:
qrc:/Racket.qml:22 id is not unique

I mean, what is the correct use of that method for the rackets, please?

Franky
  • 1,181
  • 2
  • 11
  • 33
  • 1
    Your Rectangle id is set to `root` and MultiPointTouchArea id is `root` too. – Macias Dec 29 '17 at 10:48
  • 1
    Thank you very much. After that, `drag`s will be the next problem. If you wanted to write the code correctly, how would you do it? – Franky Dec 29 '17 at 11:06
  • No answer!? Is it that strange to have a touchable item in a QML program?! – Franky Dec 30 '17 at 06:11

0 Answers0