I am trying to create a level editor for my game. The BuildEntityButtons all should create the same object – a Background object. I want to be able to change the properties of the Background object depending on which BuildEntityButton was selected. I have tried to do this using variationType and also using creationProperties. The problem is that the Background object always creates using just the default setting I set for it. Specifying variationType or creationProperties in my BuildEntityButton does not appear to have any effect.
I have copied the code that I think is relevant below:
SceneBase {
id:gameScene
width: 320
height: 480
scaleMode: "letterbox"
// the filename of the current level gets stored here, it is used for loading the
property string activeLevelFileName
// the currently loaded level gets stored here
property variant activeLevel
// set the name of the current level, this will cause the Loader to load the corresponding level
function setLevel(fileName) {
activeLevelFileName = fileName
}
Rectangle{
id: sceneBackground
anchors.fill: parent
color: "white"
}
EntityManager {
id: entityManager
entityContainer: container
// required for LevelEditor, so the entities can be created by entityType
dynamicCreationEntityList: [ Qt.resolvedUrl("../entities/Background.qml")] //IT DOESN'T APPEAR TO MAKE A DIFFERENCE WHETHER I INCLUDE THIS LINE OR NOT
}
LevelEditingUI{
id: levelUI
}
}
Item{//THIS IS THE LevelEditingUI OBJECT
id:levelUI
visible: false
anchors.left: gameWindowAnchorItem.left
anchors.bottom: gameWindowAnchorItem.bottom
height: 100
width: 720 / 2
z: 4000
property variant entities: ["sand.png","grass.png"]
// makes a grid of entities to be dragged into the level
Grid {
id: buildEntityButtons
visible: true // only gets visible when in state levelEditing
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 10
height: 75
z:1000
spacing: 5
rows: 2
BuildEntityButton {
toCreateEntityType: "../entities/Background.qml"
width: 35
height: 35
TexturePackerAnimatedSpriteVPlay {
id: image1
source: "../../assets/img/background_fire_vehicles.json"
frameNames: [entities[0]]
anchors.fill: parent
}
}
BuildEntityButton {////THIS IS THE BUTTON I AM USING TO TEST //////////////////////
variationType: "grass.png" ///THE DEFAULT VARIATIONTYPE IS SAND. EVEN WITH THIS LINE, SAND ALWAYS GETS CREATED/////
toCreateEntityType: "../entities/Background.qml"
width: 35
height: 35
TexturePackerAnimatedSpriteVPlay {
id: image2
source: "../../assets/img/background_fire_vehicles.json"
frameNames: [entities[1]]
anchors.fill: parent
}
}
EntityBaseDraggable { //THIS IS MY BACKGROUND ENTITY THAT SHOULD BE CREATED
entityId: "background"
entityType: "backgroundEntity"
variationType: "sand.png" //DEFAULT VARIATIONTYPE
poolingEnabled: true
z: -1000
width: 128
height: 128
selectionMouseArea.anchors.fill: mouseRectangle
Rectangle{
id: mouseRectangle
anchors.fill: parent
}
TexturePackerAnimatedSpriteVPlay {
id: image
z:3001
source: "../../assets/img/background_fire_vehicles.json"
frameNames: [variationType]
anchors.fill: parent
}
BoxCollider {
id: boxCollider
bodyType: Body.Static
categories: Box.Category3
collidesWith: Box.Category2 | Box.Category1
}
}