Forums

OverviewV-Play 1 SupportBuildEntityButton – create entity › Reply To: BuildEntityButton – create entity

OverviewV-Play 1 SupportBuildEntityButton – create entity › Reply To: BuildEntityButton – create entity
#4942

phil.jahoda

A simple example:

We have a Scene looking like this:

It contains a BuildEntityButton displaying the Image of a Box. The displaying of the scene and button works fine. When I click the button and drag it, I want to create a new Block from it and be able to place it somewhere on the screen.

import QtQuick 1.1
import VPlay 1.0

Scene {

    BuildEntityButton {

        id: entitybutton
        x: 50
        y: 50
        width: 50
        height: 50
        toCreateEntityType: "entities/DraggableEntity.qml"

        Image {

          // make it the size of the parent
          anchors.fill: parent
          source: "img/block.png"
        }

    }
}

 

My “Block” Item is represented by the class DraggableEntity.qml looking like this: (Its not more than a brown Rectangle)

This should be the entity that is created when I click the BuildEntityButton in the scene.

import QtQuick 1.1
import VPlay 1.0

EntityBaseDraggable {

    entityType: "block"
    z: 1

    selectionMouseArea.anchors.fill: rectangle
    colliderComponent: collider

    gridSize: 32
    // the collider's size is exactly 1x1 grid
    colliderSize: 32

    Rectangle {
        id: rectangle
        width: 32
        height: 32
        color: "brown"
    }

    BoxCollider {
        id: collider
        anchors.fill: rectangle
    }
}

 

But when I click our button, this error occurs and repeats itself when dragging:

BuildEntityButton: button MouseArea pressed, start dragging entity
file::/qml/VPlay/level/BuildEntityButton.qml:292:3: QML MouseArea: mapToItem() given argument "undefined" which is neither null nor an Item
file::/qml/VPlay/level/BuildEntityButton.qml:307: TypeError: Result of expression 'createdEntity' [undefined] is not an object.
file::/qml/VPlay/level/BuildEntityButton.qml:326: TypeError: Result of expression 'createdEntity' [undefined] is not an object.
file::/qml/VPlay/level/BuildEntityButton.qml:327: TypeError: Result of expression 'createdEntity' [undefined] is not an object. .........

 

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