Quantcast
Channel: Pixi.js Latest Topics
Viewing all articles
Browse latest Browse all 3978

How to cull objects out of camera view?

$
0
0

I know this has been asked a few times, but I cannot seem to get it to work in my implementation.

I use this code to control the camera:

stage.pivot.x = user.position.x;
stage.pivot.y = user.position.y;
stage.position.x = renderer.width/2;
stage.position.y = renderer.height/2;

Given an object in a stage, how would I detect it being outside of the camera?

I tried using:

// Works, moving the camera to the right will hide objects as they
// touch the left side of the screen
if (worldTransform.tx < 0) {
  item.visible = false;
}

// Doesn't work at all. Objects touching the right side of the screen
// will continue to be visible
// I haven't even included the code where they become visible again
// and it still doesn't make it invisible
if (worldTransform.tx > 900) {
  item.visible = false;
}

but it doesn't seem to work. I always get the same value every time I log it in the console, even in my game loop and when I move the camera (it prints the same value thousands of times in Chrome's console).

How do you detect objects outside of the "camera's" view?


Viewing all articles
Browse latest Browse all 3978

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>