OverviewFelgo 2 Support (Qt 5) › EntityId and EntityType vs Categories (for collision detection)?

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



    I have been using categories for telling my colliders which sprites to collide with but think its a little confusing to just use names like Circle.Category1 and so on. When i thought of EntityId and EntityType and read about them and it seems like i could use these in collisions? But havent found any documentation about how to use this? Can i just use that in for example: collidesWith: Ship. If i in the future begin to have a lots of different type of objects to collide i think it would be easier to remember what is what if i can use “real” names.


    Felgo Team

    Hi Isak!

    It is possible to access the entityId or entityType of a colliding entity like this:

      BoxCollider {
        // ... collider settings
        fixture.onBeginContact: {
         // retrieve properties of other colliding entity
          var otherFixture = other
          var otherBody = otherFixture.getBody()
          var otherEntity =
          var otherType = otherEntity.entityType
          console.log("OTHER: "+otherFixture)
          console.log("BODY: "+otherBody)
          console.log("ENTITY: "+otherEntity)
          console.log("TYPE: "+otherType)


    Note: If you check the type manually, the physics engine still needs to handle collisions between all colliders (the engine does not know how you handle the collision at onBeginContact). So the Categories are the only way to completely ignore certain collisions if the Categories do not match your specified settings. The category settings directly affect the Box2D physics engine that is used internally. This means that in bigger games, it can have an impact on your performance if you limit the possible collisions with categories as the engine then doesn’t need to check for collisions between certain entities.




    Felgo Team

    You could define your own names for the collision categories, to make your code more readable for you.

    For this, a singleton is the best approach, e.g. like this:

    Create a new qml file CollisionCategories.qml

    pragma Singleton
    import QtQuick 2.0
    import Felgo 3.0
    Item {
      property int ship: Circle.Category1
      property int other: Circle.Category2

    In order to register this type as a singleton, you must additionally create a file with the name qmldir in the same folder, and add this content:

    singleton ColliderCategories 1.0 ColliderCategories.qml

    Then you can use your own categories like this:

    CircleCollider {
      collidesWith: ColliderCategories.ship

    NOTE: One thing to mention here: If the ColliderCategories.qml file is in the same folder as the qml file where you are using it, you need to add this import to the file where using the categories:

    import "."

    This signals the qml engine to look through the current directory to see if any qmldir files are present to register them. If you do not import the folder with the qmldir file, you will see an error like this “ReferenceError: ColliderCategories is not defined





    Thanks Guys,


    The singleton looks like the thing i was looking for:)



Viewing 4 posts - 1 through 4 (of 4 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
create apps
create games
cross platform
native performance
3rd party services
game network
level editor
easiest to learn
biggest time saving
best support