Find the Best Demos and Examples

Check out this quick tour to find the best demos and examples for you, and to see how the Felgo SDK can help you to develop your next app or game!

Forums

OverviewFelgo 2 Support (Qt 5) › Felgo 2.6 issues

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #10997

    Phil

    Hi. Since updating to Felgo 2.6, I’m having a couple of problems accessing the properties of some entities and boxColliders. In Felgo 2.5 I can access a property I defined by using: selectedBody.parent.myProperty, but I’m now getting an error. I’ve included some example code below. Thanks, Phil

     

    Common.LevelBase {
        //...
    
        EntityBase {
            //...
            
            MouseArea {
                //...
            
                onPositionChanged: {
                    selectedBody = physicsWorld.bodyAt(Qt.point(mouseX, mouseY))
                    selectedBody.parent.isDead = true    // error in this line
                    var splatid = entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("Splat.qml"),{x:selectedBody.getWorldCenter().x, y:selectedBody.getWorldCenter().y})
                    var splat = entityManager.getEntityById(splatid)
                    splat.colorString = selectedBody.parent.colorString    // error in this line
                }
            }
        }
    }

    The qml files for my entities are:

    EntityBase {
        //...
    
        property bool isDead: false
        property string colorString: "green"
        
        BoxCollider {
            //...
        }
    }

    and Splat.qml :

    EntityBase {
        //...
    
        property string colorString: "red"
        
        Image {
            //...
        }
    }

     

    #11005

    Günther
    Felgo Team

    Hi Phil!

    Many things changed with the Box2D update, including how to access the associated entity of a body.
    There is a new property target now, so “selectedBody.target.colorString” should work.
    You can have a look at the Box 2D Upgrade Guide to see what else has changed.

    Best,
    Günther

    #11290

    Phil

    Hi Günther. Thanks for your help. Using the property target solved some of my problems. However, I find that if I define my own property within a boxCollider I cannot access it. Is it no longer possible to do this in the update? If so, I shall avoid this in the future. Thanks, Phil

     

    BoxCollider {
    
        property double myProperty
    
        //...
    }

     

    #11292

    Günther
    Felgo Team

    Hi Phil!

    Currently, it is not possible anymore to directly access the collider object that is linked with the box2d body.
    To get your game to work again, you could introduce a property alias within your entity that allows to access the collider properties.

        EntityBase {
          // ...
    
          property alias collider: collider
    
          BoxCollider {
            id: collider
            property string myProperty: "Hello from Collider!"
            // ...
          }
        }
    
        function myFunction() {
          var body = world.bodyAt(...)
          var entity = body.target
          var collider = entity.collider
          console.log("COLLIDER-PROPERTY: "+collider.myProperty)
        }
    
    

    Of course, you can also move your properties to the entity and keep the collider clean, if you prefer that.

     

    Best,
    Günther

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

RSS feed for this thread

You must be logged in to reply to this topic.