Forums

OverviewV-Play 1 SupportChange Z-Position of QML Items at run time › Re: Change Z-Position of QML Items at run time

OverviewV-Play 1 SupportChange Z-Position of QML Items at run time › Re: Change Z-Position of QML Items at run time
#4048

Christian
V-Play Team

Hi Christian,
I guess you are creating your entities dynamically with the EntityManager?
The z-ordering depends on the order of which the elements were added to the Scene: if they do not have any explicit z order set, it defaults to 0 and items added at a later time are drawn on top of the previous ones.

In your case, I would recommend 3 layers:
– a floor layer with z=0 , which holds the floor images
– a boxes layer with z=1, which holds the brown images
– a gems layer with z=2, which holds the crystals
– a player layer with z=3, which guarantees the player is always drawn on top.

When you create the entities dynamically, you can specify the parent item where the newly created entity will be added.

So in QML code it would look like the following:


function createFloor() {
  entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("pathToFloorEntity.qml"), {"z": 0})
}
function createBox() {
  entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("pathToBoxEntity.qml"), {"z": 1})
}
function createCrystal() {
  entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("pathToCrystalEntity.qml"), {"z": 2})
}
function createPlayer() {
  entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("pathToPlayerEntity.qml"), {"z": 3})
}

Does this solve your problem?

Cheers,
Chris

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