Fire event when mouse is over nothing?


#1

How can I make an event fire when the mouse is not currently hovering over any object?
I have a script which detects when the mouse is over objects and which objects (entity picking), which highlights squares on a grid, but when the mouse leaves the grid entirely I want to remove the last highlighted square, currently it just stays highlighted even if the mouse moves to a different window for example.

Here is the mouse hover code (inside an initialize function):

    app.mouse.on(pc.EVENT_MOUSEMOVE, function(e) {
        var from = this.entity.camera.screenToWorld(e.x, e.y, this.entity.camera.nearClip);
        var to = this.entity.camera.screenToWorld(e.x, e.y, this.entity.camera.farClip);
        app.systems.rigidbody.raycastFirst(from, to, function (result) {
            app.fire('EVENT_HOVER', result.entity); 
        });
    }, this);