Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 1 Support › LevelEditor: cant drag&drop/place BuildEntityButton

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #6411

    Felgo User

    hello, i have a problem with my LevelEditor, i can’t drag&drop the BuildEntityButton to the scene.

    i get following console Output (beginning at clicking to release)

    BuildEntityButton: button MouseArea pressed, start dragging entity
    BuildEntityButton: entity got pressed: EntityBaseDraggable_QMLTYPE_49(0x1105ace80, "platform_5") , for creationType: file:///Users/xxxx.app/Contents/Resources/qml/entities/Platform.qml
    pos of createdEntity: 307.5 221.5
    BuildEntityButton: button MouseArea released
    EntityBaseDraggable: entityReleased position: 283 184.5 snapped position: 288 192
    entity got released, create it at the position if allowed to build
    EntityManager: createEntityFromUrl: file:///Users/xxxx.app/Contents/Resources/qml/entities/Platform.qml
    [WARNING] EditableComponent construction without a defined and active ItemEditor. Ensure your Scene knows about the id: itemEditor or provide an explicit targetEditor!
    Platform.onCompleted(): width: 50
    file::/qml/VPlay/level/EntityBaseDraggable.qml:417: Unable to assign [undefined] to bool __buildPolygonCollider
    file::/qml/VPlay/level/EntityBaseDraggable.qml:414: Unable to assign [undefined] to bool __buildCircleCollider
    file::/qml/VPlay/level/EntityBaseDraggable.qml:411: Unable to assign [undefined] to bool __buildBoxCollider
    EntityManager: adding a component for the entityType ' platform ' to the entityTypeAndVariationTypeToComponentMap
    EntityManager: entity created with entityId: platform_13
    GameWindow: creating cocos item in cocosWrapper triggered by JavaScript code explicitly: EntityBaseDraggable_QMLTYPE_49(0x113d83110, "platform_13")

    The EntityBaseDraggable said that position is 288,192, but there is no “platform” – why?

    Platform.qml

    import QtQuick 1.1
    import VPlay 1.0
    import Box2D 1.0 // needed for Body.Static
    
    EntityBaseDraggable {
        entityType: "platform"
        // if the obstacle was pressed and held, remove it
        onEntityPressAndHold: removeEntity()
    
        // put them before the windows
        z:1
        width: 50
        height: 8
    
        Image {
            id: sprite
            source: "../img/platform.png"
            anchors.fill: parent
        }
    
        BoxCollider {
            id: collider
            bodyType: Body.Static
            anchors.fill: sprite
        }
    
        EditableComponent {
            editableType: qsTr("Platform")
            defaultGroup: "General"
            properties: {
                "width": {"min": 20, "max": 200, "stepsize": 1 },
                "rotation": {"min": 0, "max": 360, "stepsize": 1 }
            }
        }
            Component.onCompleted: console.debug("Platform.onCompleted(): width: "+width)
        //    Component.onDestruction: console.debug("Platform.onDestruction()")
    }
    
    

    BuildEntityButton:

    ....
    Column {
                    BuildEntityButton {
                        id: hudBottomButton1
                        visible: hudBottom.visible
                        toCreateEntityType: "entities/Platform.qml"
                        creationProperties: { "width":50, "height":8} // tried with and without props
                        z: 1
                        width: 60
                        height: 20
    
                        // one Platform to add
                        Platform {
                            anchors.centerIn: parent
                            preventFromRemovalFromEntityManager: true
                        }
                    }
                    MenuText {
                        text: qsTr("Platform")
                        font.pixelSize: 12
                    }
                }
    ...

     

    Can you help me please?

    #6421

    Felgo User

    i have now changed the Platform.qml to:

    import QtQuick 1.1
    import VPlay 1.0
    import Box2D 1.0 // needed for Body.Static
    
    EntityBaseDraggable {
        entityType: "platform"
        //    poolingEnabled: true
        // if the obstacle was pressed and held, remove it
        onEntityPressAndHold: removeEntity()
    
        // put them before the windows
        z:1
        width: 50
        height: 8
    
        //    property alias spriteWidth: sprite.width
    
        Image {
            id: sprite
            source: "../img/platform.png"
            //        anchors.fill: parent
            width: parent.width
            height: parent.height
        }
        property alias collider: collider
        BoxCollider {
            id: collider
            bodyType: Body.Static
            anchors.fill: sprite
        }
    
        EditableComponent {
            editableType: qsTr("Platform")
            defaultGroup: "General"
            properties: {
                "width": {"min": 20, "max": 200, "stepsize": 1 },
                "rotation": {"min": 0, "max": 360, "stepsize": 1 }
            }
        }
    
        //    Component.onCompleted: console.debug("Platform.onCompleted(): width: "+width)
        //    Component.onDestruction: console.debug("Platform.onDestruction()")
    
        // this property must be set for EntityBaseDraggable
        selectionMouseArea.anchors.fill: sprite
        // for collision detection while dragging, also define colliderComponent
        colliderComponent: collider
        //    dragOffset:Qt.point(10,10)
    }
    

    Now i get only the Console Output:

    EntityBaseDraggable: entityReleased position: 5 6 snapped position: 0 0

    i made a video:

    https://www.dropbox.com/s/cicgmj9srlb0e5h/vPlayLevelEditor.mov

     

    i hope you can help 🙂

     

     

    #6425

    Christian
    Felgo Team

    Hi,

    from the log output in your first post, I assume you did not give the ItemEditor instance the id itemEditor, or you did not provide it as an alias in your main.qml file? Please see the StackTheBoxWithEditor demo how to do so.

    Also, I would advise not to add a real Platform entity as child of your BuildEntityButton, but only a placeholder image that looks like the platform. Otherwise your entity would be created also in the physics world which is something you probably do not want. Also see the StackTheBoxWithEditor or the Squaby demo for more details how we have done it in real games.

    Please let me know if you were able to solve these issues.

    Cheers, Chris

    #6429

    Felgo User

    Thx for your input chris.

    1) I moved the ItemEditor from LevelEditorScene.qml to main.qml:

    ...
        LevelEditor {
            id: levelEditor
            applicationJSONLevelsDirectory: "JSONLevels/"
            toRemoveEntityTypes: [ "platform", "platformGoal", "stars", "obstacle" ]
            toStoreEntityTypes: [ "platform", "platformGoal", "stars", "obstacle" ]
            Component.onCompleted: {
                loadAllLevelsFromStorageLocation(applicationJSONLevelsLocation)
            }
        }
    
        ItemEditor {
            id: itemEditor
            opacity: 0.8
            z:1
            visible: window.state === "levelEditing" && scene.state  !== "playing"
        }
    ...
    

    2) changed the BuildEntityButton –> used a Image instead of Platform
    LevelEditorScene.qml:

    import QtQuick 1.1
    import VPlay 1.0
    import "./base"
    import "./entities"
    
    SceneBase {
        id: scene
        width: scene.width
        height: scene.height
    
        onBackPressed: {
            window.state = "main"
        }
    
        // this allows faster navigation through the scenes by pressing the Enter(=Return) key
        Keys.onReturnPressed: {
            window.state = "main"
        }
    
        Component.onCompleted: {
            scene.state = "levelEditing"
        }
    
        Column {
            anchors.right: parent.right
    
            spacing: 5
    
            MenuButton {
                text: scene.state === "playing" ? qsTr("Level Mode") : qsTr("Game Mode")
                onClicked: {
                    if(text === "Level Mode")
                        scene.state = "levelEditing"
                    else
                        scene.state = "playing"
                }
    
                anchors.right: parent.right
            }
            MenuButton {
                text: (itemEditor.visible ? qsTr("hide") : qsTr("show"))+" "+qsTr("ItemEditor")
                onClicked: itemEditor.visible = !itemEditor.visible
                anchors.right: parent.right
            }
    
            SimpleButton {
                text: "New Level"
                onClicked: levelEditor.createNewLevel()
                height: 20
            }
    
            SimpleButton{
                text: "Save Level"
                onClicked: nativeUtils.displayTextInput("Enter level name", "", levelEditor.currentLevelName)
                height: 20
                Connections{
                    target: nativeUtils
                    onTextInputFinished:{
                        if(accepted){
                            levelEditor.saveCurrentLevel({levelMetaData: {levelName: enteredText, "storageLocation": "applicationJSON"}})
                            levelEditor.exportLevelAsFile(enteredText)
                        }
                    }
                }
            }
    
            SimpleButton {
                text: "JSON Levels"
                height: 20
                onClicked: {
                    levelEditor.loadAllLevelsFromStorageLocation(levelEditor.applicationJSONLevelsLocation)
                    //levelSelectionList.levelMetaDataArray = levelEditor.applicationJSONLevelsLocation
                    levelSelectionListContainer.visible = true
                }
            }
            BuildEntityButton {
                visible: scene.state === "levelEditing"
                toCreateEntityType: Qt.resolvedUrl("entities/Obstacle.qml")
                creationProperties:{"width":50, "height":50}
                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: "grey"
                    anchors.fill: parent
                }
            }
        }
    
        Rectangle {
            id: levelSelectionListContainer
            anchors.horizontalCenter: parent.horizontalCenter
            y: 40
            width: 100
            height: 100
            visible: false
            color: "black"
    
            LevelSelectionList {
                id: levelSelectionList
                // at the beginning it is invisible, only gets visible after a click on the Levels button
                z: 4
                width: 100
                height: 100
                anchors.horizontalCenter: parent.horizontalCenter
                // this connects the stored levels from the player with the level list
                levelMetaDataArray: levelEditor.applicationJSONLevels
                onLevelSelected: {
                    console.debug(levelData)
                    levelEditor.loadSingleLevel(levelData)
                    // make invisible afterwards
                    levelSelectionListContainer.visible = false
                }
            }
        }
    
        // HUD bottom, for adding new platforms and stars
        Rectangle {
            id: hudBottom
            visible: window.state === "levelEditing" && scene.state !== "playing"
            width: gameWindowAnchorItem.width
            height: 40
            anchors.bottom: parent.bottom
            anchors.right: parent.right
            color: "grey"
            Row {
                id:hudBottomRow
                //            columns: 3
                anchors.right: parent.right
                Column {
                    BuildEntityButton {
                        id: hudBottomButton1
                        visible: hudBottom.visible
                        toCreateEntityType: Qt.resolvedUrl("entities/Platform.qml")
                        creationProperties: { "width":50, "height":8, "z":33}
                        z: 1
                        width: 60
                        height: 20
    
                        // one Platform to add
                        Image {
                            width: 50
                            height: 8
                            anchors.centerIn: parent
                            source: "img/platform.png"
                        }
                    }
                    MenuText {
                        text: qsTr("Platform")
                        font.pixelSize: 12
                    }
                }
                Column {
                    BuildEntityButton {
                        id: hudBottomButton2
                        visible: hudBottom.visible
                        toCreateEntityType: Qt.resolvedUrl("entities/PlatformGoal.qml")
                        creationProperties: { "width":100, "height":8, "z":33}
                        z: 1
                        width: 110
                        height: 20
    
                        // one PlatformGoal to add
                        Image {
                            width: 100
                            height: 8
                            anchors.centerIn: parent
                            source: "img/platform.png"
                        }
                    }
                    MenuText {
                        text: qsTr("Goal Platform")
                        font.pixelSize: 12
                    }
                }
                Column {
                    BuildEntityButton {
                        id: hudBottomButton3
                        visible: hudBottom.visible
                        toCreateEntityType: Qt.resolvedUrl("entities/Star.qml")
                        creationProperties: { "width":11, "height":10, "z":33}
                        z: 1
                        width: 30
                        height: 20
    
                        // one Star to add
                        Image {
                            width: 11
                            height: 10
                            anchors.centerIn: parent
                            source: "img/star.png"
                        }
                    }
                    MenuText {
                        text: qsTr("Star")
                        font.pixelSize: 12
                    }
                }
            }
        }
    }
    
    

    and if i drag a Platform now, i get this Output:

    BuildEntityButton: button MouseArea pressed, start dragging entity
    Box2DBody: calling sychronize after active got set to true 
    BuildEntityButton: entity got pressed: Platform_QMLTYPE_98(0x110f2e990, "platform_2") , for creationType: file:///Users/xxxxx.app/Contents/Resources/qml/entities/Platform.qml
    pos of createdEntity: 316.5 221
    BuildEntityButton: button MouseArea released
    EntityBaseDraggable: entityReleased position: 233.5 126.5 snapped position: 240 128
    entity got released, create it at the position if allowed to build
    EntityManager: createEntityFromUrl: file:///Users/xxxxx.app/Contents/Resources/qml/entities/Platform.qml
    EntityBaseDraggable: loaded buildCollider with colliderType box
    EntityManager: adding a component for the entityType ' platform ' to the entityTypeAndVariationTypeToComponentMap
    EntityManager: entity created with entityId: platform_29
    GameWindow: creating cocos item in cocosWrapper triggered by JavaScript code explicitly: Platform_QMLTYPE_98(0x1110f8f10, "platform_29")

    I tried it with and without creationProperties -> nothing.

    And i wont get this red Rectangle if i drag, like in the movie in my second post.

    Do you have any idea or solution?

     

    #6430

    Christian
    Felgo Team

    Putting the ItemEditor itself direcly in main.qml is not a good idea, because it would then not be in a Scene and thus content-scaling for multiple resolutions wont work – thus my last suggestion to make it available with a property alias.

    Other fixes might be the entityContainer property of your EntiyManager not being set correctly to your game scene. Also, for dynamic creation of stored levels with the LevelEditor also set the EntityManager::dynmiacCreationEntityList property. Please also see for remaining differences to StackTheBoxWithEditor to nail down your issues.

    Cheers, Chris

    #6431

    Felgo User

    ok i moved ItemEditor back to LevelEditorScene.qml and set up a property alias.

    i found the issue.. the entityContainer is “scene” (id of GameScene) and the LevelEditorScene has the id “levelEditorScene

    now i add another EntityManager in LevelEditorScene and now it works to drag & drop entities.

     

    But if i want to save and export it to JSON, there comes an Error, and i didnt found any solution in the documentation…

    NativeUtils: displayTextInput with the following default text: "Enter level name" 
    2014-01-20 16:49:17.212 GrumpyDude[59011:507] modalSession has been exited prematurely - check for a reentrant call to endModalSession:
    ERROR: LevelEditorLogic: no LevelBase loaded - either no LevelLoader defined or the loaded level was not derived from LevelBase as it has no levelData property!?
    EntityManager: found 1 entities to store
    
    LevelEditor: to store entityData: {}
    
    LevelEditor: to store editableComponentData: {}
    LevelEditor: overwriting levelMetaData property levelName with value leveltest from before undefined
    LevelEditor: overwriting levelMetaData property levelBaseName with value Package1 from before undefined
    
    LevelEditor: to store levelData: {"entityData":{},"editableComponentData":{},"levelMetaData":{"levelName":"leveltest","levelBaseName":"Package1"},"customData":{}}
    LevelStorage: save new level with name leveltest , created id for it: 9004
    LevelStorage: stored a new level with the following data: {"entityData":{},"editableComponentData":{},"levelMetaData":{"levelName":"leveltest","levelBaseName":"Package1","lastModificationTime":"Mon, 20 Jan 2014 15:49:17 GMT","storageLocation":"authorGenerated","levelId":9004,"creationTime":"Mon, 20 Jan 2014 15:49:17 GMT"},"customData":{}}
    LevelStorage: updated allLevels: [{"creationTime":"Sat, 18 Jan 2014 17:18:35 GMT","levelName":"phil1","storageLocation":"authorGenerated","lastModificationTime":"Sat, 18 Jan 2014 17:18:35 GMT","levelId":9303},{"creationTime":"Sat, 18 Jan 2014 20:42:46 GMT","levelName":"test3","storageLocation":"authorGenerated","lastModificationTime":"Sat, 18 Jan 2014 20:42:46 GMT","levelId":7653},{"creationTime":"Sun, 19 Jan 2014 23:39:59 GMT","levelName":"trynewone","storageLocation":"authorGenerated","lastModificationTime":"Sun, 19 Jan 2014 23:39:59 GMT","levelId":618},{"creationTime":"Mon, 20 Jan 2014 13:28:53 GMT","levelName":"level7","storageLocation":"authorGenerated","lastModificationTime":"Mon, 20 Jan 2014 13:28:53 GMT","levelId":5618},{"levelBaseName":"Package1","creationTime":"Mon, 20 Jan 2014 15:32:21 GMT","levelName":"8","storageLocation":"authorGenerated","lastModificationTime":"Mon, 20 Jan 2014 15:32:21 GMT","levelId":7007},{"levelBaseName":"Package1","creationTime":"Mon, 20 Jan 2014 15:34:42 GMT","levelName":"77","storageLocation":"authorGenerated","lastModificationTime":"Mon, 20 Jan 2014 15:34:42 GMT","levelId":8783},{"levelBaseName":"Package1","creationTime":"Mon, 20 Jan 2014 15:41:05 GMT","levelName":"88","storageLocation":"authorGenerated","lastModificationTime":"Mon, 20 Jan 2014 15:41:05 GMT","levelId":6213},{"levelBaseName":"Package1","creationTime":"Mon, 20 Jan 2014 15:43:58 GMT","levelName":"99","storageLocation":"authorGenerated","lastModificationTime":"Mon, 20 Jan 2014 15:43:58 GMT","levelId":7733},{"levelBaseName":"Package1","creationTime":"Mon, 20 Jan 2014 15:47:48 GMT","levelName":"888","storageLocation":"authorGenerated","lastModificationTime":"Mon, 20 Jan 2014 15:47:48 GMT","levelId":7187},{"levelName":"leveltest","levelBaseName":"Package1","lastModificationTime":"Mon, 20 Jan 2014 15:49:17 GMT","storageLocation":"authorGenerated","levelId":9004,"creationTime":"Mon, 20 Jan 2014 15:49:17 GMT"}]
    ERROR: LevelEditorLogic: no LevelBase loaded - either no LevelLoader defined or the loaded level was not derived from LevelBase as it has no levelData property!?
    LevelEditor: exportLevelAsFile is called for filename ' leveltest ' - storing the following levelData to json file: {"entityData":{},"editableComponentData":{},"levelMetaData":{"creationTime":"Mon, 20 Jan 2014 15:49:17 GMT","lastModificationTime":"Mon, 20 Jan 2014 15:49:17 GMT","levelBaseName":"Package1","levelId":9004,"levelName":"leveltest","storageLocation":"authorGenerated"},"customData":{}}
    LevelEditor: writing levelData to file was successful: true

    and the entityData is empty…

    Code Snippet of my LevelEditorScene.qml

        ...
        property alias itemEditor: itemEditor
        ItemEditor {
            id: itemEditor
            opacity: 0.8
            z:1
            visible: false
        }
    
        property alias levelLoader: levelLoader
        LevelLoader {
            id: levelLoader
            LevelBase {
    
            }
        }
        // for creating & removing entities
        EntityManager {
            id: entityManager
            entityContainer: scene
            poolingEnabled: true // entity pooling works since version 0.9.4, so use it
            // required for LevelEditor, so the entities can be created by entityType
            dynamicCreationEntityList: [ Qt.resolvedUrl("entities/Platform.qml"), Qt.resolvedUrl("entities/PlatformGoal.qml"), Qt.resolvedUrl("entities/Star.qml")]
        }
        LevelEditor {
            id: levelEditor
            levelLoader: levelLoader
            applicationJSONLevelsDirectory: "JSONLevels/"
            toRemoveEntityTypes: [ "platform", "platformGoal", "stars" ]
            toStoreEntityTypes: [ "platform", "platformGoal", "stars" ]
            Component.onCompleted: {
                //            loadAllLevelsFromStorageLocation(applicationJSONLevelsLocation)
            }
        }
    ....
    

    my save Button:

          SimpleButton{
                text: "Save Level"
                onClicked: nativeUtils.displayTextInput("Enter level name", "", levelEditor.currentLevelName)
                height: 20
                Connections{
                    target: nativeUtils
                    onTextInputFinished:{
                        if(accepted){
                            levelEditor.saveCurrentLevel({levelMetaData: {levelName: enteredText, levelBaseName: "Package1"}})
                            levelEditor.exportLevelAsFile(enteredText)
                        }
                    }
                }
            }

     

    EDIT:

    the JSON file is generated, but entityData is empty

     

     

    #6432

    Christian
    Felgo Team

    Using multiple entityManager instances is not allowed, please use a single Scene where you put the ItemEditor and toggle the UI with multiple states (game state or level state) in that scene. Again, have a look at StackTheBoxWithEditor how this is done there.

    Cheers, Chris

    #6438

    Felgo User

    i have now 2 EntityManager, and it works now.

    i can save levels, load levels in LevelEditorScene.

    Thx for the help chris.

    [CLOSED]

    #6456

    Christian
    Felgo Team

    Hi,

    you’re welcome!

     

    Though, keep the following in mind:

    Hi,
    using 2 EntityManagers cannot work, as there are dependencies in various Felgo components like EntityBase for pooling, EntityBaseDraggable and BuildEntityButton which all require the EntityManager to be defined with id ‘entityManager’. Thus only add one single EntityManager to avoid bugs later which have to do with multiple EntityManagers.

    Cheers, Chris

Viewing 9 posts - 1 through 9 (of 9 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded