Whole codebase updated to TypeScript 0.9.1, phew!

This commit is contained in:
Richard Davey
2013-08-08 19:16:47 +01:00
parent df32190db8
commit 1248a6c06e
129 changed files with 38471 additions and 30343 deletions
+77 -82
View File
@@ -1,14 +1,9 @@
/// <reference path="../Game.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../geom/Circle.ts" />
/// <reference path="../_definitions.ts" />
/**
* Phaser - CircleUtils
*
* A collection of methods useful for manipulating and comparing Circle objects.
*
* TODO:
*/
module Phaser {
@@ -16,26 +11,26 @@ module Phaser {
export class CircleUtils {
/**
* Returns a new Circle object with the same values for the x, y, width, and height properties as the original Circle object.
* @method clone
* Returns a new Circle object with the same values for the x, y, width, and height properties as the original Circle object.
* @method clone
* @param {Circle} a - The Circle object.
* @param {Circle} [optional] out Optional Circle object. If given the values will be set into the object, otherwise a brand new Circle object will be created and returned.
* @return {Phaser.Circle}
**/
static clone(a: Circle, out: Circle = new Circle): Circle {
* @param {Circle} [optional] out Optional Circle object. If given the values will be set into the object, otherwise a brand new Circle object will be created and returned.
* @return {Phaser.Circle}
**/
static clone(a: Phaser.Circle, out: Phaser.Circle = new Phaser.Circle): Phaser.Circle {
return out.setTo(a.x, a.y, a.diameter);
}
/**
* Return true if the given x/y coordinates are within the Circle object.
* Return true if the given x/y coordinates are within the Circle object.
* If you need details about the intersection then use Phaser.Intersect.circleContainsPoint instead.
* @method contains
* @method contains
* @param {Circle} a - The Circle object.
* @param {Number} The X value of the coordinate to test.
* @param {Number} The Y value of the coordinate to test.
* @return {Boolean} True if the coordinates are within this circle, otherwise false.
**/
static contains(a: Circle, x: number, y: number): boolean {
* @param {Number} The X value of the coordinate to test.
* @param {Number} The Y value of the coordinate to test.
* @return {Boolean} True if the coordinates are within this circle, otherwise false.
**/
static contains(a: Phaser.Circle, x: number, y: number): boolean {
// Check if x/y are within the bounds first
if (x >= a.left && x <= a.right && y >= a.top && y <= a.bottom)
@@ -44,44 +39,44 @@ module Phaser {
var dy: number = (a.y - y) * (a.y - y);
return (dx + dy) <= (a.radius * a.radius);
}
return false;
}
/**
* Return true if the coordinates of the given Point object are within this Circle object.
* Return true if the coordinates of the given Point object are within this Circle object.
* If you need details about the intersection then use Phaser.Intersect.circleContainsPoint instead.
* @method containsPoint
* @method containsPoint
* @param {Circle} a - The Circle object.
* @param {Point} The Point object to test.
* @return {Boolean} True if the coordinates are within this circle, otherwise false.
**/
static containsPoint(a: Circle, point:Point): boolean {
* @param {Point} The Point object to test.
* @return {Boolean} True if the coordinates are within this circle, otherwise false.
**/
static containsPoint(a: Phaser.Circle, point: Phaser.Point): boolean {
return CircleUtils.contains(a, point.x, point.y);
}
/**
* Return true if the given Circle is contained entirely within this Circle object.
* Return true if the given Circle is contained entirely within this Circle object.
* If you need details about the intersection then use Phaser.Intersect.circleToCircle instead.
* @method containsCircle
* @param {Circle} The Circle object to test.
* @return {Boolean} True if the coordinates are within this circle, otherwise false.
**/
static containsCircle(a:Circle, b:Circle): boolean {
* @method containsCircle
* @param {Circle} The Circle object to test.
* @return {Boolean} True if the coordinates are within this circle, otherwise false.
**/
static containsCircle(a: Phaser.Circle, b: Phaser.Circle): boolean {
//return ((a.radius + b.radius) * (a.radius + b.radius)) >= Collision.distanceSquared(a.x, a.y, b.x, b.y);
return true;
}
/**
* Returns the distance from the center of the Circle object to the given object (can be Circle, Point or anything with x/y properties)
* @method distanceBetween
* @param {Circle} a - The Circle object.
* @param {Circle} b - The target object. Must have visible x and y properties that represent the center of the object.
* @param {Boolean} [optional] round - Round the distance to the nearest integer (default false)
* @return {Number} The distance between this Point object and the destination Point object.
**/
static distanceBetween(a:Circle, target: any, round: boolean = false): number {
* Returns the distance from the center of the Circle object to the given object (can be Circle, Point or anything with x/y properties)
* @method distanceBetween
* @param {Circle} a - The Circle object.
* @param {Circle} b - The target object. Must have visible x and y properties that represent the center of the object.
* @param {Boolean} [optional] round - Round the distance to the nearest integer (default false)
* @return {Number} The distance between this Point object and the destination Point object.
**/
static distanceBetween(a: Phaser.Circle, target: any, round: boolean = false): number {
var dx = a.x - target.x;
var dy = a.y - target.y;
@@ -98,42 +93,42 @@ module Phaser {
}
/**
* Determines whether the two Circle objects match. This method compares the x, y and diameter properties.
* @method equals
* Determines whether the two Circle objects match. This method compares the x, y and diameter properties.
* @method equals
* @param {Circle} a - The first Circle object.
* @param {Circle} b - The second Circle object.
* @return {Boolean} A value of true if the object has exactly the same values for the x, y and diameter properties as this Circle object; otherwise false.
**/
static equals(a:Circle, b: Circle): boolean {
* @return {Boolean} A value of true if the object has exactly the same values for the x, y and diameter properties as this Circle object; otherwise false.
**/
static equals(a: Phaser.Circle, b: Phaser.Circle): boolean {
return (a.x == b.x && a.y == b.y && a.diameter == b.diameter);
}
/**
* Determines whether the two Circle objects intersect.
* Determines whether the two Circle objects intersect.
* This method checks the radius distances between the two Circle objects to see if they intersect.
* @method intersects
* @method intersects
* @param {Circle} a - The first Circle object.
* @param {Circle} b - The second Circle object.
* @return {Boolean} A value of true if the specified object intersects with this Circle object; otherwise false.
**/
static intersects(a:Circle, b: Circle): boolean {
return (CircleUtils.distanceBetween(a, b) <= (a.radius + b.radius));
* @return {Boolean} A value of true if the specified object intersects with this Circle object; otherwise false.
**/
static intersects(a: Phaser.Circle, b: Phaser.Circle): boolean {
return (Phaser.CircleUtils.distanceBetween(a, b) <= (a.radius + b.radius));
}
/**
* Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle.
* @method circumferencePoint
* Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle.
* @method circumferencePoint
* @param {Circle} a - The first Circle object.
* @param {Number} angle The angle in radians (unless asDegrees is true) to return the point from.
* @param {Boolean} asDegrees Is the given angle in radians (false) or degrees (true)?
* @param {Phaser.Point} [optional] output An optional Point object to put the result in to. If none specified a new Point object will be created.
* @return {Phaser.Point} The Point object holding the result.
**/
static circumferencePoint(a:Circle, angle: number, asDegrees: boolean = false, out: Point = new Point): Point {
* @param {Number} angle The angle in radians (unless asDegrees is true) to return the point from.
* @param {Boolean} asDegrees Is the given angle in radians (false) or degrees (true)?
* @param {Phaser.Point} [optional] output An optional Point object to put the result in to. If none specified a new Point object will be created.
* @return {Phaser.Point} The Point object holding the result.
**/
static circumferencePoint(a: Phaser.Circle, angle: number, asDegrees: boolean = false, out: Phaser.Point = new Phaser.Point): Phaser.Point {
if (asDegrees === true)
{
angle = angle * GameMath.DEG_TO_RAD;
angle = angle * Phaser.GameMath.DEG_TO_RAD;
}
return out.setTo(a.x + a.radius * Math.cos(angle), a.y + a.radius * Math.sin(angle));
@@ -141,29 +136,29 @@ module Phaser {
}
/*
public static boolean intersect(Rectangle r, Circle c)
{
float cx = Math.abs(c.x - r.x - r.halfWidth);
float xDist = r.halfWidth + c.radius;
if (cx > xDist)
return false;
float cy = Math.abs(c.y - r.y - r.halfHeight);
float yDist = r.halfHeight + c.radius;
if (cy > yDist)
return false;
if (cx <= r.halfWidth || cy <= r.halfHeight)
return true;
float xCornerDist = cx - r.halfWidth;
float yCornerDist = cy - r.halfHeight;
float xCornerDistSq = xCornerDist * xCornerDist;
float yCornerDistSq = yCornerDist * yCornerDist;
float maxCornerDistSq = c.radius * c.radius;
return xCornerDistSq + yCornerDistSq <= maxCornerDistSq;
}
*/
/*
public static boolean intersect(Rectangle r, Circle c)
{
float cx = Math.abs(c.x - r.x - r.halfWidth);
float xDist = r.halfWidth + c.radius;
if (cx > xDist)
return false;
float cy = Math.abs(c.y - r.y - r.halfHeight);
float yDist = r.halfHeight + c.radius;
if (cy > yDist)
return false;
if (cx <= r.halfWidth || cy <= r.halfHeight)
return true;
float xCornerDist = cx - r.halfWidth;
float yCornerDist = cy - r.halfHeight;
float xCornerDistSq = xCornerDist * xCornerDist;
float yCornerDistSq = yCornerDist * yCornerDist;
float maxCornerDistSq = c.radius * c.radius;
return xCornerDistSq + yCornerDistSq <= maxCornerDistSq;
}
*/
static intersectsRectangle(c: Circle, r: Rectangle): boolean {
static intersectsRectangle(c: Phaser.Circle, r: Phaser.Rectangle): boolean {
var cx: number = Math.abs(c.x - r.x - r.halfWidth);
var xDist: number = r.halfWidth + c.radius;
+45 -48
View File
@@ -1,7 +1,4 @@
/// <reference path="../Game.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../geom/Circle.ts" />
/// <reference path="../_definitions.ts" />
/**
* Phaser - ColorUtils
@@ -13,7 +10,7 @@ module Phaser {
export class ColorUtils {
static game: Game;
static game: Phaser.Game;
/**
* Given an alpha and 3 color values this will return an integer representation of it
@@ -55,7 +52,7 @@ module Phaser {
for (var c: number = 0; c <= 359; c++)
{
colors[c] = ColorUtils.getWebRGB(ColorUtils.HSVtoRGB(c, 1.0, 1.0, alpha));
colors[c] = Phaser.ColorUtils.getWebRGB(Phaser.ColorUtils.HSVtoRGB(c, 1.0, 1.0, alpha));
}
return colors;
@@ -73,11 +70,11 @@ module Phaser {
*/
public static getComplementHarmony(color: number): number {
var hsv: any = ColorUtils.RGBtoHSV(color);
var hsv: any = Phaser.ColorUtils.RGBtoHSV(color);
var opposite: number = ColorUtils.game.math.wrapValue(hsv.hue, 180, 359);
var opposite: number = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 180, 359);
return ColorUtils.HSVtoRGB(opposite, 1.0, 1.0);
return Phaser.ColorUtils.HSVtoRGB(opposite, 1.0, 1.0);
}
@@ -93,17 +90,17 @@ module Phaser {
*/
public static getAnalogousHarmony(color: number, threshold: number = 30) {
var hsv: any = ColorUtils.RGBtoHSV(color);
var hsv: any = Phaser.ColorUtils.RGBtoHSV(color);
if (threshold > 359 || threshold < 0)
{
throw Error("Color Warning: Invalid threshold given to getAnalogousHarmony()");
}
var warmer: number = ColorUtils.game.math.wrapValue(hsv.hue, 359 - threshold, 359);
var colder: number = ColorUtils.game.math.wrapValue(hsv.hue, threshold, 359);
var warmer: number = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 359 - threshold, 359);
var colder: number = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, threshold, 359);
return { color1: color, color2: ColorUtils.HSVtoRGB(warmer, 1.0, 1.0), color3: ColorUtils.HSVtoRGB(colder, 1.0, 1.0), hue1: hsv.hue, hue2: warmer, hue3: colder }
return { color1: color, color2: Phaser.ColorUtils.HSVtoRGB(warmer, 1.0, 1.0), color3: Phaser.ColorUtils.HSVtoRGB(colder, 1.0, 1.0), hue1: hsv.hue, hue2: warmer, hue3: colder }
}
@@ -119,19 +116,19 @@ module Phaser {
*/
public static getSplitComplementHarmony(color: number, threshold: number = 30): any {
var hsv: any = ColorUtils.RGBtoHSV(color);
var hsv: any = Phaser.ColorUtils.RGBtoHSV(color);
if (threshold >= 359 || threshold <= 0)
{
throw Error("ColorUtils Warning: Invalid threshold given to getSplitComplementHarmony()");
throw Error("Phaser.ColorUtils Warning: Invalid threshold given to getSplitComplementHarmony()");
}
var opposite: number = ColorUtils.game.math.wrapValue(hsv.hue, 180, 359);
var opposite: number = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 180, 359);
var warmer: number = ColorUtils.game.math.wrapValue(hsv.hue, opposite - threshold, 359);
var colder: number = ColorUtils.game.math.wrapValue(hsv.hue, opposite + threshold, 359);
var warmer: number = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, opposite - threshold, 359);
var colder: number = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, opposite + threshold, 359);
return { color1: color, color2: ColorUtils.HSVtoRGB(warmer, hsv.saturation, hsv.value), color3: ColorUtils.HSVtoRGB(colder, hsv.saturation, hsv.value), hue1: hsv.hue, hue2: warmer, hue3: colder }
return { color1: color, color2: Phaser.ColorUtils.HSVtoRGB(warmer, hsv.saturation, hsv.value), color3: Phaser.ColorUtils.HSVtoRGB(colder, hsv.saturation, hsv.value), hue1: hsv.hue, hue2: warmer, hue3: colder }
}
/**
@@ -145,12 +142,12 @@ module Phaser {
*/
public static getTriadicHarmony(color: number): any {
var hsv: any = ColorUtils.RGBtoHSV(color);
var hsv: any = Phaser.ColorUtils.RGBtoHSV(color);
var triadic1: number = ColorUtils.game.math.wrapValue(hsv.hue, 120, 359);
var triadic2: number = ColorUtils.game.math.wrapValue(triadic1, 120, 359);
var triadic1: number = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 120, 359);
var triadic2: number = Phaser.ColorUtils.game.math.wrapValue(triadic1, 120, 359);
return { color1: color, color2: ColorUtils.HSVtoRGB(triadic1, 1.0, 1.0), color3: ColorUtils.HSVtoRGB(triadic2, 1.0, 1.0) }
return { color1: color, color2: Phaser.ColorUtils.HSVtoRGB(triadic1, 1.0, 1.0), color3: Phaser.ColorUtils.HSVtoRGB(triadic2, 1.0, 1.0) }
}
@@ -164,11 +161,11 @@ module Phaser {
*/
public static getColorInfo(color: number): string {
var argb: any = ColorUtils.getRGB(color);
var hsl: any = ColorUtils.RGBtoHSV(color);
var argb: any = Phaser.ColorUtils.getRGB(color);
var hsl: any = Phaser.ColorUtils.RGBtoHSV(color);
// Hex format
var result: string = ColorUtils.RGBtoHexstring(color) + "\n";
var result: string = Phaser.ColorUtils.RGBtoHexstring(color) + "\n";
// RGB format
result = result.concat("Alpha: " + argb.alpha + " Red: " + argb.red + " Green: " + argb.green + " Blue: " + argb.blue) + "\n";
@@ -189,9 +186,9 @@ module Phaser {
*/
public static RGBtoHexstring(color: number): string {
var argb: any = ColorUtils.getRGB(color);
var argb: any = Phaser.ColorUtils.getRGB(color);
return "0x" + ColorUtils.colorToHexstring(argb.alpha) + ColorUtils.colorToHexstring(argb.red) + ColorUtils.colorToHexstring(argb.green) + ColorUtils.colorToHexstring(argb.blue);
return "0x" + Phaser.ColorUtils.colorToHexstring(argb.alpha) + Phaser.ColorUtils.colorToHexstring(argb.red) + Phaser.ColorUtils.colorToHexstring(argb.green) + Phaser.ColorUtils.colorToHexstring(argb.blue);
}
@@ -204,9 +201,9 @@ module Phaser {
*/
public static RGBtoWebstring(color: number): string {
var argb: any = ColorUtils.getRGB(color);
var argb: any = Phaser.ColorUtils.getRGB(color);
return "#" + ColorUtils.colorToHexstring(argb.red) + ColorUtils.colorToHexstring(argb.green) + ColorUtils.colorToHexstring(argb.blue);
return "#" + Phaser.ColorUtils.colorToHexstring(argb.red) + Phaser.ColorUtils.colorToHexstring(argb.green) + Phaser.ColorUtils.colorToHexstring(argb.blue);
}
@@ -246,7 +243,7 @@ module Phaser {
if (s == 0.0)
{
result = ColorUtils.getColor32(alpha, v * 255, v * 255, v * 255);
result = Phaser.ColorUtils.getColor32(alpha, v * 255, v * 255, v * 255);
}
else
{
@@ -259,31 +256,31 @@ module Phaser {
switch (Math.floor(h))
{
case 0:
result = ColorUtils.getColor32(alpha, v * 255, t * 255, p * 255);
result = Phaser.ColorUtils.getColor32(alpha, v * 255, t * 255, p * 255);
break;
case 1:
result = ColorUtils.getColor32(alpha, q * 255, v * 255, p * 255);
result = Phaser.ColorUtils.getColor32(alpha, q * 255, v * 255, p * 255);
break;
case 2:
result = ColorUtils.getColor32(alpha, p * 255, v * 255, t * 255);
result = Phaser.ColorUtils.getColor32(alpha, p * 255, v * 255, t * 255);
break;
case 3:
result = ColorUtils.getColor32(alpha, p * 255, q * 255, v * 255);
result = Phaser.ColorUtils.getColor32(alpha, p * 255, q * 255, v * 255);
break;
case 4:
result = ColorUtils.getColor32(alpha, t * 255, p * 255, v * 255);
result = Phaser.ColorUtils.getColor32(alpha, t * 255, p * 255, v * 255);
break;
case 5:
result = ColorUtils.getColor32(alpha, v * 255, p * 255, q * 255);
result = Phaser.ColorUtils.getColor32(alpha, v * 255, p * 255, q * 255);
break;
default:
throw new Error("ColorUtils.HSVtoRGB : Unknown color");
throw new Error("Phaser.ColorUtils.HSVtoRGB : Unknown color");
}
}
@@ -300,7 +297,7 @@ module Phaser {
*/
public static RGBtoHSV(color: number): any {
var rgb: any = ColorUtils.getRGB(color);
var rgb: any = Phaser.ColorUtils.getRGB(color);
var red: number = rgb.red / 255;
var green: number = rgb.green / 255;
@@ -379,14 +376,14 @@ module Phaser {
*/
public static interpolateColor(color1: number, color2: number, steps: number, currentStep: number, alpha: number = 255): number {
var src1: any = ColorUtils.getRGB(color1);
var src2: any = ColorUtils.getRGB(color2);
var src1: any = Phaser.ColorUtils.getRGB(color1);
var src2: any = Phaser.ColorUtils.getRGB(color2);
var r: number = (((src2.red - src1.red) * currentStep) / steps) + src1.red;
var g: number = (((src2.green - src1.green) * currentStep) / steps) + src1.green;
var b: number = (((src2.blue - src1.blue) * currentStep) / steps) + src1.blue;
return ColorUtils.getColor32(alpha, r, g, b);
return Phaser.ColorUtils.getColor32(alpha, r, g, b);
}
@@ -404,13 +401,13 @@ module Phaser {
*/
public static interpolateColorWithRGB(color: number, r2: number, g2: number, b2: number, steps: number, currentStep: number): number {
var src: any = ColorUtils.getRGB(color);
var src: any = Phaser.ColorUtils.getRGB(color);
var r: number = (((r2 - src.red) * currentStep) / steps) + src.red;
var g: number = (((g2 - src.green) * currentStep) / steps) + src.green;
var b: number = (((b2 - src.blue) * currentStep) / steps) + src.blue;
return ColorUtils.getColor(r, g, b);
return Phaser.ColorUtils.getColor(r, g, b);
}
@@ -434,7 +431,7 @@ module Phaser {
var g: number = (((g2 - g1) * currentStep) / steps) + g1;
var b: number = (((b2 - b1) * currentStep) / steps) + b1;
return ColorUtils.getColor(r, g, b);
return Phaser.ColorUtils.getColor(r, g, b);
}
@@ -454,19 +451,19 @@ module Phaser {
// Sanity checks
if (max > 255)
{
return ColorUtils.getColor(255, 255, 255);
return Phaser.ColorUtils.getColor(255, 255, 255);
}
if (min > max)
{
return ColorUtils.getColor(255, 255, 255);
return Phaser.ColorUtils.getColor(255, 255, 255);
}
var red: number = min + Math.round(Math.random() * (max - min));
var green: number = min + Math.round(Math.random() * (max - min));
var blue: number = min + Math.round(Math.random() * (max - min));
return ColorUtils.getColor32(alpha, red, green, blue);
return Phaser.ColorUtils.getColor32(alpha, red, green, blue);
}
+103 -108
View File
@@ -1,9 +1,4 @@
/// <reference path="../Game.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../geom/Circle.ts" />
/// <reference path="../gameobjects/Sprite.ts" />
/// <reference path="RectangleUtils.ts" />
/// <reference path="../_definitions.ts" />
/**
* Phaser - DebugUtils
@@ -15,7 +10,7 @@ module Phaser {
export class DebugUtils {
static game: Game;
static game: Phaser.Game;
/**
* The context to which the render debug info will be drawn.
@@ -33,12 +28,12 @@ module Phaser {
static start(x: number, y: number, color: string = 'rgb(255,255,255)') {
DebugUtils.currentX = x;
DebugUtils.currentY = y;
DebugUtils.currentColor = color;
Phaser.DebugUtils.currentX = x;
Phaser.DebugUtils.currentY = y;
Phaser.DebugUtils.currentColor = color;
DebugUtils.context.fillStyle = color;
DebugUtils.context.font = font;
Phaser.DebugUtils.context.fillStyle = color;
Phaser.DebugUtils.context.font = Phaser.DebugUtils.font;
}
@@ -46,35 +41,35 @@ module Phaser {
if (x !== null)
{
DebugUtils.currentX = x;
Phaser.DebugUtils.currentX = x;
}
if (y !== null)
{
DebugUtils.currentY = y;
Phaser.DebugUtils.currentY = y;
}
if (renderShadow)
if (Phaser.DebugUtils.renderShadow)
{
DebugUtils.context.fillStyle = 'rgb(0,0,0)';
DebugUtils.context.fillText(text, DebugUtils.currentX + 1, DebugUtils.currentY + 1);
DebugUtils.context.fillStyle = DebugUtils.currentColor;
Phaser.DebugUtils.context.fillStyle = 'rgb(0,0,0)';
Phaser.DebugUtils.context.fillText(text, Phaser.DebugUtils.currentX + 1, Phaser.DebugUtils.currentY + 1);
Phaser.DebugUtils.context.fillStyle = Phaser.DebugUtils.currentColor;
}
DebugUtils.context.fillText(text, DebugUtils.currentX, DebugUtils.currentY);
Phaser.DebugUtils.context.fillText(text, Phaser.DebugUtils.currentX, Phaser.DebugUtils.currentY);
DebugUtils.currentY += lineHeight;
Phaser.DebugUtils.currentY += Phaser.DebugUtils.lineHeight;
}
static renderSpriteCorners(sprite: Sprite, color: string = 'rgb(255,0,255)') {
static renderSpriteCorners(sprite: Phaser.Sprite, color: string = 'rgb(255,0,255)') {
start(0, 0, color);
Phaser.DebugUtils.start(0, 0, color);
line('x: ' + Math.floor(sprite.transform.upperLeft.x) + ' y: ' + Math.floor(sprite.transform.upperLeft.y), sprite.transform.upperLeft.x, sprite.transform.upperLeft.y);
line('x: ' + Math.floor(sprite.transform.upperRight.x) + ' y: ' + Math.floor(sprite.transform.upperRight.y), sprite.transform.upperRight.x, sprite.transform.upperRight.y);
line('x: ' + Math.floor(sprite.transform.bottomLeft.x) + ' y: ' + Math.floor(sprite.transform.bottomLeft.y), sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y);
line('x: ' + Math.floor(sprite.transform.bottomRight.x) + ' y: ' + Math.floor(sprite.transform.bottomRight.y), sprite.transform.bottomRight.x, sprite.transform.bottomRight.y);
Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.upperLeft.x) + ' y: ' + Math.floor(sprite.transform.upperLeft.y), sprite.transform.upperLeft.x, sprite.transform.upperLeft.y);
Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.upperRight.x) + ' y: ' + Math.floor(sprite.transform.upperRight.y), sprite.transform.upperRight.x, sprite.transform.upperRight.y);
Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.bottomLeft.x) + ' y: ' + Math.floor(sprite.transform.bottomLeft.y), sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y);
Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.bottomRight.x) + ' y: ' + Math.floor(sprite.transform.bottomRight.y), sprite.transform.bottomRight.x, sprite.transform.bottomRight.y);
}
@@ -84,22 +79,22 @@ module Phaser {
* @param y {number} Y position of the debug info to be rendered.
* @param [color] {number} color of the debug info to be rendered. (format is css color string)
*/
static renderSoundInfo(sound: Sound, x: number, y: number, color: string = 'rgb(255,255,255)') {
static renderSoundInfo(sound: Phaser.Sound, x: number, y: number, color: string = 'rgb(255,255,255)') {
start(x, y, color);
Phaser.DebugUtils.start(x, y, color);
line('Sound: ' + sound.key + ' Locked: ' + sound.game.sound.touchLocked + ' Pending Playback: ' + sound.pendingPlayback);
line('Decoded: ' + sound.isDecoded + ' Decoding: ' + sound.isDecoding);
line('Total Duration: ' + sound.totalDuration + ' Playing: ' + sound.isPlaying);
line('Time: ' + sound.currentTime);
line('Volume: ' + sound.volume + ' Muted: ' + sound.mute);
line('WebAudio: ' + sound.usingWebAudio + ' Audio: ' + sound.usingAudioTag);
Phaser.DebugUtils.line('Sound: ' + sound.key + ' Locked: ' + sound.game.sound.touchLocked + ' Pending Playback: ' + sound.pendingPlayback);
Phaser.DebugUtils.line('Decoded: ' + sound.isDecoded + ' Decoding: ' + sound.isDecoding);
Phaser.DebugUtils.line('Total Duration: ' + sound.totalDuration + ' Playing: ' + sound.isPlaying);
Phaser.DebugUtils.line('Time: ' + sound.currentTime);
Phaser.DebugUtils.line('Volume: ' + sound.volume + ' Muted: ' + sound.mute);
Phaser.DebugUtils.line('WebAudio: ' + sound.usingWebAudio + ' Audio: ' + sound.usingAudioTag);
if (sound.currentMarker !== '')
{
line('Marker: ' + sound.currentMarker + ' Duration: ' + sound.duration);
line('Start: ' + sound.markers[sound.currentMarker].start + ' Stop: ' + sound.markers[sound.currentMarker].stop);
line('Position: ' + sound.position);
Phaser.DebugUtils.line('Marker: ' + sound.currentMarker + ' Duration: ' + sound.duration);
Phaser.DebugUtils.line('Start: ' + sound.markers[sound.currentMarker].start + ' Stop: ' + sound.markers[sound.currentMarker].stop);
Phaser.DebugUtils.line('Position: ' + sound.position);
}
}
@@ -110,17 +105,17 @@ module Phaser {
* @param y {number} Y position of the debug info to be rendered.
* @param [color] {number} color of the debug info to be rendered. (format is css color string)
*/
static renderCameraInfo(camera: Camera, x: number, y: number, color: string = 'rgb(255,255,255)') {
static renderCameraInfo(camera: Phaser.Camera, x: number, y: number, color: string = 'rgb(255,255,255)') {
start(x, y, color);
line('Camera ID: ' + camera.ID + ' (' + camera.screenView.width + ' x ' + camera.screenView.height + ')');
line('X: ' + camera.x + ' Y: ' + camera.y + ' Rotation: ' + camera.transform.rotation);
line('WorldView X: ' + camera.worldView.x + ' Y: ' + camera.worldView.y + ' W: ' + camera.worldView.width + ' H: ' + camera.worldView.height);
line('ScreenView X: ' + camera.screenView.x + ' Y: ' + camera.screenView.y + ' W: ' + camera.screenView.width + ' H: ' + camera.screenView.height);
Phaser.DebugUtils.start(x, y, color);
Phaser.DebugUtils.line('Camera ID: ' + camera.ID + ' (' + camera.screenView.width + ' x ' + camera.screenView.height + ')');
Phaser.DebugUtils.line('X: ' + camera.x + ' Y: ' + camera.y + ' Rotation: ' + camera.transform.rotation);
Phaser.DebugUtils.line('WorldView X: ' + camera.worldView.x + ' Y: ' + camera.worldView.y + ' W: ' + camera.worldView.width + ' H: ' + camera.worldView.height);
Phaser.DebugUtils.line('ScreenView X: ' + camera.screenView.x + ' Y: ' + camera.screenView.y + ' W: ' + camera.screenView.width + ' H: ' + camera.screenView.height);
if (camera.worldBounds)
{
line('Bounds: ' + camera.worldBounds.width + ' x ' + camera.worldBounds.height);
Phaser.DebugUtils.line('Bounds: ' + camera.worldBounds.width + ' x ' + camera.worldBounds.height);
}
}
@@ -129,43 +124,43 @@ module Phaser {
* Renders the Pointer.circle object onto the stage in green if down or red if up.
* @method renderDebug
*/
static renderPointer(pointer: Pointer, hideIfUp: boolean = false, downColor: string = 'rgba(0,255,0,0.5)', upColor: string = 'rgba(255,0,0,0.5)', color: string = 'rgb(255,255,255)') {
static renderPointer(pointer: Phaser.Pointer, hideIfUp: boolean = false, downColor: string = 'rgba(0,255,0,0.5)', upColor: string = 'rgba(255,0,0,0.5)', color: string = 'rgb(255,255,255)') {
if (hideIfUp == true && pointer.isUp == true)
{
return;
}
DebugUtils.context.beginPath();
DebugUtils.context.arc(pointer.x, pointer.y, pointer.circle.radius, 0, Math.PI * 2);
Phaser.DebugUtils.context.beginPath();
Phaser.DebugUtils.context.arc(pointer.x, pointer.y, pointer.circle.radius, 0, Math.PI * 2);
if (pointer.active)
{
DebugUtils.context.fillStyle = downColor;
Phaser.DebugUtils.context.fillStyle = downColor;
}
else
{
DebugUtils.context.fillStyle = upColor;
Phaser.DebugUtils.context.fillStyle = upColor;
}
DebugUtils.context.fill();
DebugUtils.context.closePath();
Phaser.DebugUtils.context.fill();
Phaser.DebugUtils.context.closePath();
// Render the points
DebugUtils.context.beginPath();
DebugUtils.context.moveTo(pointer.positionDown.x, pointer.positionDown.y);
DebugUtils.context.lineTo(pointer.position.x, pointer.position.y);
DebugUtils.context.lineWidth = 2;
DebugUtils.context.stroke();
DebugUtils.context.closePath();
Phaser.DebugUtils.context.beginPath();
Phaser.DebugUtils.context.moveTo(pointer.positionDown.x, pointer.positionDown.y);
Phaser.DebugUtils.context.lineTo(pointer.position.x, pointer.position.y);
Phaser.DebugUtils.context.lineWidth = 2;
Phaser.DebugUtils.context.stroke();
Phaser.DebugUtils.context.closePath();
// Render the text
start(pointer.x, pointer.y - 100, color);
Phaser.DebugUtils.start(pointer.x, pointer.y - 100, color);
line('ID: ' + pointer.id + " Active: " + pointer.active);
line('World X: ' + pointer.worldX + " World Y: " + pointer.worldY);
line('Screen X: ' + pointer.x + " Screen Y: " + pointer.y);
line('Duration: ' + pointer.duration + " ms");
Phaser.DebugUtils.line('ID: ' + pointer.id + " Active: " + pointer.active);
Phaser.DebugUtils.line('World X: ' + pointer.worldX + " World Y: " + pointer.worldY);
Phaser.DebugUtils.line('Screen X: ' + pointer.x + " Screen Y: " + pointer.y);
Phaser.DebugUtils.line('Duration: ' + pointer.duration + " ms");
}
@@ -175,15 +170,15 @@ module Phaser {
* @param y {number} Y position of the debug info to be rendered.
* @param [color] {number} color of the debug info to be rendered. (format is css color string)
*/
static renderSpriteInputInfo(sprite: Sprite, x: number, y: number, color: string = 'rgb(255,255,255)') {
static renderSpriteInputInfo(sprite: Phaser.Sprite, x: number, y: number, color: string = 'rgb(255,255,255)') {
start(x, y, color);
Phaser.DebugUtils.start(x, y, color);
line('Sprite Input: (' + sprite.width + ' x ' + sprite.height + ')');
line('x: ' + sprite.input.pointerX().toFixed(1) + ' y: ' + sprite.input.pointerY().toFixed(1));
line('over: ' + sprite.input.pointerOver() + ' duration: ' + sprite.input.overDuration().toFixed(0));
line('down: ' + sprite.input.pointerDown() + ' duration: ' + sprite.input.downDuration().toFixed(0));
line('just over: ' + sprite.input.justOver() + ' just out: ' + sprite.input.justOut());
Phaser.DebugUtils.line('Sprite Input: (' + sprite.width + ' x ' + sprite.height + ')');
Phaser.DebugUtils.line('x: ' + sprite.input.pointerX().toFixed(1) + ' y: ' + sprite.input.pointerY().toFixed(1));
Phaser.DebugUtils.line('over: ' + sprite.input.pointerOver() + ' duration: ' + sprite.input.overDuration().toFixed(0));
Phaser.DebugUtils.line('down: ' + sprite.input.pointerDown() + ' duration: ' + sprite.input.downDuration().toFixed(0));
Phaser.DebugUtils.line('just over: ' + sprite.input.justOver() + ' just out: ' + sprite.input.justOut());
}
@@ -195,30 +190,30 @@ module Phaser {
*/
static renderInputInfo(x: number, y: number, color: string = 'rgb(255,255,255)') {
start(x, y, color);
Phaser.DebugUtils.start(x, y, color);
if (game.input.camera)
if (Phaser.DebugUtils.game.input.camera)
{
line('Input - Camera: ' + game.input.camera.ID);
Phaser.DebugUtils.line('Input - Camera: ' + Phaser.DebugUtils.game.input.camera.ID);
}
else
{
line('Input - Camera: null');
Phaser.DebugUtils.line('Input - Camera: null');
}
line('X: ' + game.input.x + ' Y: ' + game.input.y);
line('World X: ' + game.input.worldX + ' World Y: ' + game.input.worldY);
line('Scale X: ' + game.input.scale.x.toFixed(1) + ' Scale Y: ' + game.input.scale.x.toFixed(1));
line('Screen X: ' + game.input.activePointer.screenX + ' Screen Y: ' + game.input.activePointer.screenY);
Phaser.DebugUtils.line('X: ' + Phaser.DebugUtils.game.input.x + ' Y: ' + Phaser.DebugUtils.game.input.y);
Phaser.DebugUtils.line('World X: ' + Phaser.DebugUtils.game.input.worldX + ' World Y: ' + Phaser.DebugUtils.game.input.worldY);
Phaser.DebugUtils.line('Scale X: ' + Phaser.DebugUtils.game.input.scale.x.toFixed(1) + ' Scale Y: ' + Phaser.DebugUtils.game.input.scale.x.toFixed(1));
Phaser.DebugUtils.line('Screen X: ' + Phaser.DebugUtils.game.input.activePointer.screenX + ' Screen Y: ' + Phaser.DebugUtils.game.input.activePointer.screenY);
}
static renderSpriteWorldView(sprite: Sprite, x: number, y: number, color: string = 'rgb(255,255,255)') {
static renderSpriteWorldView(sprite: Phaser.Sprite, x: number, y: number, color: string = 'rgb(255,255,255)') {
start(x, y, color);
line('Sprite World Coords (' + sprite.width + ' x ' + sprite.height + ')');
line('x: ' + sprite.worldView.x + ' y: ' + sprite.worldView.y);
line('bottom: ' + sprite.worldView.bottom + ' right: ' + sprite.worldView.right.toFixed(1));
Phaser.DebugUtils.start(x, y, color);
Phaser.DebugUtils.line('Sprite World Coords (' + sprite.width + ' x ' + sprite.height + ')');
Phaser.DebugUtils.line('x: ' + sprite.worldView.x + ' y: ' + sprite.worldView.y);
Phaser.DebugUtils.line('bottom: ' + sprite.worldView.bottom + ' right: ' + sprite.worldView.right.toFixed(1));
}
@@ -228,61 +223,61 @@ module Phaser {
* @param y {number} Y position of the debug info to be rendered.
* @param [color] {number} color of the debug info to be rendered. (format is css color string)
*/
static renderSpriteInfo(sprite: Sprite, x: number, y: number, color: string = 'rgb(255,255,255)') {
static renderSpriteInfo(sprite: Phaser.Sprite, x: number, y: number, color: string = 'rgb(255,255,255)') {
start(x, y, color);
line('Sprite: ' + ' (' + sprite.width + ' x ' + sprite.height + ') origin: ' + sprite.transform.origin.x + ' x ' + sprite.transform.origin.y);
line('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1));
line('wx: ' + sprite.worldView.x + ' wy: ' + sprite.worldView.y + ' ww: ' + sprite.worldView.width.toFixed(1) + ' wh: ' + sprite.worldView.height.toFixed(1) + ' wb: ' + sprite.worldView.bottom + ' wr: ' + sprite.worldView.right);
line('sx: ' + sprite.transform.scale.x.toFixed(1) + ' sy: ' + sprite.transform.scale.y.toFixed(1));
line('tx: ' + sprite.texture.width.toFixed(1) + ' ty: ' + sprite.texture.height.toFixed(1));
line('center x: ' + sprite.transform.center.x + ' y: ' + sprite.transform.center.y);
line('cameraView x: ' + sprite.cameraView.x + ' y: ' + sprite.cameraView.y + ' width: ' + sprite.cameraView.width + ' height: ' + sprite.cameraView.height);
line('inCamera: ' + DebugUtils.game.renderer.spriteRenderer.inCamera(DebugUtils.game.camera, sprite));
Phaser.DebugUtils.start(x, y, color);
Phaser.DebugUtils.line('Sprite: ' + ' (' + sprite.width + ' x ' + sprite.height + ') origin: ' + sprite.transform.origin.x + ' x ' + sprite.transform.origin.y);
Phaser.DebugUtils.line('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1));
Phaser.DebugUtils.line('wx: ' + sprite.worldView.x + ' wy: ' + sprite.worldView.y + ' ww: ' + sprite.worldView.width.toFixed(1) + ' wh: ' + sprite.worldView.height.toFixed(1) + ' wb: ' + sprite.worldView.bottom + ' wr: ' + sprite.worldView.right);
Phaser.DebugUtils.line('sx: ' + sprite.transform.scale.x.toFixed(1) + ' sy: ' + sprite.transform.scale.y.toFixed(1));
Phaser.DebugUtils.line('tx: ' + sprite.texture.width.toFixed(1) + ' ty: ' + sprite.texture.height.toFixed(1));
Phaser.DebugUtils.line('center x: ' + sprite.transform.center.x + ' y: ' + sprite.transform.center.y);
Phaser.DebugUtils.line('cameraView x: ' + sprite.cameraView.x + ' y: ' + sprite.cameraView.y + ' width: ' + sprite.cameraView.width + ' height: ' + sprite.cameraView.height);
Phaser.DebugUtils.line('inCamera: ' + Phaser.DebugUtils.game.renderer.spriteRenderer.inCamera(Phaser.DebugUtils.game.camera, sprite));
}
static renderSpriteBounds(sprite: Sprite, camera: Camera = null, color: string = 'rgba(0,255,0,0.2)') {
static renderSpriteBounds(sprite: Phaser.Sprite, camera: Phaser.Camera = null, color: string = 'rgba(0,255,0,0.2)') {
if (camera == null)
{
camera = DebugUtils.game.camera;
camera = Phaser.DebugUtils.game.camera;
}
var dx = sprite.worldView.x;
var dy = sprite.worldView.y;
DebugUtils.context.fillStyle = color;
DebugUtils.context.fillRect(dx, dy, sprite.width, sprite.height);
Phaser.DebugUtils.context.fillStyle = color;
Phaser.DebugUtils.context.fillRect(dx, dy, sprite.width, sprite.height);
}
static renderPixel(x: number, y: number, fillStyle: string = 'rgba(0,255,0,1)') {
DebugUtils.context.fillStyle = fillStyle;
DebugUtils.context.fillRect(x, y, 1, 1);
Phaser.DebugUtils.context.fillStyle = fillStyle;
Phaser.DebugUtils.context.fillRect(x, y, 1, 1);
}
static renderPoint(point: Phaser.Point, fillStyle: string = 'rgba(0,255,0,1)') {
DebugUtils.context.fillStyle = fillStyle;
DebugUtils.context.fillRect(point.x, point.y, 1, 1);
Phaser.DebugUtils.context.fillStyle = fillStyle;
Phaser.DebugUtils.context.fillRect(point.x, point.y, 1, 1);
}
static renderRectangle(rect: Phaser.Rectangle, fillStyle: string = 'rgba(0,255,0,0.3)') {
DebugUtils.context.fillStyle = fillStyle;
DebugUtils.context.fillRect(rect.x, rect.y, rect.width, rect.height);
Phaser.DebugUtils.context.fillStyle = fillStyle;
Phaser.DebugUtils.context.fillRect(rect.x, rect.y, rect.width, rect.height);
}
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();
Phaser.DebugUtils.context.fillStyle = fillStyle;
Phaser.DebugUtils.context.arc(circle.x, circle.y, circle.radius, 0, Math.PI * 2, false);
Phaser.DebugUtils.context.fill();
}
@@ -294,9 +289,9 @@ module Phaser {
*/
static renderText(text: string, x: number, y: number, color: string = 'rgb(255,255,255)', font: string = '16px Courier') {
DebugUtils.context.font = font;
DebugUtils.context.fillStyle = color;
DebugUtils.context.fillText(text, x, y);
Phaser.DebugUtils.context.font = font;
Phaser.DebugUtils.context.fillStyle = color;
Phaser.DebugUtils.context.fillText(text, x, y);
}
+17 -18
View File
@@ -1,5 +1,4 @@
/// <reference path="../Game.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../_definitions.ts" />
/**
* Phaser - PointUtils
@@ -21,7 +20,7 @@ module Phaser {
* @param {Point} out - Optional Point to store the value in, if not supplied a new Point object will be created.
* @return {Point} The new Point object.
**/
static add(a: Point, b: Point, out: Point = new Point): Point {
static add(a: Phaser.Point, b: Phaser.Point, out: Phaser.Point = new Phaser.Point): Phaser.Point {
return out.setTo(a.x + b.x, a.y + b.y);
}
@@ -33,7 +32,7 @@ module Phaser {
* @param {Point} out - Optional Point to store the value in, if not supplied a new Point object will be created.
* @return {Point} The new Point object.
**/
static subtract(a: Point, b: Point, out: Point = new Point): Point {
static subtract(a: Phaser.Point, b: Phaser.Point, out: Phaser.Point = new Phaser.Point): Phaser.Point {
return out.setTo(a.x - b.x, a.y - b.y);
}
@@ -45,7 +44,7 @@ module Phaser {
* @param {Point} out - Optional Point to store the value in, if not supplied a new Point object will be created.
* @return {Point} The new Point object.
**/
static multiply(a: Point, b: Point, out: Point = new Point): Point {
static multiply(a: Phaser.Point, b: Phaser.Point, out: Phaser.Point = new Phaser.Point): Phaser.Point {
return out.setTo(a.x * b.x, a.y * b.y);
}
@@ -57,7 +56,7 @@ module Phaser {
* @param {Point} out - Optional Point to store the value in, if not supplied a new Point object will be created.
* @return {Point} The new Point object.
**/
static divide(a: Point, b: Point, out: Point = new Point): Point {
static divide(a: Phaser.Point, b: Phaser.Point, out: Phaser.Point = new Phaser.Point): Phaser.Point {
return out.setTo(a.x / b.x, a.y / b.y);
}
@@ -69,10 +68,10 @@ module Phaser {
* @param {number} The maximum value to clamp this Point to
* @return {Point} This Point object.
**/
static clamp(a: Point, min: number, max: number): Point {
static clamp(a: Phaser.Point, min: number, max: number): Phaser.Point {
PointUtils.clampX(a, min, max);
PointUtils.clampY(a, min, max);
Phaser.PointUtils.clampX(a, min, max);
Phaser.PointUtils.clampY(a, min, max);
return a;
}
@@ -85,7 +84,7 @@ module Phaser {
* @param {number} The maximum value to clamp this Point to
* @return {Point} This Point object.
**/
static clampX(a: Point, min: number, max: number): Point {
static clampX(a: Phaser.Point, min: number, max: number): Phaser.Point {
a.x = Math.max(Math.min(a.x, max), min);
return a;
@@ -100,7 +99,7 @@ module Phaser {
* @param {number} The maximum value to clamp this Point to
* @return {Point} This Point object.
**/
static clampY(a: Point, min: number, max: number): Point {
static clampY(a: Phaser.Point, min: number, max: number): Phaser.Point {
a.y = Math.max(Math.min(a.y, max), min);
return a;
@@ -113,7 +112,7 @@ module Phaser {
* @param {Point} output Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned.
* @return {Point} The new Point object.
**/
static clone(a: Point, output: Point = new Point): Point {
static clone(a: Phaser.Point, output: Phaser.Point = new Phaser.Point): Phaser.Point {
return output.setTo(a.x, a.y);
}
@@ -125,7 +124,7 @@ module Phaser {
* @param {Boolean} round - Round the distance to the nearest integer (default false)
* @return {Number} The distance between the two Point objects.
**/
static distanceBetween(a: Point, b: Point, round: boolean = false): number {
static distanceBetween(a: Phaser.Point, b: Phaser.Point, round: boolean = false): number {
var dx = a.x - b.x;
var dy = a.y - b.y;
@@ -148,7 +147,7 @@ module Phaser {
* @param {Point} b - The second Point object.
* @return {Boolean} A value of true if the Points are equal, otherwise false.
**/
static equals(a: Point, b: Point): boolean {
static equals(a: Phaser.Point, b: Phaser.Point): boolean {
return (a.x == b.x && a.y == b.y);
}
@@ -184,11 +183,11 @@ module Phaser {
* @param {Number} distance An optional distance constraint between the Point and the anchor.
* @return The modified point object
*/
static rotate(a: Point, x: number, y: number, angle: number, asDegrees: boolean = false, distance: number = null): Point {
static rotate(a: Phaser.Point, x: number, y: number, angle: number, asDegrees: boolean = false, distance: number = null): Phaser.Point {
if (asDegrees)
{
angle = angle * GameMath.DEG_TO_RAD;
angle = angle * Phaser.GameMath.DEG_TO_RAD;
}
// Get distance from origin (cx/cy) to this point
@@ -212,8 +211,8 @@ module Phaser {
* @param {Number} distance An optional distance constraint between the Point and the anchor.
* @return The modified point object
*/
static rotateAroundPoint(a: Point, b: Point, angle: number, asDegrees: boolean = false, distance: number = null): Point {
return PointUtils.rotate(a, b.x, b.y, angle, asDegrees, distance);
static rotateAroundPoint(a: Phaser.Point, b: Phaser.Point, angle: number, asDegrees: boolean = false, distance: number = null): Phaser.Point {
return Phaser.PointUtils.rotate(a, b.x, b.y, angle, asDegrees, distance);
}
}
+18 -20
View File
@@ -1,6 +1,4 @@
/// <reference path="../Game.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../_definitions.ts" />
/**
* Phaser - RectangleUtils
@@ -21,7 +19,7 @@ module Phaser {
* @param {Point} out - Optional Point to store the value in, if not supplied a new Point object will be created.
* @return {Point} The new Point object.
**/
static getTopLeftAsPoint(a: Rectangle, out: Point = new Point): Point {
static getTopLeftAsPoint(a: Phaser.Rectangle, out: Phaser.Point = new Phaser.Point): Phaser.Point {
return out.setTo(a.x, a.y);
}
@@ -32,7 +30,7 @@ module Phaser {
* @param {Point} out - Optional Point to store the value in, if not supplied a new Point object will be created.
* @return {Point} The new Point object.
**/
static getBottomRightAsPoint(a: Rectangle, out: Point = new Point): Point {
static getBottomRightAsPoint(a: Phaser.Rectangle, out: Phaser.Point = new Phaser.Point): Phaser.Point {
return out.setTo(a.right, a.bottom);
}
@@ -44,7 +42,7 @@ module Phaser {
* @param {Number} dy The amount to be added to the bottom side of the Rectangle.
* @return {Rectangle} This Rectangle object.
**/
static inflate(a: Rectangle, dx: number, dy: number): Rectangle {
static inflate(a: Phaser.Rectangle, dx: number, dy: number): Phaser.Rectangle {
a.x -= dx;
a.width += 2 * dx;
@@ -63,8 +61,8 @@ module Phaser {
* @param {Point} point The x property of this Point object is used to increase the horizontal dimension of the Rectangle object. The y property is used to increase the vertical dimension of the Rectangle object.
* @return {Rectangle} The Rectangle object.
**/
static inflatePoint(a: Rectangle, point: Point): Rectangle {
return RectangleUtils.inflate(a, point.x, point.y);
static inflatePoint(a: Phaser.Rectangle, point: Phaser.Point): Phaser.Rectangle {
return Phaser.RectangleUtils.inflate(a, point.x, point.y);
}
/**
@@ -74,7 +72,7 @@ module Phaser {
* @param {Point} output Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned.
* @return {Point} The size of the Rectangle object
**/
static size(a: Rectangle, output: Point = new Point): Point {
static size(a: Phaser.Rectangle, output: Phaser.Point = new Phaser.Point): Phaser.Point {
return output.setTo(a.width, a.height);
}
@@ -85,7 +83,7 @@ module Phaser {
* @param {Rectangle} output Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned.
* @return {Rectangle}
**/
static clone(a: Rectangle, output: Rectangle = new Rectangle): Rectangle {
static clone(a: Phaser.Rectangle, output: Phaser.Rectangle = new Phaser.Rectangle): Phaser.Rectangle {
return output.setTo(a.x, a.y, a.width, a.height);
}
@@ -97,7 +95,7 @@ module Phaser {
* @param {Number} y The y coordinate of the point to test.
* @return {Boolean} A value of true if the Rectangle object contains the specified point; otherwise false.
**/
static contains(a: Rectangle, x: number, y: number): boolean {
static contains(a: Phaser.Rectangle, x: number, y: number): boolean {
return (x >= a.x && x <= a.right && y >= a.y && y <= a.bottom);
}
@@ -108,8 +106,8 @@ module Phaser {
* @param {Point} point The point object being checked. Can be Point or any object with .x and .y values.
* @return {Boolean} A value of true if the Rectangle object contains the specified point; otherwise false.
**/
static containsPoint(a: Rectangle, point: Point): boolean {
return RectangleUtils.contains(a, point.x, point.y);
static containsPoint(a: Phaser.Rectangle, point: Phaser.Point): boolean {
return Phaser.RectangleUtils.contains(a, point.x, point.y);
}
/**
@@ -120,7 +118,7 @@ module Phaser {
* @param {Rectangle} b - The second Rectangle object.
* @return {Boolean} A value of true if the Rectangle object contains the specified point; otherwise false.
**/
static containsRect(a: Rectangle, b: Rectangle): boolean {
static containsRect(a: Phaser.Rectangle, b: Phaser.Rectangle): boolean {
// If the given rect has a larger volume than this one then it can never contain it
if (a.volume > b.volume)
@@ -140,7 +138,7 @@ module Phaser {
* @param {Rectangle} b - The second Rectangle object.
* @return {Boolean} A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false.
**/
static equals(a: Rectangle, b: Rectangle): boolean {
static equals(a: Phaser.Rectangle, b: Phaser.Rectangle): boolean {
return (a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height);
}
@@ -152,9 +150,9 @@ module Phaser {
* @param {Rectangle} output Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
* @return {Rectangle} A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0.
**/
static intersection(a: Rectangle, b: Rectangle, out: Rectangle = new Rectangle): Rectangle {
static intersection(a: Phaser.Rectangle, b: Phaser.Rectangle, out: Phaser.Rectangle = new Phaser.Rectangle): Phaser.Rectangle {
if (RectangleUtils.intersects(a, b))
if (Phaser.RectangleUtils.intersects(a, b))
{
out.x = Math.max(a.x, b.x);
out.y = Math.max(a.y, b.y);
@@ -175,7 +173,7 @@ module Phaser {
* @param {Number} tolerance A tolerance value to allow for an intersection test with padding, default to 0
* @return {Boolean} A value of true if the specified object intersects with this Rectangle object; otherwise false.
**/
static intersects(a: Rectangle, b: Rectangle, tolerance: number = 0): boolean {
static intersects(a: Phaser.Rectangle, b: Phaser.Rectangle, tolerance: number = 0): boolean {
return !(a.left > b.right + tolerance || a.right < b.left - tolerance || a.top > b.bottom + tolerance || a.bottom < b.top - tolerance);
}
@@ -189,7 +187,7 @@ module Phaser {
* @param {Number} tolerance A tolerance value to allow for an intersection test with padding, default to 0
* @return {Boolean} A value of true if the specified object intersects with the Rectangle; otherwise false.
**/
static intersectsRaw(a: Rectangle, left: number, right: number, top: number, bottom: number, tolerance: number = 0): boolean {
static intersectsRaw(a: Phaser.Rectangle, left: number, right: number, top: number, bottom: number, tolerance: number = 0): boolean {
return !(left > a.right + tolerance || right < a.left - tolerance || top > a.bottom + tolerance || bottom < a.top - tolerance);
}
@@ -201,7 +199,7 @@ module Phaser {
* @param {Rectangle} output Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
* @return {Rectangle} A Rectangle object that is the union of the two Rectangles.
**/
static union(a: Rectangle, b: Rectangle, out: Rectangle = new Rectangle): Rectangle {
static union(a: Phaser.Rectangle, b: Phaser.Rectangle, out: Phaser.Rectangle = new Phaser.Rectangle): Phaser.Rectangle {
return out.setTo(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.right, b.right), Math.max(a.bottom, b.bottom));
}
+24 -29
View File
@@ -1,9 +1,4 @@
/// <reference path="../Game.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../geom/Circle.ts" />
/// <reference path="../gameobjects/Sprite.ts" />
/// <reference path="RectangleUtils.ts" />
/// <reference path="../_definitions.ts" />
/**
* Phaser - SpriteUtils
@@ -15,7 +10,7 @@ module Phaser {
export class SpriteUtils {
static _tempPoint: Point;
static _tempPoint: Phaser.Point;
static _sin: number;
static _cos: number;
@@ -25,7 +20,7 @@ module Phaser {
* @param sprite {Sprite} The Sprite that will have its cameraView property modified
* @return {Rectangle} A reference to the Sprite.cameraView property
*/
static updateCameraView(camera: Camera, sprite: Sprite): Rectangle {
static updateCameraView(camera: Phaser.Camera, sprite: Phaser.Sprite): Phaser.Rectangle {
if (sprite.rotation == 0 || sprite.texture.renderRotation == false)
{
@@ -40,21 +35,21 @@ module Phaser {
// If the sprite is rotated around its center we can use this quicker method:
if (sprite.transform.origin.x == 0.5 && sprite.transform.origin.y == 0.5)
{
SpriteUtils._sin = sprite.transform.sin;
SpriteUtils._cos = sprite.transform.cos;
Phaser.SpriteUtils._sin = sprite.transform.sin;
Phaser.SpriteUtils._cos = sprite.transform.cos;
if (SpriteUtils._sin < 0)
if (Phaser.SpriteUtils._sin < 0)
{
SpriteUtils._sin = -SpriteUtils._sin;
Phaser.SpriteUtils._sin = -Phaser.SpriteUtils._sin;
}
if (SpriteUtils._cos < 0)
if (Phaser.SpriteUtils._cos < 0)
{
SpriteUtils._cos = -SpriteUtils._cos;
Phaser.SpriteUtils._cos = -Phaser.SpriteUtils._cos;
}
sprite.cameraView.width = Math.round(sprite.height * SpriteUtils._sin + sprite.width * SpriteUtils._cos);
sprite.cameraView.height = Math.round(sprite.height * SpriteUtils._cos + sprite.width * SpriteUtils._sin);
sprite.cameraView.width = Math.round(sprite.height * Phaser.SpriteUtils._sin + sprite.width * Phaser.SpriteUtils._cos);
sprite.cameraView.height = Math.round(sprite.height * Phaser.SpriteUtils._cos + sprite.width * Phaser.SpriteUtils._sin);
sprite.cameraView.x = Math.round(sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x) - (sprite.cameraView.width * sprite.transform.origin.x));
sprite.cameraView.y = Math.round(sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y) - (sprite.cameraView.height * sprite.transform.origin.y));
}
@@ -71,21 +66,21 @@ module Phaser {
}
static getAsPoints(sprite: Sprite): Phaser.Point[] {
static getAsPoints(sprite: Phaser.Sprite): Phaser.Point[] {
var out: Phaser.Point[] = [];
// top left
out.push(new Point(sprite.x, sprite.y));
out.push(new Phaser.Point(sprite.x, sprite.y));
// top right
out.push(new Point(sprite.x + sprite.width, sprite.y));
out.push(new Phaser.Point(sprite.x + sprite.width, sprite.y));
// bottom right
out.push(new Point(sprite.x + sprite.width, sprite.y + sprite.height));
out.push(new Phaser.Point(sprite.x + sprite.width, sprite.y + sprite.height));
// bottom left
out.push(new Point(sprite.x, sprite.y + sprite.height));
out.push(new Phaser.Point(sprite.x, sprite.y + sprite.height));
return out;
@@ -195,8 +190,8 @@ module Phaser {
*
* @return Whether or not the point overlaps this object.
*/
static overlapsPoint(sprite: Sprite, point: Point): boolean {
return SpriteUtils.overlapsXY(sprite, point.x, point.y);
static overlapsPoint(sprite: Phaser.Sprite, point: Phaser.Point): boolean {
return Phaser.SpriteUtils.overlapsXY(sprite, point.x, point.y);
}
/**
@@ -206,16 +201,16 @@ module Phaser {
*
* @return {boolean} Whether the object is on screen or not.
*/
static onScreen(sprite: Sprite, camera: Camera = null): boolean {
static onScreen(sprite: Phaser.Sprite, camera: Phaser.Camera = null): boolean {
if (camera == null)
{
camera = sprite.game.camera;
}
SpriteUtils.getScreenXY(sprite, SpriteUtils._tempPoint, camera);
Phaser.SpriteUtils.getScreenXY(sprite, SpriteUtils._tempPoint, camera);
return (SpriteUtils._tempPoint.x + sprite.width > 0) && (SpriteUtils._tempPoint.x < camera.width) && (SpriteUtils._tempPoint.y + sprite.height > 0) && (SpriteUtils._tempPoint.y < camera.height);
return (Phaser.SpriteUtils._tempPoint.x + sprite.width > 0) && (Phaser.SpriteUtils._tempPoint.x < camera.width) && (Phaser.SpriteUtils._tempPoint.y + sprite.height > 0) && (Phaser.SpriteUtils._tempPoint.y < camera.height);
}
@@ -227,7 +222,7 @@ module Phaser {
*
* @return {Point} The <code>Point</code> you passed in, or a new <code>Point</code> if you didn't pass one, containing the screen X and Y position of this object.
*/
static getScreenXY(sprite: Sprite, point: Point = null, camera: Camera = null): Point {
static getScreenXY(sprite: Phaser.Sprite, point: Phaser.Point = null, camera: Phaser.Camera = null): Phaser.Point {
if (point == null)
{
@@ -236,7 +231,7 @@ module Phaser {
if (camera == null)
{
camera = this.game.camera;
camera = sprite.game.camera;
}
point.x = sprite.x - camera.x * sprite.transform.scrollFactor.x;
@@ -269,7 +264,7 @@ module Phaser {
* @param x {number} The new X position of this object.
* @param y {number} The new Y position of this object.
*/
static reset(sprite: Sprite, x: number, y: number) {
static reset(sprite: Phaser.Sprite, x: number, y: number) {
sprite.revive();
//sprite.body.touching = Types.NONE;