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

Forums

OverviewFelgo 3 Support (Qt 5) › EntityBase BoxCollider centering issue

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #13584

    Kool

    Hi guys,

    I have an issue where I’ve placed some entities inside a Row item. I use a row because it’s useful in positioning my entities together and moving them as one. I could create them in the scene itself, but it over complicates what I want to do.

    Here is a sample game that illustrates the issue:

    import Felgo 3.0
    import QtQuick 2.0
    
    GameWindow {
        id: gameWindow
        
        activeScene: scene
        
        screenWidth: 960
        screenHeight: 640
        
        EntityManager {
            id: entityManager
            entityContainer: scene
        }
        
        Scene {
            id: scene
            width: 480
            height: 320
            
            PhysicsWorld {
                debugDrawVisible: true
            }
            
            Rectangle {
                color: "black"
                anchors.fill: parent
            }
            
            Item {
                width: 100
                height: 50
                anchors {top: parent.top; right: parent.right}
                
                Text {
                    text: "Click"
                    color: "white"
                    anchors.centerIn: parent
                }
                
                MouseArea {
                    anchors.fill: parent
                    onClicked: movement.start()
                }
            }
            
            MovementAnimation {
                id: movement
                target: content
                property: "y"
                velocity: 10
            }
            
            Row {
                id: content
                height: 50
                width: 200
                spacing: 2
                x: scene.width/2 - content.width/2
                y: scene.height/2 - content.height/2
                Repeater {
                    model: 4
                    
                    EntityBase {
                        width: 50
                        height: 50
                        
                        Rectangle {
                            color: "white"
                            anchors.fill: parent
                        }
                        
                        BoxCollider {
                            anchors.fill: parent
                            bodyType: Body.Static
                            collisionTestingOnlyMode: true
                        }
                    }
                }
            }
        }
    }

    If you run the game, you’ll see the box colliders are not centered within the entities but are in the top left of the scene. This appears to be due to something fishy with the coordinate mapping from the entity base, the row and the scene itself.

    Any ideas what I can do here?

    #13588

    Günther
    Felgo Team

    Hi Kool!

    At the moment, the collider position in the physics-world only takes the position of the entity into account, but not additional offsets due to the position of parent items.

    If you use the following code for the collider to also include the offset of the row, the positions should match again:

    BoxCollider {
      width: parent.width
      height: parent.height
      x: content.x
      y: content.y
      bodyType: Body.Static
      collisionTestingOnlyMode: true
    }

    Best,
    Günther

    #13589

    Kool

    Perfect! Thanks!

Viewing 3 posts - 1 through 3 (of 3 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