Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Event listener for sprite in camera


afcruzs
 Share

Recommended Posts

Is there any way to add a listener that triggers when a sprite is visible by the camera?. The object Sprite contains inCamera, but it seems to re compute the bounds of the sprite according to this: http://www.html5gamedevs.com/topic/8936-does-phaser-handle-object-visibility-according-to-camera/, and that can be expensive. In my case I need to do this for many sprites on the screen, so I want to know if there is a more efficient way to do it.

Link to comment
Share on other sites

Thanks for your answer samme :)

In the docs (https://phaser.io/docs/2.6.2/Phaser.Sprite.html#checkWorldBounds) says that checkWorldBounds calculates the bounds every time and that it can be a expensive operation. Is it worst to use inCamera withouth having set checkWorldBounds to true?. Using intersectsRaw has linear time cost with respect to the size of camera.view.

I am not sure, but it seems like the 3 approaches end up doing calculations in linear time (maybe checkWorldBounds is faster?). I think that using a quadtree or a structure like that can make this operation much faster, but I don't know if the current API has something like that, of if that is even possible anyway.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...