mirror of
https://github.com/wassname/phaser.git
synced 2026-09-09 11:28:47 +08:00
Added optimised point in circle test to CircleUtils
This commit is contained in:
@@ -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++)
|
||||
|
||||
Reference in New Issue
Block a user