Forums

OverviewV-Play 2 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 VPlay 2.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?

    • This topic was modified 2 years, 5 months ago.
    #13588

    Günther
    V-Play 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.

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