diff --git a/Docs/logo/phaser vector final.eps b/Docs/logo/phaser vector final.eps new file mode 100644 index 00000000..1b05d5a1 Binary files /dev/null and b/Docs/logo/phaser vector final.eps differ diff --git a/Docs/logo/phaser vector final.fla b/Docs/logo/phaser vector final.fla new file mode 100644 index 00000000..490f11d8 Binary files /dev/null and b/Docs/logo/phaser vector final.fla differ diff --git a/Docs/logo/phaser vector final.png b/Docs/logo/phaser vector final.png new file mode 100644 index 00000000..11668258 Binary files /dev/null and b/Docs/logo/phaser vector final.png differ diff --git a/Phaser/Phaser.csproj b/Phaser/Phaser.csproj index 2772b307..d627d288 100644 --- a/Phaser/Phaser.csproj +++ b/Phaser/Phaser.csproj @@ -135,6 +135,10 @@ + + + CollisionMask.ts + Gestures.ts diff --git a/Phaser/gameobjects/GeomSprite.ts b/Phaser/gameobjects/GeomSprite.ts index 254be89b..d33c44ad 100644 --- a/Phaser/gameobjects/GeomSprite.ts +++ b/Phaser/gameobjects/GeomSprite.ts @@ -228,9 +228,10 @@ module Phaser { } /** - * Create a circle shape with specific diameter. - * @param diameter {number} Diameter of the circle. - * @return {GeomSprite} GeomSprite instance itself. + * Create a rectangle shape of the given width and height size + * @param width {Number} Width of the rectangle + * @param height {Number} Height of the rectangle + * @return {GeomSprite} GeomSprite instance. */ createRectangle(width: number, height: number): GeomSprite { diff --git a/Phaser/geom/Quad.ts b/Phaser/geom/Quad.ts index e1bb7b85..7aec112d 100644 --- a/Phaser/geom/Quad.ts +++ b/Phaser/geom/Quad.ts @@ -90,6 +90,30 @@ module Phaser { } + /** + * Copies the x/y/width/height values from the source object into this Quad + * @method copyFrom + * @param {Any} source The source object to copy from. Can be a Quad, Rectangle or any object with exposed x/y/width/height properties + * @return {Quad} This object + **/ + public copyFrom(source): Quad { + + return this.setTo(source.x, source.y, source.width, source.height); + + } + + /** + * Copies the x/y/width/height values from this Quad into the given target object + * @method copyTo + * @param {Any} target The object to copy this quads values in to. Can be a Quad, Rectangle or any object with exposed x/y/width/height properties + * @return {Any} The target object + **/ + public copyTo(target): any { + + return target.copyFrom(this); + + } + /** * Returns a string representation of this object. * @method toString diff --git a/Phaser/system/CollisionMask.ts b/Phaser/system/CollisionMask.ts new file mode 100644 index 00000000..ecf8e00d --- /dev/null +++ b/Phaser/system/CollisionMask.ts @@ -0,0 +1,157 @@ +/// + +/** +* Phaser - CollisionMask +*/ + +module Phaser { + + export class CollisionMask { + + /** + * CollisionMask constructor. Creates a new CollisionMask for the given GameObject. + * + * @param game {Phaser.Game} Current game instance. + * @param parent {Phaser.GameObject} The GameObject this CollisionMask belongs to. + * @param x {number} The initial x position of the CollisionMask. + * @param y {number} The initial y position of the CollisionMask. + * @param width {number} The width of the CollisionMask. + * @param height {number} The height of the CollisionMask. + */ + constructor(game: Game, parent: GameObject, x: number, y: number, width: number, height: number) { + + this._game = game; + this._parent = parent; + + // By default the CollisionMask is a quad + this.type = CollisionMask.QUAD; + + this.quad = new Phaser.Quad(this._parent.x, this._parent.y, this._parent.width, this._parent.height); + this.offset = new MicroPoint(0, 0); + + return this; + + } + + private _game; + private _parent; + + /** + * Geom type of this sprite. (available: UNASSIGNED, CIRCLE, LINE, POINT, RECTANGLE) + * @type {number} + */ + public type: number = 0; + + /** + * Quad (a smaller version of Rectangle). + * @type {number} + */ + public static QUAD: number = 0; + + /** + * Point. + * @type {number} + */ + public static POINT: number = 1; + + /** + * Circle. + * @type {number} + */ + public static CIRCLE: number = 2; + + /** + * Line. + * @type {number} + */ + public static LINE: number = 3; + + /** + * Rectangle. + * @type {number} + */ + public static RECTANGLE: number = 4; + + /** + * Polygon. + * @type {number} + */ + public static POLYGON: number = 5; + + /** + * Rectangle shape container. A Rectangle instance. + * @type {Rectangle} + */ + public quad: Quad; + + /** + * Point shape container. A Point instance. + * @type {Point} + */ + public point: Point; + + /** + * Circle shape container. A Circle instance. + * @type {Circle} + */ + public circle: Circle; + + /** + * Line shape container. A Line instance. + * @type {Line} + */ + public line: Line; + + /** + * Rectangle shape container. A Rectangle instance. + * @type {Rectangle} + */ + public rect: Rectangle; + + /** + * A value from the top-left of the GameObject frame that this collisionMask is offset to. + * If the CollisionMask is a Quad/Rectangle the offset relates to the top-left of that Quad. + * If the CollisionMask is a Circle the offset relates to the center of the circle. + * @type {MicroPoint} + */ + public offset: MicroPoint; + + + + public update() { + + } + + + + + + + + + + + + + /** + * Destroy all objects and references belonging to this CollisionMask + */ + public destroy() { + + this._game = null; + this._parent = null; + this.quad = null; + this.point = null; + this.circle = null; + this.rect = null; + this.line = null; + this.offset = null; + + } + + + + + } + +} \ No newline at end of file diff --git a/README.md b/README.md index 8a47ac37..48d23814 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ V0.9.6 * Added Sprite.cacheKey which stores the key of the item from the cache that was used for its texture (if any) * Added GameMath.shuffleArray * Updated Animation.frame to return the index of the currentFrame if set +* Added Quad.copyTo and Quad.copyFrom @@ -88,6 +89,10 @@ V0.9.6 * TODO: Investigate bug re: tilemap collision and animation frames * TODO: Update tests that use arrow keys and include touch/mouse support * TODO: GameObject.clipRect +* TODO: Use CollisionMask in Input instead of Circle? +* TODO: Polygon geom primitive +* TODO: Move GameObject transforms to a single matrix + Requirements diff --git a/Tests/misc/starfield.js b/Tests/misc/starfield.js index 29ab6c22..7a98871c 100644 --- a/Tests/misc/starfield.js +++ b/Tests/misc/starfield.js @@ -25,8 +25,10 @@ } xxx = (xx[i]) / (zz[i]); yyy = (yy[i]) / (zz[i])--; - var x = xxx + myGame.input.x; - var y = yyy + myGame.input.y; + //var x: number = xxx + myGame.input.x; + //var y: number = yyy + myGame.input.y; + var x = xxx + 400; + var y = yyy + 300; var c = '#ffffff'; if(zz[i] > 80) { c = '#666666'; @@ -35,7 +37,6 @@ } else if(zz[i] > 40) { c = '#aaaaaa'; } - //else if (zz[i] > 20) c = '#ffffff'; starfield.setPixel(x, y, c); } } diff --git a/build/phaser.d.ts b/build/phaser.d.ts index 7509c8e3..3b2e67bf 100644 --- a/build/phaser.d.ts +++ b/build/phaser.d.ts @@ -1519,8 +1519,9 @@ module Phaser { * @param frameRate {number} The speed in frames per second that the animation should play at (e.g. 60 fps). * @param loop {boolean} Whether or not the animation is looped or just plays once. * @param useNumericIndex {boolean} Use number indexes instead of string indexes? + * @return {Animation} The Animation that was created */ - public add(name: string, frames?: any[], frameRate?: number, loop?: bool, useNumericIndex?: bool): void; + public add(name: string, frames?: any[], frameRate?: number, loop?: bool, useNumericIndex?: bool): Animation; /** * Check whether the frames is valid. * @param frames {any[]} Frames to be validated. @@ -8688,6 +8689,20 @@ module Phaser { public destroy(): void; } } +interface IPoint { + getDist(): number; +} +module Shapes { + class Point implements IPoint { + public x: number; + public y: number; + constructor(x: number, y: number); + public getDist(): number; + static origin: Point; + } +} +var p: IPoint; +var dist: number; /** * Phaser - State * diff --git a/build/phaser.js b/build/phaser.js index 1d6178c2..33bcea67 100644 --- a/build/phaser.js +++ b/build/phaser.js @@ -1837,7 +1837,11 @@ var Phaser; }); Object.defineProperty(Animation.prototype, "frame", { get: function () { - return this._frameIndex; + if(this.currentFrame !== null) { + return this.currentFrame.index; + } else { + return this._frameIndex; + } }, set: function (value) { this.currentFrame = this._frameData.getFrame(value); @@ -2257,6 +2261,7 @@ var Phaser; * @param frameRate {number} The speed in frames per second that the animation should play at (e.g. 60 fps). * @param loop {boolean} Whether or not the animation is looped or just plays once. * @param useNumericIndex {boolean} Use number indexes instead of string indexes? + * @return {Animation} The Animation that was created */ function (name, frames, frameRate, loop, useNumericIndex) { if (typeof frames === "undefined") { frames = null; } @@ -2280,6 +2285,7 @@ var Phaser; this._anims[name] = new Phaser.Animation(this._game, this._parent, this._frameData, name, frames, frameRate, loop); this.currentAnim = this._anims[name]; this.currentFrame = this.currentAnim.currentFrame; + return this._anims[name]; }; AnimationManager.prototype.validateFrames = /** * Check whether the frames is valid. @@ -15035,6 +15041,28 @@ var Phaser; })(); Phaser.FXManager = FXManager; })(Phaser || (Phaser = {})); +// Module +var Shapes; +(function (Shapes) { + // Class + var Point = (function () { + // Constructor + function Point(x, y) { + this.x = x; + this.y = y; + } + Point.prototype.getDist = // Instance member + function () { + return Math.sqrt(this.x * this.x + this.y * this.y); + }; + Point.origin = new Point(0, 0); + return Point; + })(); + Shapes.Point = Point; +})(Shapes || (Shapes = {})); +// Local variables +var p = new Shapes.Point(3, 4); +var dist = p.getDist(); /// /** * Phaser - State