Forums

OverviewFelgo 2 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.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support