mirror of
https://github.com/wassname/phaser.git
synced 2026-06-27 16:10:15 +08:00
Added optimised point in circle test to CircleUtils
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 6.9 MiB |
@@ -36,8 +36,17 @@ module Phaser {
|
||||
* @return {Boolean} True if the coordinates are within this circle, otherwise false.
|
||||
**/
|
||||
static contains(a: Circle, x: number, y: number): bool {
|
||||
//return (a.radius * a.radius >= Collision.distanceSquared(a.x, a.y, x, y));
|
||||
return true;
|
||||
|
||||
// Check if x/y are within the bounds first
|
||||
if (x >= a.left && x <= a.right && y >= a.top && y <= a.bottom)
|
||||
{
|
||||
var dx: number = (a.x - x) * (a.x - x);
|
||||
var dy: number = (a.y - y) * (a.y - y);
|
||||
return (dx + dy) <= (a.radius * a.radius);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -96,6 +96,14 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
static renderCircle(circle: Phaser.Circle, fillStyle: string = 'rgba(0,255,0,0.3)') {
|
||||
|
||||
DebugUtils.context.fillStyle = fillStyle;
|
||||
DebugUtils.context.arc(circle.x, circle.y, circle.radius, 0, Math.PI * 2, false);
|
||||
DebugUtils.context.fill();
|
||||
|
||||
}
|
||||
|
||||
static renderPhysicsBody(body: Phaser.Physics.Body, lineWidth: number = 1, fillStyle: string = 'rgba(0,255,0,0.2)', sleepStyle: string = 'rgba(100,100,100,0.2)') {
|
||||
|
||||
for (var s = 0; s < body.shapesLength; s++)
|
||||
|
||||
@@ -60,6 +60,7 @@ TODO:
|
||||
* Stage CSS3 Transforms?
|
||||
* Ability to layer another DOM object and have it controlled by the game somehow. Can then do stacked canvas effects.
|
||||
* Stage lost to mute
|
||||
* When game is paused Pointer shouldn't process targetObjects / change cursor
|
||||
|
||||
|
||||
|
||||
@@ -157,6 +158,7 @@ V1.0.0
|
||||
* Dropped the StageScaleMode.setScreenSize iterations count from 40 down to 10 and document min body height to 2000px.
|
||||
* Added Phaser.Net for browser and network specific functions, currently includes query string parsing and updating methods.
|
||||
* Added a new CSS3 Filters component. Apply blur, grayscale, sepia, brightness, contrast, hue rotation, invert, opacity and saturate filters to the games stage.
|
||||
* Fixed the CircleUtils.contains and containsPoint methods
|
||||
|
||||
|
||||
|
||||
|
||||
+12
-2
@@ -20758,8 +20758,18 @@ var Phaser;
|
||||
* @return {Boolean} True if the coordinates are within this circle, otherwise false.
|
||||
**/
|
||||
function contains(a, x, y) {
|
||||
//return (a.radius * a.radius >= Collision.distanceSquared(a.x, a.y, x, y));
|
||||
return true;
|
||||
// Check if x/y are within the bounds first
|
||||
if(x >= a.left && x <= a.right && y >= a.top && y <= a.bottom) {
|
||||
var dx = a.x - x;
|
||||
var dy = a.y - y;
|
||||
dx *= dx;
|
||||
dy *= dy;
|
||||
var radSqr = a.radius * a.radius;
|
||||
console.log('within bounds', dx, dy, radSqr);
|
||||
return (dx + dy) <= radSqr;
|
||||
//return (a.left * a.left + a.top * a.top) <= (a.radius * a.radius);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
CircleUtils.containsPoint = /**
|
||||
* Return true if the coordinates of the given Point object are within this Circle object.
|
||||
|
||||
+12
-2
@@ -20758,8 +20758,18 @@ var Phaser;
|
||||
* @return {Boolean} True if the coordinates are within this circle, otherwise false.
|
||||
**/
|
||||
function contains(a, x, y) {
|
||||
//return (a.radius * a.radius >= Collision.distanceSquared(a.x, a.y, x, y));
|
||||
return true;
|
||||
// Check if x/y are within the bounds first
|
||||
if(x >= a.left && x <= a.right && y >= a.top && y <= a.bottom) {
|
||||
var dx = a.x - x;
|
||||
var dy = a.y - y;
|
||||
dx *= dx;
|
||||
dy *= dy;
|
||||
var radSqr = a.radius * a.radius;
|
||||
console.log('within bounds', dx, dy, radSqr);
|
||||
return (dx + dy) <= radSqr;
|
||||
//return (a.left * a.left + a.top * a.top) <= (a.radius * a.radius);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
CircleUtils.containsPoint = /**
|
||||
* Return true if the coordinates of the given Point object are within this Circle object.
|
||||
|
||||
Reference in New Issue
Block a user