phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
36.9k stars 7.08k forks source link

[1.2] Sprite.checkWorldBounds is never set. #415

Closed Fishrock123 closed 10 years ago

Fishrock123 commented 10 years ago

Issue origin: 4aa945

In the current 1.2, there is no check that ever sets Sprite.checkWorldBounds.

photonstorm commented 10 years ago

Fixed, latest commit has updated and working "out of bounds" example too.

Fishrock123 commented 10 years ago

Wait what? What does the actual checking then? Meh, nevermind.

photonstorm commented 10 years ago

It was always checked in the preUpdate loop (comparing Sprite.bounds to game world via an intersects). Now I've just basically confirmed it works fine via a test case.

Fishrock123 commented 10 years ago

@photonstorm This issue isn't fixed -- it was about that fact that phaser does not set it.

Can we alleviate having to use .getBounds() by assuming the last bounds is accurate?

https://github.com/GoodBoyDigital/pixi.js/blob/master/src/pixi/display/Sprite.js#L241-L242

photonstorm commented 10 years ago

Doesn't set what? checkWorldBounds and _bounds are both set in the constructor and checked in preUpdate.

_currentBounds, despite what it says above it in the code, doesn't seem to be checked on a pixi level at all.

Fishrock123 commented 10 years ago

We don't have a pre-check that does Sprite.checkWorldBounds = true. So it currently never sets it.

photonstorm commented 10 years ago

But it's disabled by default as it's so expensive, no-where in the phaser source should it ever be set to true. If you want to check the bounds you need to enable it yourself from the game code.

Fishrock123 commented 10 years ago

You had said that Sprite.getBounds() was the expensive part: https://github.com/photonstorm/phaser/commit/4aa945f991a205792aa3b87e364b91cdf83a918c#commitcomment-5373312

Would _currentBounds alleviate that? Would it be accurate enough to do checks on, you think? Or does it not change enough?

photonstorm commented 10 years ago

getBounds is never actually called by Pixi, so _currentBounds won't be populated (or current!). iirc it's called just once by the webgl filter manager.

A safer bounds to use would be the texture frame dimensions imho, but that won't take into account rotation or offsets from parents. There's really no easy way to do it. I guess we could add a flag similar to "this Sprite never rotates, scales or inherits from a parent" - if that was true then you'd only need to do a getBounds once and store the result. And I think in a lot of cases it would be ok too, like bullets in a shmup, or in the Invaders example game. Like a fixed rotation / ultra simple AABB.