OverviewV-Play 1 SupportLevel Editor (not possible to position entity at row 0 or column 0 › Reply To: Level Editor (not possible to position entity at row 0 or column 0

OverviewV-Play 1 SupportLevel Editor (not possible to position entity at row 0 or column 0 › Reply To: Level Editor (not possible to position entity at row 0 or column 0


Here is the code of the Tree.qml:


import QtQuick 1.1
import VPlay 1.0
import Box2D 1.0 // needed for Box category

//Item {
// use an EntityBase for the base item, to be able to create, destroy and access the tntity by type with the EntityManager (and to be able to save/load it through the EM!)
EntityBaseDraggable {
    id: tree

    // columnn & row may be set from outside, for easier positioning along the grid
    property int column
    property int row

    property real gridSize: scene.gridSize

    entityType: "tree"
    // the variationType may be blockBrown, blockRed
    variationType: "standard"

    // when e.g. column = 0 is specified, the block should be placed centered at column 0
    x: column*gridSize//+gridSize*0.5
    y: row*gridSize//+gridSize*0.5

    // these properties must be set for EntityBaseDraggable
    selectionMouseArea.anchors.fill: sprite
    //colliderComponent: collider

    selectionMouseArea.onPressAndHold: removeEntity()//onEntityPressAndHold: removeEntity()

    Rectangle {
        id: sprite
        color: "blue"

        width: gridSize+1
        height: gridSize+1
        anchors.left: parent.left


and here is the code of the main.qml:


import VPlay 1.0
import QtQuick 1.1
import "entities"

GameWindow {
    activeScene: scene
    // the size of the Window can be changed at runtime by pressing the number keys 1-7
    // the content of the logical scene size (480x320 by default) gets scaled to the window size based on the scaleMode
    // you can set this size to any resolution you would like your project to start with, most of the times the one of your main target device
    // this resolution is for iPhone 4 & iPhone 4S
    // change this to a portrait resolution (e.g. 640x960) for games in portrait mode
    width: 960
    height: 640
    EntityManager {
        id: entityManager
        entityContainer: scene

        // required for LevelEditor, so the entities can be created by entityType
        dynamicCreationEntityList: [ Qt.resolvedUrl("entities/Tree.qml") ]

    Scene {
        id: scene
        // the "logical size" - the scene content is auto-scaled to match the GameWindow size
        // change this to 320x480 for games in portrait mode
        width: 480
        height: 320

        gridSize: scene.height/9

        //        BackgroundImage {
        //            source: "img/forestground.png"
        //            anchors.fill: parent
        //        }

        Tree {
            column: 0
            row: 0

        Tree {
            column: 1
            row: 0
        Tree {
            column: 0
            row: 8

        Tree {
            column: 12
            row: 8

        // state: "levelEditing" enables dragging and clicking of obstacles
        // change the state in the next line to start in levelEditing mode:
        state: "playing" //state: "levelEditing"

        onStateChanged: {
            if(state === "levelEditing") {

        function stopGame() { //needs to be modified in actual game ^^
            // remove all entities of type "tree", but not the walls

        LevelEditor {
            id: levelEditor
            toRemoveEntityTypes: [ "tree" ]
            toStoreEntityTypes: [ "tree" ]

        Column {
            anchors.right: parent.right

            spacing: 5

            SimpleButton {
                text: scene.state === "playing" ? "Level Mode" : "Game Mode"
                onClicked: {
                    if(text === "Level Mode")
                        scene.state = "levelEditing"
                        scene.state = "playing"

                anchors.right: parent.right

            BuildEntityButton {
                visible: scene.state === "levelEditing"
                toCreateEntityType: "entities/Tree.qml"

                width: 50
                height: 50
                anchors.right: parent.right

                // the obstacle is just a grey entity, we can customize the look of the button here
                Rectangle {
                    color: "purple"
                    anchors.fill: parent


I replaced the image with and Rectangle and commented the part with the background-image.

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
create apps
create games
cross platform
native performance
3rd party services
game network
level editor
easiest to learn
biggest time saving
best support