Jump to content

Event listener for sprite in camera


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...