Multi-Resolution Game Development With GameBuilder Studio Check it out!
NEW Version 0.9.7 has arrived! New Blazing Fast Particle Engine & More Game Actions. Check it out
Catch a mouse up event using code
  • Hi

    How can I catch a mouse up event on a Entity using code. I used the following
    entity.eventDispatcher.addEventListener("mouseUp", onMouseUp);
    But no result (onMouseUp is not called)
  • 2 Comments sorted by
  • @Jelle the way mouse events are evaluated in GameBuilder Engine is by checking for the mouse key and seeing if it has just been released globally. There is an api for this found on the Input Manager it can be accessed like this:

    PBE.inputManager.keyJustReleased(InputKey.MOUSE_BUTTON.keyCode);

    Once you check if the mouse has been released you can then check if the mouse position is over an entity by querying the spatial manager for objects (spatials on entities) under the current mouse position:

    var spatialsUnderPoint : Array = PBE.spatialManager.
    getObjectsUnderPoint( new Point(stageX, stageY) );

    from there you can access the owner of the spatial or the attached renderer on the spatial to see if it is the renderer that you want to detect a mouse up on. (i.e. spatial.spriteForPointChecks).

    If you already have the entity object you want to check directly to see if the mouse is over it then you can access each spatial on the entity using a spatial lookup like this:


    var spatialsOnEntity : Array = entity.lookupComponentsByType(ISpatialObject2D);

    Then you can query each spatial to see if its bounds occupies the current position of the mouse using the spatial.pointOccupied( new Point(stageX, stageY) ) method. Hope this helps.





  • Thank you, it was indeed helpful

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion