Forums

OverviewV-Play 1 Supportdynamically sized EntityBaseDraggable Objects › Reply To: dynamically sized EntityBaseDraggable Objects

OverviewV-Play 1 Supportdynamically sized EntityBaseDraggable Objects › Reply To: dynamically sized EntityBaseDraggable Objects
#4413

hener.stephan

BuildEntityButton:

 

BuildEntityButton {

    id: ballPreview
    toCreateEntityType: "../shapes/Ball.qml"
    width: 20
    height: 20

    property int shapeWidth: 20
    property int shapeHeight: 20

    onEntityPressed: {
        shapeCol.nextShape();
        opacity = 0;
        createdEntity.sWidth = shapeWidth;
        createdEntity.sHeight = shapeHeight;
    }

    Image {
        x: -width/2
        y: -height/2
        width:20
        height: 20
        source: "../../img/ball.png"
        anchors.fill:parent
    }
}

EntityBaseDraggable:

EntityBaseDraggable {
    id: ball

    entityId: "ball"
    entityType: "circle"

    colliderComponent: circleCollider
    selectionMouseArea.anchors.fill: ballImage
    gridSize: 1
    height: 20
    width: 20
    dragOffset: Qt.point(0,0)
    allowedToBuild: true

    property alias sWidth: ballImage.width
    property alias sHeight: ballImage.height

    Image {
        id: ballImage
        source: "../../img/ball.png"
        height: 20
        width: 20
        x: -width/2
        y: -height/2
    }

    CircleCollider {
        id: circleCollider
        radius: ballImage.width / 2
        friction: 1.6
        restitution: 0.2
        density: 50
        anchors.centerIn: parent
    }
}

ShapeCol (Row Element where the build buttons are located)

    ShapeContainer {
         id:shapeCol

        BallPreview {shapeHeight: 50; shapeWidth: 50}
        BallPreview {shapeHeight: 50; shapeWidth: 50}
        BallPreview {shapeHeight: 50; shapeWidth: 50}
        BallPreview {shapeHeight: 50; shapeWidth: 50}
        BallPreview {shapeHeight: 50; shapeWidth: 50}

    }

 

ShapeHeight and ShapeWidth define the future width and height created ball. With this code I can drag the ball with my desired size and as soon as I drop it, the Ball reverts back to the default size

 

 

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