Forums

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
#6453

Alex
V-Play Team

Hi again,

i changed the Tree.qml like this to make it work, my changes are highlighted with “// !!!!“:

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

    // !!!!
    // the default not allowed to build rectangle has its position at x:-width/2 and y:-height/2
    notAllowedRectangle.x: 0
    notAllowedRectangle.y: 0
    // !!!!
    // this is used internally (it was initially added for our squaby demo game) so the towers cannot be built at the edges of the level, however that is just what you want, so set this internal value to 0
    __towerSizeInGridsHalf: 0

    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
        height: gridSize
        anchors.left: parent.left
    }
    // !!!!
    // you should always use a collider in your EntityBaseDraggable, it is used for collision detection while building it, e.g. to prevent that 2 entities are built in the same spot
    BoxCollider {
      id: collider
      width: gridSize
      height: gridSize
      anchors.left: parent.left
      bodyType: Body.Static
    }
}

Now that there is a collider used, you also need to add a PhysicsWorld to your scene. After that, it should work as you requested.

Cheers,
Alex

 

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