Phaser.Ellipse.contains is now working again (thanks @spayton)

This commit is contained in:
photonstorm 2015-02-11 18:51:35 +00:00
parent 0e7820bde5
commit b68c3071a6
2 changed files with 11 additions and 11 deletions

View file

@ -150,6 +150,7 @@ Thanks to @pnstickne for vast majority of this update.
* Timer.update was calling the TimerEvent callback even if `TimerEvent.pendingDelete` was already set to `true`, causing timer events to stack-up in cases where a new TimerEvent was generated in the callback (thanks @clowerweb #838)
* Pointer.stop would call `event.preventDefault` if `Pointer._stateReset` was `true`, which is always `true` after a State has changed and before Pointer.start has been called. However this broken interacting with DOM elements in the case where the State changes and you immediately try to use the DOM element without first having clicked on the Phaser game. An additional guard was added so `preventDefault` will now only be called if both `_stateReste` and `Pointer.withinGame` are true (thanks @satan6 #1509)
* Group.forEach (and many other Group methods) now uses the `children.length` value directly instead of caching it, which both helps performance and stops the loop from breaking should you remove a Group child in the invoked callback.
* Phaser.Ellipse.contains is now working again (thanks @spayton)
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).

View file

@ -276,21 +276,20 @@ Object.defineProperty(Phaser.Ellipse.prototype, "empty", {
* @return {boolean} True if the coordinates are within this ellipse, otherwise false.
*/
Phaser.Ellipse.contains = function (a, x, y) {
if (a.width <= 0 || a.height <= 0)
{
if (a.width <= 0 || a.height <= 0) {
return false;
}
// Normalize the coords to an ellipse with center 0,0
var normx = ((x - a.x) / a.width);
var normy = ((y - a.y) / a.height);
// Normalize the coords to an ellipse with center 0,0 and a radius of 0.5
var normx = ((x - a.x) / a.width) - 0.5;
var normy = ((y - a.y) / a.height) - 0.5;
normx *= normx;
normy *= normy;
return (normx + normy <= 1);
return (normx + normy < 0.25);
};
// Because PIXI uses its own Ellipse, we'll replace it with ours to avoid duplicating code or confusion.