Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 2.0
- Item {
- signal pressed(real x, real y)
- signal moved(real x, real y)
- signal released
- id: joystick
- width: 160
- height: 160
- onPressed: console.log("Pressed:", x, y)
- onMoved: console.log("Moved:", x, y)
- onReleased: console.log("Released")
- Image {
- id: backgroundImage
- anchors.fill: parent
- source: "background.png"
- }
- Item {
- id: finger
- width: 26
- height: 26
- x: 80-13
- y: 80-13
- Image {
- id: fingerImage
- anchors.fill: parent
- source: "finger.png"
- }
- }
- MouseArea {
- id: joystickArea
- anchors.fill: parent
- property int signX: 1
- property int signY: 1
- PropertyAnimation {
- id: returnToOrigin
- target: finger
- properties: "x,y"
- to: 80-13
- duration: 100
- }
- onPressed: joystick.pressed(joystickArea.mouseX, joystickArea.mouseY)
- onPositionChanged: {
- if (Math.pow(joystickArea.mouseX-80, 2) + Math.pow(joystickArea.mouseY-80, 2) < Math.pow(80-13, 2)) {
- finger.x = joystickArea.mouseX-13
- finger.y = joystickArea.mouseY-13
- 80 - joystickArea.mouseX > 0 ? signX = 1 : signX = -1
- 80 - joystickArea.mouseY > 0 ? signY = 1 : signY = -1
- joystick.moved(-(80+13*signX-joystickArea.mouseX)/80, (80+13*signY-joystickArea.mouseY)/80)
- } else {
- // else what?
- }
- }
- onReleased: {
- returnToOrigin.start()
- joystick.released()
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement