Forums

OverviewV-Play 1 Support › dynamically sized EntityBaseDraggable Objects

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #4410

    hener.stephan

    Hey,

    I am trying to create dynamically sized EntityBaseDraggable Objects based on custom properties in BuildEntityButton.

    In the BuildEntityButton I have shapeWidth and shapeHeight for the EntityBaseDraggable Object I want to create.

    My Problem is that I can’t seem to get it to work. No Matter what I try to change in the BuildEntityButton, the button always creates a new Object

    with the default Values. The only thing that works is the right size while dragging the object (set in the onEntityPressed Event with the creationEntity property). But as soon as I let go of the created object it reverts back to the default size. I tried to change the size in the onEntityRelease and onEntityWasBuilt Event but to no avail.

    I also tried to set the size in the creationProperties also with the creationEntity property, but that throws an error.

    <Unknown File>: QML Component: createObject: value is not an object

    file::/qml/VPlay/scripts/EntityManager.js:200: TypeError: Result of expression ‘entity’ [null] is not an object.”

     

    Any Idea what I might be doing wrong?

     

     

    #4411

    Christian
    V-Play Team

    Hi Stephan,

    could you please post the relevant source code of the parts that are not working for you?

    Cheers, Chris

    #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

     

     

    #4415

    Christian
    V-Play Team

    Hi Stephan,

    please note, that the createdEntity only modifies the internally created entity that gets used for dragging, which is not the same that gets created after you release the entity and build a new one. To set the properties of the newly created entity, you can use the creationProperties property of BuildEntityButton.

    Add the following code to your BallPreview.qml:

    BuildEntityButton {
    
        id: ballPreview
        toCreateEntityType: "../shapes/Ball.qml"
        width: 20
        height: 20
    
        property int shapeWidth: 20
        property int shapeHeight: 20
    
        creationProperties: {
         "sWidth": shapeWidth,
         "sHeight": shapeHeight
        }
    }
    
    ...
    }

    Cheers, Chris

    #4416

    hener.stephan

    Hey,

    works perfectly, thank you very much.

    I was using the wrong syntax for the creationProperties, that’s why it didn’t work

    Cheers

    Stephan

Viewing 5 posts - 1 through 5 (of 5 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