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

Forums

OverviewFelgo 3 Support (Qt 5) › Using collision detection to determine if object is onscreen

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #23676

    OCG

    I am trying to detect when particular bodies are visible onscreen (using the RUBE example).  Based on another post i found you suggested creating a boxcollider the size of the screen to detect when another object enters/exits the screens.  I have created the code below, and I have the following questions:

    1. The body I’m trying to detect on/off screen is Kinetic.  My screen detector body is also kinetic.  Do I have to force one of these to be Dynamic to make this work?  How should this ideally be handled? (Neither should be dynamic by definition)
    2. When I move the penguin which is always onscreen, a single movement generates 10+ beginContact and 10+ endContacts signals with each movement.  Why?  The penguin is ALWAYS onscreen…why are begin/end slots firing?  The penguin is always in contact with my ‘screenEntity’ / collider
    3. I tried to position my boxcollider to fit the scene borders by using anchors.fill : parent.  But that didn’t work (it’s top left corner was fixed at the level’s 0,0 coordinate).  On top of that, I could not move the boxcollider!  I suspect this had something to do with binding…the only way I could make it work was by settings height/width/x/y of the collider.  Can you explain why the first way didn’t work, and the second did?
    4. I assume I need to move the boxcollider as the penguin moves.  Is the OnXChanged slot the penguin the right place to do this?  Does it add a lot of overhead that each X movement requires moving the boxcollider?  Is there a better place to do this?
    5. I have to move the boxcollider to fill the scene since when it’s first created it is out of place.  Where is the best place to set the initial position of the boxcollider?

     

     

    EntityBase {

    id: screenEntity
    property alias screenA: screenA
    entityId: “screen1”
    entityType: “box”
    anchors.fill: parent

    // Collider to determine if body is visible onscreen
    BoxCollider {
    id: screenA
    bodyType: Body.Kinetic
    width: parent.width
    height: parent.height
    x: parent.x
    y: parent.y
    collisionTestingOnlyMode: true

    fixture.onBeginContact: {
    var entityType = other.getBody().target.entityType;
    var entityID = other.getBody().target.entityId;
    console.log(“Begin collide with type “+entityType+” id “+entityID)
    }

    fixture.onEndContact: {
    var entityType = other.getBody().target.entityType;
    var entityID = other.getBody().target.entityId;
    console.log(“End collide with type “+entityType+” id “+entityID)
    }
    }

     

     

Viewing 1 post (of 1 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