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?