Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › Joystick Controller HUD

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #19545

    Gabriel

    I’m starting coding with Felgo and got stuck on joystick

    I was trying to control an image with joystick but it only works if I keep moving the joystick. (onControllerXPositionChanged)

    I want the image to keep moving for example to the left when the XPosition is -1 and not only if the XPosition has changed form 0 to -1

     

    Here is the code:

    import Felgo 3.0

    import QtQuick 2.0
    
    
    
    
    GameWindow {
        property alias joystickBackgroundImageSource: joystick.backgroundImageSource
    
    
    
    
      // this rectangle fills the whole screen with grey
    
    
        Rectangle {
            id: bg
    
    
            anchors.fill: parent
            color: "light gray"
        }
    
    
      Scene {
          id: scene
    
    
    
    
    
    
    
    
          Image{
              id: goku
    source: "https://i.pinimg.com/originals/a1/66/71/a1667139446a400786829073db83a20b.png"
    height: 200
    width: 100
    
    
          }
    
    
    
    
       JoystickControllerHUD {
           id: joystick
    anchors.right: parent.left
    anchors.top: parent
    width:100;height:100
    
    
    onControllerXPositionChanged: {if(controllerXPosition>0){
                                      goku.x=goku.x+5
                                  }
                                  if(controllerXPosition<0){
                                        goku.x=goku.x-5
    }
    }
    onControllerYPositionChanged: {
        if(controllerYPosition>0){
                                          goku.y=goku.y-5
                                      }
                                      if(controllerYPosition<0){
                                            goku.y=goku.y+5
        }
    }
    }
    
    
    }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    Thank you

     

     

     

     

    #19549

    Günther
    Felgo Team

    Hi Gabriel,

    you can have look at some of our demos to see how game controls are set up there. For example:

    Best,
    Günther

    #19552

    Gabriel

    Thank you Gunther.

    I did it  using  Animation:

     

    MovementAnimation {

                target: goku
                property: "pos"
    
    
    
    
                  velocity: Qt.point(300*joystick.controllerXPosition, -300*joystick.controllerYPosition)
    
    
    
    
    
    
                running: true
    
    
    }
Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded