Forums

OverviewV-Play 1 Support › EntityBaseDraggable with embedded ParallaxItem

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #5074

    Martin

    Hi there,

    our game has different layers which are implemented with the nice ParallaxItem component in the entities. Moreover, we would like to build the levels with the LevelEditor and thus have EntityBaseDraggable components like the following one.

    import QtQuick 1.1
    import VPlay 1.0
    import Box2D 1.0
    
    EntityBaseDraggable {
        id: obstacle
        entityType: "obstacle"
    
        width: size
        height: size
    
        property int size: 64
        property alias color: rectangle.color
    
        colliderComponent: collider
        selectionMouseArea.anchors.fill: rectangle
        gridSize: size
        colliderSize: width
    
        ParallaxItem {  // this seems to be a problem?! without it, everything works fine...
            ratio: 1.4
    
            Rectangle {
                id: rectangle
                color: "yellow"
                x: -obstacle.width / 2
                y: -obstacle.height / 2
                width: obstacle.width
                height: obstacle.height
            }
    
            BoxCollider {
                id: collider
                x: -obstacle.width / 2
                y: -obstacle.height / 2
                bodyType: Body.Static
            }
        }
    }
    

    Unfortunately, this does not work and the error message is not comprehensible [to me at least], i.e.,

    file::/qml/VPlay/level/BuildEntityButton.qml:338: TypeError: Result of expression 'createdEntity' [undefined] is not an object.
    file::/qml/VPlay/level/BuildEntityButton.qml:336: TypeError: Result of expression 'createdEntity' [undefined] is not an object.
    BuildEntityButton: button MouseArea pressed, start dragging entity
    file::/qml/VPlay/level/BuildEntityButton.qml:302:3: QML MouseArea: mapToItem() given argument "undefined" which is neither null nor an Item

    If one removes ParallaxItem (or just replaces it by Item), everything seems to work just fine. So what is the problem and how can this be resolved?

    Cheers, Martin

    #5075

    Martin

    …and, to add another issue, specifying creationProperties as shown below results in the same error message as above, also in the otherwise working case without the ParallaxItem.

    BuildEntityButton {
        id: obstaclebutton
    
        toCreateEntityType: "Obstacle.qml"
        creationProperties: { color: "green" }
    
        width: 50
        height: 50
    
        Rectangle {
            id: rectangle
            color: "green"
            anchors.fill: parent
        }
    }

    Could someone please also comment on this?

    In general, it would be great to get more information in the error messages. If possible, they could be somewhat more meaningful and provide pointers to the exact location and cause of the error.

    Cheers, Martin

    #5092

    Alex
    V-Play Team

    Hi Martin,

     

    Regarding your first post:

    ratio: 1.4

    the ratio must be set as Qt.point(x.x,x.x), for example:

    ratio: Qt.point(0.8,1.0)

     

     

    Regarding your second post:

    creationProperties: { color: "green" }

    should be:

    creationProperties: { "color" : "green" }

    There is obviously a mistake in the BuildEntityButton documentation, we will fix that.

     

    Best Regards,

    Alexander

    #5097

    Martin

    Oops, my bad regarding the Qt.point… However, clearer error messages would help to find such errors. With the other suggested fix everything seems to work.

    Spendid! Thanks a bunch!

    Martin

    #5099

    Martin

    Ok, there are still some issues with this. First of all, the ratio of such an EntityBaseDraggable with ParallaxItem has to be 1 initially and adjusted after it was created which is also the case for the position. Otherwise it will jump away from the mouse/finger when released. I figured out how to do this but interestingly, only the x component has to be modified, y is fine which is weird. In the respective BuildEntityButton, I have some code like this

        onEntityWasBuilt: {
            var obstacles = entityManager.getEntityArrayByType("obstacle");
            var o = obstacles[obstacles.length-1];
    
            var ratio = 1.5;
            var lx = levelContainer.x;      // position in the level
            var ly = levelContainer.y;
            var x1 = o.x + lx;              // split x
            var x2 = o.x - x1;
    
            o.x = x1/ratio + x2;            // x has to be adjusted according to parallax ratio
            o.y = o.y;                      // y not...?
            o.ratio = ratio;                // set parallax ratio
        }

    Next thing is that I am not able to drag or remove such an entity once it is created. I guess you should be able to reproduce these problems with an EntityBaseDraggable as in post #5074.

    Cheers, Martin

    #5101

    Alex
    V-Play Team

    The reason you can’t drag and drop can be found (through a hopefully this time clearer error message 😛 ) in the output:

    … EntityBaseDraggable.qml:449:3: QML MouseArea: Cannot anchor to an item that isn’t a parent or sibling.

    selectionMouseArea.anchors.fill: xxx //parent or sibling else it can't anchor

     

    Cheers, Alex

     

    #5105

    Martin

    Ok, thanks for the hint. I clearly see the problem. However, the solution is not clear to me. Simply

    selectionMouseArea.anchors.fill: parallaxitem

    and assigning the ParallaxItem this id won’t do the trick. So how can the ParallaxItem with the Rectangle inside be made draggable?

    Cheers, Martin

    #5107

    Alex
    V-Play Team

    I still can’t quite understand what you trying to achieve, could you explain a little deeper what the outcome should be?

    Anyway, with this code i have no problems moving around the entity, if you run it with enabled QML renderer then you can see that everything is in the right place.

    import QtQuick 1.1
    import VPlay 1.0
    import Box2D 1.0
    
    EntityBaseDraggable {
      id: obstacle
      entityType: "obstacle"
    
      width: size
      height: size
    
      property int size: 64
      property alias color: rectangle.color
    
      colliderComponent: collider
      selectionMouseArea.anchors.fill: item
      gridSize: size
    
      ParallaxItem {
        id: item
        //ratio: Qt.point(0.8,1.0)
        x: -width/2
        y: -height/2
        width: parent.width
        height: parent.height
    
        Rectangle {
          id: rectangle
          color: "grey"
          anchors.fill: parent
        }
      }
    
      BoxCollider {
        id: collider
        x: -width/2
        y: -height/2
        width: obstacle.width
        height: obstacle.height
        bodyType: Body.Static
      }
    }

    The BoxCollider must be a direct child of the EntitiyBase to work properly.

    To help you any further i will need a little more information about the exact functionality that you want to achieve. 😉

     

    Cheers, Alex

    #5183

    Martin

    Thanks for the support. Our setup is as follows: A level is several times larger than the screen so that it is scrolled according to the movement of the player or directly with the joystick controller in the level editor. It consists of three layers. (1) background, i.e. the bottom z=0 with ratio 0.8, (2) obstacles, i.e. the center z=1 with ratio 1.0, (3) non-colliding objects which are “on top” z=2 with ratio 1.4. In the level editor, objects have to be places on layers (2) and (3).

    I tried to construct a simple example of our setup since some code is worth a thousand words. Unfortunately, I seem to have introduced an error by this which I have not been able to track down yet. Here comes the main.qml which unfortunately crashes…

    import VPlay 1.0
    import QtQuick 1.1
    
    GameWindow {
        activeScene: scene
        width: 960; height: 640
        focus: true
        Keys.forwardTo: controller
    
        EntityManager{
            id: entityManager
            entityContainer: levelContainer
            dynamicCreationEntityList: [Qt.resolvedUrl("Block.qml")]
        }
    
        TwoAxisController {
            id: controller
            inputActionsToKeyCode: {
                "up": Qt.Key_W,
                        "down": Qt.Key_S,
                        "left": Qt.Key_D,
                        "right": Qt.Key_A,
                        "fire": Qt.Key_Space
            }
        }
    
        MovementAnimation{
            target: levelContainer
            property: "pos"
            running: true
            property real scale: 200
            velocity: Qt.point(controller.xAxis*scale,controller.yAxis*scale)
        }
    
        Scene {
            id: scene
            width: 480
            height: 320
    
            LevelEditor {
                id: levelEditor
                toRemoveEntityTypes: ["obstacle"]
                toStoreEntityTypes: ["obstacle"]
            }
    
            // === LEVEL ===
            Item{
                id: levelContainer
    
                // === BACKGROUND ===
                ParallaxItem{
                    id: background
                    ratio: Qt.point(0.6,0.6)
    
                    // some generated background...
                    Grid{
                        rows: 10; columns: 10; spacing: 50
                        Repeater{
                            model: 100
                            Rectangle{
                                width: 100; height: 100
                                color: "grey"
                            }
                        }
                    }
                }
    
                // === FOREGROUND ===
                ParallaxItem{
                    id: levelgrid
                    ratio: Qt.point(1,1)
    
                    // some generated foreground...
                    Grid{
                        rows: 10; columns: 10; spacing: 100
                        Repeater{
                            model: 100
                            Rectangle{
                                x: 100; y: 100
                                width: 50; height: 50
                                color: "red"
                            }
                        }
                    }
                }
    
            }
    
    //        BEButton{ }   // (*) we'll get to this later...
        }
    }
    

    Moreover, save the code of your last post to Box.qml.

    The error message then is

    EntityBase: entityDestroyed received, setting visible to false
    destroy item in AbstractCCNodeManager: QObject(0x9b4b4c0) , nodeMgr: CCRectangleManager(0x9690118) 
    the node to remove does not have a parent! that should never happen, because it means the root object wanted to be deleted! 
    The program has unexpectedly finished.

    What’s the matter here?

    Cheers, Martin

    #5185

    Alex
    V-Play Team

    You are using a Collider without defining a PhysicsWorld in your Scene, that’s the problem. Yeah we know, the error message doesn’t really point that out 😛 We will try to take care of that.

    >> Moreover, save the code of your last post to Box.qml.
    I guess it should be Block.qml

    Cheers, Alex

    #5186

    Martin

    Very well, you are right. And yes, it should be Block.qml.

    Ok, so now activate the BEButton in main.qml which reads

    import QtQuick 1.1
    import VPlay 1.0
    
    BuildEntityButton {
        id: bebutton
        width: 50; height: 50
    
        toCreateEntityType: "Block.qml"
    
        Rectangle {
            id: rectangle
            color: "yellow"
            anchors.fill: parent
        }
    }
    

    This now enables one to place Block entities on the level. However, they can’t be dragged once dropped.

    Thanks in advance, Martin

    #5187

    Martin

    Another observation: When the qmlrenderer is enabled, the ParallaxItem does not seem to have any effect whatsoever…

    Best, Martin

    #5197

    Martin

    Hi, could you (or anyone else) reproduce the described problem? Is it a bug or is there some mistake in my code?

    Cheers, Martin

    #5209

    Martin

    Another remark: When dragged initially, the entity moves according to the ratio of the ParallaxItem, i.e. at a different speed than the finger/mouse.

    Do you have any suggestions for how to cope with these problems? Since this currently is a major problem for us, support is greatly appreciated.

    Cheers, Martin

    #5221

    Alex
    V-Play Team

    Hi Martin,

    I’m currently trying to make it work, sorry for letting you wait quite some time.

    Regarding the qml renderer, only our custom renderer can handle the parallax effect.

    I will get come back to you as soon as i got news for you 😉

    Cheers, Alex

Viewing 15 posts - 1 through 15 (of 23 total)

RSS feed for this thread

You must be logged in to reply to this topic.

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