Skip to content

Commit b68c307

Browse files
committed
Phaser.Ellipse.contains is now working again (thanks @spayton)
1 parent 0e7820b commit b68c307

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Thanks to @pnstickne for vast majority of this update.
150150
* 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)
151151
* 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)
152152
* 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.
153+
* Phaser.Ellipse.contains is now working again (thanks @spayton)
153154

154155
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).
155156

src/geom/Ellipse.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,21 +276,20 @@ Object.defineProperty(Phaser.Ellipse.prototype, "empty", {
276276
* @return {boolean} True if the coordinates are within this ellipse, otherwise false.
277277
*/
278278
Phaser.Ellipse.contains = function (a, x, y) {
279-
280-
if (a.width <= 0 || a.height <= 0)
281-
{
279+
280+
if (a.width <= 0 || a.height <= 0) {
282281
return false;
283282
}
284-
285-
// Normalize the coords to an ellipse with center 0,0
286-
var normx = ((x - a.x) / a.width);
287-
var normy = ((y - a.y) / a.height);
288-
283+
284+
// Normalize the coords to an ellipse with center 0,0 and a radius of 0.5
285+
var normx = ((x - a.x) / a.width) - 0.5;
286+
var normy = ((y - a.y) / a.height) - 0.5;
287+
289288
normx *= normx;
290289
normy *= normy;
291-
292-
return (normx + normy <= 1);
293-
290+
291+
return (normx + normy < 0.25);
292+
294293
};
295294

296295
// Because PIXI uses its own Ellipse, we'll replace it with ours to avoid duplicating code or confusion.

0 commit comments

Comments
 (0)