Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Using animations
Forum Updated to NodeBB v4.3 + New Features

Using animations

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 424 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • tomyT Offline
    tomyT Offline
    tomy
    wrote on last edited by tomy
    #1

    Hello,

    Here is a minimal version of a code revealing the problem which is:

    Moving the racket when playing the game on the Desktop kit (Windows) doesn't affect the speed of ball's movement and is fine. But when run on an Android device, moving the racket affects the speed of ball's movement as though their movements have been tied together.

    I guess if I use Animations that problem may be solved. How to use Animations in this program, please?

    main.qml:

    import QtQuick 2.9
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: 720
        height: 620
        title: qsTr("Movement Test")
    
        Rectangle {
            id: table
            anchors.fill: parent
            color: "gray"
    
            Rectangle {
                id: ball
                property double xincrement: Math.random() + 0.5
                property double yincrement: Math.random() + 0.5
                width: 15
                height: width
                radius: width / 2
                color: "white"
                x: 300; y: 300
            }
    
            Racket {
                id: myRacket
                x: table.width - 50
                y: table.height/3
                color: "blue"
            }
    
            Timer {
                interval: 5; repeat: true; running: true
    
                function collision() {
                    if((ball.x + ball.width >= myRacket.x  &&
                        ball.x < myRacket.x + myRacket.width) &&
                       (ball.y + ball.height >= myRacket.y &&
                        ball.y <= myRacket.y + myRacket.height))
                        return true
                    return false
                }
    
                onTriggered: {
                    if(ball.x + ball.width >= table.width)
                        running = false
    
                    else if(ball.x <= 0)
                        ball.xincrement *= -1
    
                    else if (collision())
                        ball.xincrement *= -1
                                   
                                // Move the ball 
                    ball.x = ball.x + (ball.xincrement * 1.5);
                    ball.y = ball.y + (ball.yincrement * 1.5);
    
                    if(ball.y <= 0 || ball.y + ball.height >= table.height)
                        ball.yincrement *= -1
                }
            }
        }
    }
    

    Racket.qml:

    import QtQuick 2.9
    
    Rectangle {
        id: root
        width: 15; height: 65
    
        MouseArea {
            anchors.fill: parent
            anchors.margins: -root.height
            drag.target: root
            drag.axis: Drag.YAxis
            drag.minimumY: table.y
            drag.maximumY: table.height - root.height - 10
        }
    }
    
    1 Reply Last reply
    0
    • tomyT Offline
      tomyT Offline
      tomy
      wrote on last edited by
      #2

      When I change the kit from Desktop to Android on Qt Creator, I get these messages/warnings on Issues window:

      :-1: warning: "D:\android-ndk-r10e\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-gcc" is used by qmake, but "D:\android-ndk-r10e\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-gcc.exe" is configured in the kit.
      Please update your kit or choose a mkspec for qmake that matches your target environment better.

      :-1: warning: "D:\android-ndk-r10e\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-g++" is used by qmake, but "D:\android-ndk-r10e\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-g++.exe" is configured in the kit.
      Please update your kit or choose a mkspec for qmake that matches your target environment better.

      Isn't it related to the problem with the program?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved