mirror of
https://github.com/wassname/phaser.git
synced 2026-08-04 13:14:14 +08:00
Preparing new tests
This commit is contained in:
+8
-24
@@ -92,6 +92,10 @@
|
||||
<DependentUpon>Game.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="gameobjects\Sprite.ts" />
|
||||
<TypeScriptCompile Include="gameobjects\IGameObject.ts" />
|
||||
<Content Include="gameobjects\IGameObject.js">
|
||||
<DependentUpon>IGameObject.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="math\GameMath.js">
|
||||
<DependentUpon>GameMath.ts</DependentUpon>
|
||||
</Content>
|
||||
@@ -99,14 +103,9 @@
|
||||
<Content Include="gameobjects\GameObjectFactory.js">
|
||||
<DependentUpon>GameObjectFactory.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="components\ScrollRegion.ts" />
|
||||
<Content Include="components\ScrollRegion.js">
|
||||
<DependentUpon>ScrollRegion.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="gameobjects\Sprite.js">
|
||||
<DependentUpon>Sprite.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="geom\Polygon.ts" />
|
||||
<TypeScriptCompile Include="utils\PointUtils.ts" />
|
||||
<TypeScriptCompile Include="utils\CircleUtils.ts" />
|
||||
<TypeScriptCompile Include="renderers\CanvasRenderer.ts" />
|
||||
@@ -131,24 +130,17 @@
|
||||
<Content Include="utils\PointUtils.js">
|
||||
<DependentUpon>PointUtils.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="geom\Polygon.js">
|
||||
<DependentUpon>Polygon.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="geom\Response.ts" />
|
||||
<TypeScriptCompile Include="utils\RectangleUtils.ts" />
|
||||
<Content Include="utils\RectangleUtils.js">
|
||||
<DependentUpon>RectangleUtils.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="geom\Response.js">
|
||||
<DependentUpon>Response.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="core\Circle.js">
|
||||
<DependentUpon>Circle.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="geom\IntersectResult.js">
|
||||
<Content Include="math\IntersectResult.js">
|
||||
<DependentUpon>IntersectResult.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="geom\Line.js">
|
||||
<Content Include="core\Line.js">
|
||||
<DependentUpon>Line.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="math\Vec2Utils.ts" />
|
||||
@@ -216,18 +208,10 @@
|
||||
<Content Include="system\StageScaleMode.js">
|
||||
<DependentUpon>StageScaleMode.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="components\Tile.js">
|
||||
<DependentUpon>Tile.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="components\TilemapLayer.ts" />
|
||||
<Content Include="components\TilemapLayer.js">
|
||||
<DependentUpon>TilemapLayer.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="tweens\Tween.js">
|
||||
<DependentUpon>Tween.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="tweens\Tween.ts" />
|
||||
<TypeScriptCompile Include="components\Tile.ts" />
|
||||
<TypeScriptCompile Include="system\StageScaleMode.ts" />
|
||||
<TypeScriptCompile Include="system\RequestAnimationFrame.ts" />
|
||||
<TypeScriptCompile Include="math\RandomDataGenerator.ts" />
|
||||
@@ -299,8 +283,8 @@
|
||||
<TypeScriptCompile Include="components\animation\Frame.ts" />
|
||||
<TypeScriptCompile Include="loader\AnimationLoader.ts" />
|
||||
<TypeScriptCompile Include="components\animation\Animation.ts" />
|
||||
<TypeScriptCompile Include="geom\Line.ts" />
|
||||
<TypeScriptCompile Include="geom\IntersectResult.ts" />
|
||||
<TypeScriptCompile Include="core\Line.ts" />
|
||||
<TypeScriptCompile Include="math\IntersectResult.ts" />
|
||||
<TypeScriptCompile Include="core\Circle.ts" />
|
||||
<Content Include="core\Group.js">
|
||||
<DependentUpon>Group.ts</DependentUpon>
|
||||
|
||||
+7
-7
@@ -21,11 +21,11 @@ module Phaser {
|
||||
this.add = game.add;
|
||||
this.camera = game.camera;
|
||||
this.cache = game.cache;
|
||||
this.collision = game.collision;
|
||||
//this.collision = game.collision;
|
||||
this.input = game.input;
|
||||
this.loader = game.loader;
|
||||
this.math = game.math;
|
||||
this.motion = game.motion;
|
||||
//this.motion = game.motion;
|
||||
this.sound = game.sound;
|
||||
this.stage = game.stage;
|
||||
this.time = game.time;
|
||||
@@ -55,7 +55,7 @@ module Phaser {
|
||||
* Reference to the collision helper.
|
||||
* @type {Collision}
|
||||
*/
|
||||
public collision: Collision;
|
||||
//public collision: Collision;
|
||||
|
||||
/**
|
||||
* Reference to the GameObject Factory.
|
||||
@@ -85,7 +85,7 @@ module Phaser {
|
||||
* Reference to the motion helper.
|
||||
* @type {Motion}
|
||||
*/
|
||||
public motion: Motion;
|
||||
//public motion: Motion;
|
||||
|
||||
/**
|
||||
* Reference to the sound manager.
|
||||
@@ -161,9 +161,9 @@ module Phaser {
|
||||
* @param context The context in which the callbacks will be called
|
||||
* @returns {boolean} true if the objects overlap, otherwise false.
|
||||
*/
|
||||
public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.game.callbackContext): bool {
|
||||
return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context);
|
||||
}
|
||||
//public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.game.callbackContext): bool {
|
||||
// return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../gameobjects/Tilemap.ts" />
|
||||
/// <reference path="../gameobjects/IGameObject.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - TilemapLayer
|
||||
@@ -354,7 +356,7 @@ module Phaser {
|
||||
* @param object {GameObject} Tiles you want to get that overlaps this.
|
||||
* @return {array} Array with tiles informations. (Each contains x, y and the tile.)
|
||||
*/
|
||||
public getTileOverlaps(object: GameObject) {
|
||||
public getTileOverlaps(object: IGameObject) {
|
||||
|
||||
// If the object is outside of the world coordinates then abort the check (tilemap has to exist within world bounds)
|
||||
if (object.collisionMask.x < 0 || object.collisionMask.x > this.widthInPixels || object.collisionMask.y < 0 || object.collisionMask.bottom > this.heightInPixels)
|
||||
|
||||
@@ -14,6 +14,7 @@ module Phaser.Components {
|
||||
|
||||
constructor(parent: Sprite, key?: string = '', canvas?: HTMLCanvasElement = null, context?: CanvasRenderingContext2D = null) {
|
||||
|
||||
this._game = parent.game;
|
||||
this._sprite = parent;
|
||||
|
||||
this.canvas = canvas;
|
||||
@@ -30,6 +31,11 @@ module Phaser.Components {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private _game: Game;
|
||||
|
||||
/**
|
||||
* Reference to the Image stored in the Game.Cache that is used as the texture for the Sprite.
|
||||
*/
|
||||
@@ -121,8 +127,32 @@ module Phaser.Components {
|
||||
* @param clearAnimations {boolean} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this boolean
|
||||
* @return {Sprite} Sprite instance itself.
|
||||
*/
|
||||
public loadImage(key: string, clearAnimations: bool = true): Sprite {
|
||||
return Phaser.SpriteUtils.loadTexture(this._sprite, key, clearAnimations);
|
||||
public loadImage(key: string, clearAnimations: bool = true) {
|
||||
|
||||
//if (clearAnimations && sprite.animations.frameData !== null)
|
||||
//{
|
||||
// sprite.animations.destroy();
|
||||
//}
|
||||
|
||||
if (this._game.cache.getImage(key) !== null)
|
||||
{
|
||||
this.setTo(this._game.cache.getImage(key), null);
|
||||
|
||||
if (this._game.cache.isSpriteSheet(key))
|
||||
{
|
||||
//sprite.animations.loadFrameData(sprite._game.cache.getFrameData(key));
|
||||
//sprite.collisionMask.width = sprite.animations.currentFrame.width;
|
||||
//sprite.collisionMask.height = sprite.animations.currentFrame.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._sprite.frameBounds.width = this.width;
|
||||
this._sprite.frameBounds.height = this.height;
|
||||
//sprite.collisionMask.width = sprite._texture.width;
|
||||
//sprite.collisionMask.height = sprite._texture.height;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,8 +160,17 @@ module Phaser.Components {
|
||||
* @param texture {DynamicTexture} The texture object to be used by this sprite.
|
||||
* @return {Sprite} Sprite instance itself.
|
||||
*/
|
||||
public loadDynamicTexture(texture: DynamicTexture): Sprite {
|
||||
return Phaser.SpriteUtils.loadDynamicTexture(this._sprite, texture);
|
||||
public loadDynamicTexture(texture: DynamicTexture) {
|
||||
|
||||
//if (sprite.animations.frameData !== null)
|
||||
//{
|
||||
// sprite.animations.destroy();
|
||||
//}
|
||||
|
||||
this.setTo(null, texture);
|
||||
this._sprite.frameBounds.width = this.width;
|
||||
this._sprite.frameBounds.height = this.height;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../utils/RectangleUtils.ts" />
|
||||
/// <reference path="IGameObject.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - DynamicTexture
|
||||
@@ -234,7 +236,7 @@ module Phaser {
|
||||
public copyPixels(sourceTexture: DynamicTexture, sourceRect: Rectangle, destPoint: Point) {
|
||||
|
||||
// Swap for drawImage if the sourceRect is the same size as the sourceTexture to avoid a costly getImageData call
|
||||
if (sourceRect.equals(this.bounds) == true)
|
||||
if (Phaser.RectangleUtils.equals(sourceRect, this.bounds) == true)
|
||||
{
|
||||
this.context.drawImage(sourceTexture.canvas, destPoint.x, destPoint.y);
|
||||
}
|
||||
@@ -246,15 +248,15 @@ module Phaser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array of GameObjects it will update each of them so that their canvas/contexts reference this DynamicTexture
|
||||
* Given an array of Sprites it will update each of them so that their canvas/contexts reference this DynamicTexture
|
||||
* @param objects {Array} An array of GameObjects, or objects that inherit from it such as Sprites
|
||||
*/
|
||||
public assignCanvasToGameObjects(objects: GameObject[]) {
|
||||
public assignCanvasToGameObjects(objects: IGameObject[]) {
|
||||
|
||||
for (var i = 0; i < objects.length; i++)
|
||||
{
|
||||
objects[i].canvas = this.canvas;
|
||||
objects[i].context = this.context;
|
||||
objects[i].texture.canvas = this.canvas;
|
||||
objects[i].texture.context = this.context;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -275,9 +277,7 @@ module Phaser {
|
||||
* @param y {number} The Y coordinate to render on the stage to (given in screen coordinates, not world)
|
||||
*/
|
||||
public render(x?: number = 0, y?: number = 0) {
|
||||
|
||||
this.game.stage.context.drawImage(this.canvas, x, y);
|
||||
|
||||
}
|
||||
|
||||
public get width(): number {
|
||||
|
||||
@@ -135,9 +135,9 @@ module Phaser {
|
||||
* @param [tileHeight] {number} height of each tile.
|
||||
* @return {Tilemap} The newly created tilemap object.
|
||||
*/
|
||||
public tilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
|
||||
return <Tilemap> this._world.group.add(new Tilemap(this._game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
|
||||
}
|
||||
//public tilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
|
||||
// return <Tilemap> this._world.group.add(new Tilemap(this._game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
|
||||
//}
|
||||
|
||||
/**
|
||||
* Create a tween object for a specific object.
|
||||
@@ -200,9 +200,9 @@ module Phaser {
|
||||
* @param tilemap The Tilemap to add to the Game World
|
||||
* @return {Phaser.Tilemap} The Tilemap object
|
||||
*/
|
||||
public existingTilemap(tilemap: Tilemap): Tilemap {
|
||||
return this._world.group.add(tilemap);
|
||||
}
|
||||
//public existingTilemap(tilemap: Tilemap): Tilemap {
|
||||
// return this._world.group.add(tilemap);
|
||||
//}
|
||||
|
||||
/**
|
||||
* Add an existing Tween to the current world.
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
|
||||
module Phaser {
|
||||
|
||||
export interface IGameObject {
|
||||
|
||||
/**
|
||||
* Reference to the main game object
|
||||
*/
|
||||
game: Game;
|
||||
|
||||
/**
|
||||
* The type of game object.
|
||||
*/
|
||||
type: number;
|
||||
|
||||
/**
|
||||
* Reference to the Renderer.renderSprite method. Can be overriden by custom classes.
|
||||
*/
|
||||
render;
|
||||
|
||||
/**
|
||||
* Controls if both <code>update</code> and render are called by the core game loop.
|
||||
*/
|
||||
exists: bool;
|
||||
|
||||
/**
|
||||
* Controls if <code>update()</code> is automatically called by the core game loop.
|
||||
*/
|
||||
active: bool;
|
||||
|
||||
/**
|
||||
* Controls if this Sprite is rendered or skipped during the core game loop.
|
||||
*/
|
||||
visible: bool;
|
||||
|
||||
/**
|
||||
* The position of the Sprite in world and screen coordinates.
|
||||
*/
|
||||
position: Phaser.Components.Position;
|
||||
|
||||
/**
|
||||
* The texture used to render the Sprite.
|
||||
*/
|
||||
texture: Phaser.Components.Texture;
|
||||
|
||||
/**
|
||||
* Scale of the Sprite. A scale of 1.0 is the original size. 0.5 half size. 2.0 double sized.
|
||||
*/
|
||||
scale: Phaser.Vec2;
|
||||
|
||||
/**
|
||||
* The influence of camera movement upon the Sprite.
|
||||
*/
|
||||
scrollFactor: Phaser.Vec2;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Sprite {
|
||||
export class Sprite implements IGameObject {
|
||||
|
||||
/**
|
||||
* Create a new <code>Sprite</code>.
|
||||
@@ -34,12 +34,18 @@ module Phaser {
|
||||
this.visible = true;
|
||||
this.alive = true;
|
||||
|
||||
this.frameBounds = new Rectangle(x, y, width, height);
|
||||
this.origin = new Phaser.Vec2(0, 0);
|
||||
this.scrollFactor = new Phaser.Vec2(1, 1);
|
||||
this.scale = new Phaser.Vec2(1, 1);
|
||||
|
||||
this.position = new Phaser.Components.Position(this, x, y);
|
||||
this.texture = new Phaser.Components.Texture(this, key, game.stage.canvas, game.stage.context);
|
||||
|
||||
this.width = this.frameBounds.width;
|
||||
this.height = this.frameBounds.height;
|
||||
this.rotation = this.position.rotation;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,6 +83,10 @@ module Phaser {
|
||||
*/
|
||||
public alive: bool;
|
||||
|
||||
// Getters only, don't over-write these values
|
||||
public width: number;
|
||||
public height: number;
|
||||
|
||||
/**
|
||||
* The position of the Sprite in world and screen coordinates.
|
||||
*/
|
||||
@@ -94,9 +104,102 @@ module Phaser {
|
||||
*/
|
||||
public frameBounds: Phaser.Rectangle;
|
||||
|
||||
/**
|
||||
* Scale of the Sprite. A scale of 1.0 is the original size. 0.5 half size. 2.0 double sized.
|
||||
*/
|
||||
public scale: Phaser.Vec2;
|
||||
|
||||
/**
|
||||
* The influence of camera movement upon the Sprite.
|
||||
*/
|
||||
public scrollFactor: Phaser.Vec2;
|
||||
|
||||
/**
|
||||
* The Sprite origin is the point around which scale and rotation transforms take place.
|
||||
*/
|
||||
public origin: Phaser.Vec2;
|
||||
|
||||
/**
|
||||
* Pre-update is called right before update() on each object in the game loop.
|
||||
*/
|
||||
public preUpdate() {
|
||||
|
||||
//this.last.x = this.frameBounds.x;
|
||||
//this.last.y = this.frameBounds.y;
|
||||
|
||||
//this.collisionMask.preUpdate();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this function to update your class's position and appearance.
|
||||
*/
|
||||
public update() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically called after update() by the game loop.
|
||||
*/
|
||||
public postUpdate() {
|
||||
|
||||
/*
|
||||
this.animations.update();
|
||||
|
||||
if (this.moves)
|
||||
{
|
||||
this.updateMotion();
|
||||
}
|
||||
|
||||
if (this.worldBounds != null)
|
||||
{
|
||||
if (this.outOfBoundsAction == GameObject.OUT_OF_BOUNDS_KILL)
|
||||
{
|
||||
if (this.x < this.worldBounds.x || this.x > this.worldBounds.right || this.y < this.worldBounds.y || this.y > this.worldBounds.bottom)
|
||||
{
|
||||
this.kill();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.x < this.worldBounds.x)
|
||||
{
|
||||
this.x = this.worldBounds.x;
|
||||
}
|
||||
else if (this.x > this.worldBounds.right)
|
||||
{
|
||||
this.x = this.worldBounds.right;
|
||||
}
|
||||
|
||||
if (this.y < this.worldBounds.y)
|
||||
{
|
||||
this.y = this.worldBounds.y;
|
||||
}
|
||||
else if (this.y > this.worldBounds.bottom)
|
||||
{
|
||||
this.y = this.worldBounds.bottom;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.collisionMask.update();
|
||||
|
||||
if (this.inputEnabled)
|
||||
{
|
||||
this.updateInput();
|
||||
}
|
||||
|
||||
this.wasTouching = this.touching;
|
||||
this.touching = Collision.NONE;
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up memory.
|
||||
*/
|
||||
public destroy() {
|
||||
}
|
||||
|
||||
/**
|
||||
* x value of the object.
|
||||
*/
|
||||
@@ -130,6 +233,17 @@ module Phaser {
|
||||
this.position.z = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* rotation value of the object.
|
||||
*/
|
||||
public get rotation(): number {
|
||||
return this.position.rotation;
|
||||
}
|
||||
|
||||
public set rotation(value: number) {
|
||||
this.position.rotation = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Polygon
|
||||
*
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Polygon {
|
||||
|
||||
/**
|
||||
* A *convex* clockwise polygon
|
||||
* @class Polygon
|
||||
* @constructor
|
||||
* @param {Vec2} pos A vector representing the origin of the polygon (all other points are relative to this one)
|
||||
* @param {Array.<Vec2>} points An Array of vectors representing the points in the polygon, in clockwise order.
|
||||
**/
|
||||
constructor(pos?: Vec2 = new Vec2, points?: Vec2[] = [], parent?:any = null) {
|
||||
|
||||
this.pos = pos;
|
||||
this.points = points;
|
||||
this.parent = parent;
|
||||
this.recalc();
|
||||
|
||||
}
|
||||
|
||||
public parent: any;
|
||||
public pos: Vec2;
|
||||
public points: Vec2[];
|
||||
public edges: Vec2[];
|
||||
public normals: Vec2[];
|
||||
|
||||
/**
|
||||
* Recalculate the edges and normals of the polygon. This
|
||||
* MUST be called if the points array is modified at all and
|
||||
* the edges or normals are to be accessed.
|
||||
*/
|
||||
public recalc() {
|
||||
|
||||
var points = this.points;
|
||||
var len = points.length;
|
||||
|
||||
this.edges = [];
|
||||
this.normals = [];
|
||||
|
||||
for (var i = 0; i < len; i++)
|
||||
{
|
||||
var p1 = points[i];
|
||||
var p2 = i < len - 1 ? points[i + 1] : points[0];
|
||||
var e = new Vec2().copyFrom(p2).sub(p1);
|
||||
var n = new Vec2().copyFrom(e).perp().normalize();
|
||||
this.edges.push(e);
|
||||
this.normals.push(n);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="Polygon.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Response
|
||||
*
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Response {
|
||||
|
||||
/**
|
||||
* An object representing the result of an intersection. Contain information about:
|
||||
* - The two objects participating in the intersection
|
||||
* - The vector representing the minimum change necessary to extract the first object
|
||||
* from the second one.
|
||||
* - Whether the first object is entirely inside the second, or vice versa.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
this.a = null;
|
||||
this.b = null;
|
||||
this.overlapN = new Vec2;
|
||||
this.overlapV = new Vec2;
|
||||
|
||||
this.clear();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The first object in the collision
|
||||
*/
|
||||
public a;
|
||||
|
||||
/**
|
||||
* The second object in the collision
|
||||
*/
|
||||
public b;
|
||||
|
||||
/**
|
||||
* The shortest colliding axis (unit-vector)
|
||||
*/
|
||||
public overlapN: Vec2;
|
||||
|
||||
/**
|
||||
* The overlap vector (i.e. overlapN.scale(overlap, overlap)).
|
||||
* If this vector is subtracted from the position of `a`, `a` and `b` will no longer be colliding.
|
||||
*/
|
||||
public overlapV: Vec2;
|
||||
|
||||
/**
|
||||
* Whether the first object is completely inside the second.
|
||||
*/
|
||||
public aInB: bool;
|
||||
|
||||
/**
|
||||
* Whether the second object is completely inside the first.
|
||||
*/
|
||||
public bInA: bool;
|
||||
|
||||
/**
|
||||
* Magnitude of the overlap on the shortest colliding axis
|
||||
*/
|
||||
public overlap: number;
|
||||
|
||||
/**
|
||||
* Set some values of the response back to their defaults. Call this between tests if
|
||||
* you are going to reuse a single Response object for multiple intersection tests (recommented)
|
||||
*
|
||||
* @return {Response} This for chaining
|
||||
*/
|
||||
public clear() {
|
||||
|
||||
this.aInB = true;
|
||||
this.bInA = true;
|
||||
this.overlap = Number.MAX_VALUE;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../Signal.ts" />
|
||||
/// <reference path="../core/Signal.ts" />
|
||||
/// <reference path="../utils/PointUtils.ts" />
|
||||
/// <reference path="../math/Vec2Utils.ts" />
|
||||
/// <reference path="Pointer.ts" />
|
||||
/// <reference path="MSPointer.ts" />
|
||||
/// <reference path="Gestures.ts" />
|
||||
/// <reference path="../utils/PointUtils.ts" />
|
||||
/// <reference path="../math/Vec2Utils.ts" />
|
||||
/// <reference path="Mouse.ts" />
|
||||
/// <reference path="Keyboard.ts" />
|
||||
/// <reference path="Touch.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Input
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../gameobjects/IGameObject.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - LinkedList
|
||||
@@ -21,9 +22,9 @@ module Phaser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a reference to an <code>Basic</code>.
|
||||
* Stores a reference to an <code>IGameObject</code>.
|
||||
*/
|
||||
public object: Basic;
|
||||
public object: IGameObject;
|
||||
|
||||
/**
|
||||
* Stores a reference to the next link in the list.
|
||||
|
||||
+63
-60
@@ -1,5 +1,6 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="LinkedList.ts" />
|
||||
/// <reference path="../gameobjects/IGameObject.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - QuadTree
|
||||
@@ -32,42 +33,39 @@ module Phaser {
|
||||
//Copy the parent's children (if there are any)
|
||||
if (parent != null)
|
||||
{
|
||||
var iterator: LinkedList;
|
||||
var ot: LinkedList;
|
||||
|
||||
if (parent._headA.object != null)
|
||||
{
|
||||
iterator = parent._headA;
|
||||
this._iterator = parent._headA;
|
||||
|
||||
while (iterator != null)
|
||||
while (this._iterator != null)
|
||||
{
|
||||
if (this._tailA.object != null)
|
||||
{
|
||||
ot = this._tailA;
|
||||
this._ot = this._tailA;
|
||||
this._tailA = new LinkedList();
|
||||
ot.next = this._tailA;
|
||||
this._ot.next = this._tailA;
|
||||
}
|
||||
|
||||
this._tailA.object = iterator.object;
|
||||
iterator = iterator.next;
|
||||
this._tailA.object = this._iterator.object;
|
||||
this._iterator = this._iterator.next;
|
||||
}
|
||||
}
|
||||
|
||||
if (parent._headB.object != null)
|
||||
{
|
||||
iterator = parent._headB;
|
||||
this._iterator = parent._headB;
|
||||
|
||||
while (iterator != null)
|
||||
while (this._iterator != null)
|
||||
{
|
||||
if (this._tailB.object != null)
|
||||
{
|
||||
ot = this._tailB;
|
||||
this._ot = this._tailB;
|
||||
this._tailB = new LinkedList();
|
||||
ot.next = this._tailB;
|
||||
this._ot.next = this._tailB;
|
||||
}
|
||||
|
||||
this._tailB.object = iterator.object;
|
||||
iterator = iterator.next;
|
||||
this._tailB.object = this._iterator.object;
|
||||
this._iterator = this._iterator.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,6 +92,16 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
// Reused temporary vars to help avoid gc spikes
|
||||
private _iterator: LinkedList;
|
||||
private _ot: LinkedList;
|
||||
private _i;
|
||||
private _basic;
|
||||
private _members;
|
||||
private _l: number;
|
||||
private _overlapProcessed: bool;
|
||||
private _checkObject;
|
||||
|
||||
/**
|
||||
* Flag for specifying that you want to add an object to the A list.
|
||||
*/
|
||||
@@ -287,13 +295,13 @@ module Phaser {
|
||||
/**
|
||||
* Load objects and/or groups into the quad tree, and register notify and processing callbacks.
|
||||
*
|
||||
* @param {Basic} objectOrGroup1 Any object that is or extends GameObject or Group.
|
||||
* @param {Basic} objectOrGroup2 Any object that is or extends GameObject or Group. If null, the first parameter will be checked against itself.
|
||||
* @param {} objectOrGroup1 Any object that is or extends IGameObject or Group.
|
||||
* @param {} objectOrGroup2 Any object that is or extends IGameObject or Group. If null, the first parameter will be checked against itself.
|
||||
* @param {Function} notifyCallback A function with the form <code>myFunction(Object1:GameObject,Object2:GameObject)</code> that is called whenever two objects are found to overlap in world space, and either no processCallback is specified, or the processCallback returns true.
|
||||
* @param {Function} processCallback A function with the form <code>myFunction(Object1:GameObject,Object2:GameObject):bool</code> that is called whenever two objects are found to overlap in world space. The notifyCallback is only called if this function returns true. See GameObject.separate().
|
||||
* @param context The context in which the callbacks will be called
|
||||
*/
|
||||
public load(objectOrGroup1: Basic, objectOrGroup2: Basic = null, notifyCallback = null, processCallback = null, context = null) {
|
||||
public load(objectOrGroup1, objectOrGroup2 = null, notifyCallback = null, processCallback = null, context = null) {
|
||||
|
||||
this.add(objectOrGroup1, QuadTree.A_LIST);
|
||||
|
||||
@@ -318,33 +326,32 @@ module Phaser {
|
||||
* This function will recursively add all group members, but
|
||||
* not the groups themselves.
|
||||
*
|
||||
* @param {Basic} objectOrGroup GameObjects are just added, Groups are recursed and their applicable members added accordingly.
|
||||
* @param {} objectOrGroup GameObjects are just added, Groups are recursed and their applicable members added accordingly.
|
||||
* @param {Number} list A <code>uint</code> flag indicating the list to which you want to add the objects. Options are <code>QuadTree.A_LIST</code> and <code>QuadTree.B_LIST</code>.
|
||||
*/
|
||||
public add(objectOrGroup: Basic, list: number) {
|
||||
public add(objectOrGroup, list: number) {
|
||||
|
||||
QuadTree._list = list;
|
||||
|
||||
if (objectOrGroup.isGroup == true)
|
||||
{
|
||||
var i: number = 0;
|
||||
var basic: Basic;
|
||||
var members = <Group> objectOrGroup['members'];
|
||||
var l: number = objectOrGroup['length'];
|
||||
this._i = 0;
|
||||
this._members = <Group> objectOrGroup['members'];
|
||||
this._l = objectOrGroup['length'];
|
||||
|
||||
while (i < l)
|
||||
while (this._i < this._l)
|
||||
{
|
||||
basic = members[i++];
|
||||
this._basic = this._members[this._i++];
|
||||
|
||||
if ((basic != null) && basic.exists)
|
||||
if (this._basic != null && this._basic.exists)
|
||||
{
|
||||
if (basic.isGroup)
|
||||
if (this._basic.type == Phaser.Types.GROUP)
|
||||
{
|
||||
this.add(basic, list);
|
||||
this.add(this._basic, list);
|
||||
}
|
||||
else
|
||||
{
|
||||
QuadTree._object = basic;
|
||||
QuadTree._object = this._basic;
|
||||
|
||||
if (QuadTree._object.exists && QuadTree._object.allowCollisions)
|
||||
{
|
||||
@@ -477,15 +484,13 @@ module Phaser {
|
||||
*/
|
||||
private addToList() {
|
||||
|
||||
var ot: LinkedList;
|
||||
|
||||
if (QuadTree._list == QuadTree.A_LIST)
|
||||
{
|
||||
if (this._tailA.object != null)
|
||||
{
|
||||
ot = this._tailA;
|
||||
this._ot = this._tailA;
|
||||
this._tailA = new LinkedList();
|
||||
ot.next = this._tailA;
|
||||
this._ot.next = this._tailA;
|
||||
}
|
||||
|
||||
this._tailA.object = QuadTree._object;
|
||||
@@ -494,9 +499,9 @@ module Phaser {
|
||||
{
|
||||
if (this._tailB.object != null)
|
||||
{
|
||||
ot = this._tailB;
|
||||
this._ot = this._tailB;
|
||||
this._tailB = new LinkedList();
|
||||
ot.next = this._tailB;
|
||||
this._ot.next = this._tailB;
|
||||
}
|
||||
|
||||
this._tailB.object = QuadTree._object;
|
||||
@@ -537,16 +542,15 @@ module Phaser {
|
||||
*/
|
||||
public execute(): bool {
|
||||
|
||||
var overlapProcessed: bool = false;
|
||||
var iterator: LinkedList;
|
||||
this._overlapProcessed = false;
|
||||
|
||||
if (this._headA.object != null)
|
||||
{
|
||||
iterator = this._headA;
|
||||
this._iterator = this._headA;
|
||||
|
||||
while (iterator != null)
|
||||
while (this._iterator != null)
|
||||
{
|
||||
QuadTree._object = iterator.object;
|
||||
QuadTree._object = this._iterator.object;
|
||||
|
||||
if (QuadTree._useBothLists)
|
||||
{
|
||||
@@ -554,15 +558,15 @@ module Phaser {
|
||||
}
|
||||
else
|
||||
{
|
||||
QuadTree._iterator = iterator.next;
|
||||
QuadTree._iterator = this._iterator.next;
|
||||
}
|
||||
|
||||
if (QuadTree._object.exists && (QuadTree._object.allowCollisions > 0) && (QuadTree._iterator != null) && (QuadTree._iterator.object != null) && QuadTree._iterator.object.exists && this.overlapNode())
|
||||
{
|
||||
overlapProcessed = true;
|
||||
this._overlapProcessed = true;
|
||||
}
|
||||
|
||||
iterator = iterator.next;
|
||||
this._iterator = this._iterator.next;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -570,25 +574,25 @@ module Phaser {
|
||||
//Advance through the tree by calling overlap on each child
|
||||
if ((this._northWestTree != null) && this._northWestTree.execute())
|
||||
{
|
||||
overlapProcessed = true;
|
||||
this._overlapProcessed = true;
|
||||
}
|
||||
|
||||
if ((this._northEastTree != null) && this._northEastTree.execute())
|
||||
{
|
||||
overlapProcessed = true;
|
||||
this._overlapProcessed = true;
|
||||
}
|
||||
|
||||
if ((this._southEastTree != null) && this._southEastTree.execute())
|
||||
{
|
||||
overlapProcessed = true;
|
||||
this._overlapProcessed = true;
|
||||
}
|
||||
|
||||
if ((this._southWestTree != null) && this._southWestTree.execute())
|
||||
{
|
||||
overlapProcessed = true;
|
||||
this._overlapProcessed = true;
|
||||
}
|
||||
|
||||
return overlapProcessed;
|
||||
return this._overlapProcessed;
|
||||
|
||||
}
|
||||
|
||||
@@ -600,8 +604,7 @@ module Phaser {
|
||||
private overlapNode(): bool {
|
||||
|
||||
//Walk the list and check for overlaps
|
||||
var overlapProcessed: bool = false;
|
||||
var checkObject;
|
||||
this._overlapProcessed = false;
|
||||
|
||||
while (QuadTree._iterator != null)
|
||||
{
|
||||
@@ -610,31 +613,31 @@ module Phaser {
|
||||
break;
|
||||
}
|
||||
|
||||
checkObject = QuadTree._iterator.object;
|
||||
this._checkObject = QuadTree._iterator.object;
|
||||
|
||||
if ((QuadTree._object === checkObject) || !checkObject.exists || (checkObject.allowCollisions <= 0))
|
||||
if ((QuadTree._object === this._checkObject) || !this._checkObject.exists || (this._checkObject.allowCollisions <= 0))
|
||||
{
|
||||
QuadTree._iterator = QuadTree._iterator.next;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (QuadTree._object.collisionMask.checkHullIntersection(checkObject.collisionMask))
|
||||
if (QuadTree._object.collisionMask.checkHullIntersection(this._checkObject.collisionMask))
|
||||
{
|
||||
//Execute callback functions if they exist
|
||||
if ((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, checkObject))
|
||||
if ((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, this._checkObject))
|
||||
{
|
||||
overlapProcessed = true;
|
||||
this._overlapProcessed = true;
|
||||
}
|
||||
|
||||
if (overlapProcessed && (QuadTree._notifyCallback != null))
|
||||
if (this._overlapProcessed && (QuadTree._notifyCallback != null))
|
||||
{
|
||||
if (QuadTree._callbackContext !== null)
|
||||
{
|
||||
QuadTree._notifyCallback.call(QuadTree._callbackContext, QuadTree._object, checkObject);
|
||||
QuadTree._notifyCallback.call(QuadTree._callbackContext, QuadTree._object, this._checkObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
QuadTree._notifyCallback(QuadTree._object, checkObject);
|
||||
QuadTree._notifyCallback(QuadTree._object, this._checkObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -643,7 +646,7 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
return overlapProcessed;
|
||||
return this._overlapProcessed;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/**
|
||||
* Phaser
|
||||
*
|
||||
* v1.0.0 - June XX 2013
|
||||
*
|
||||
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
||||
*
|
||||
* Richard Davey (@photonstorm)
|
||||
*
|
||||
* Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from both which Phaser
|
||||
* and my love of game development took a lot of inspiration.
|
||||
*
|
||||
* "If you want your children to be intelligent, read them fairy tales."
|
||||
* "If you want them to be more intelligent, read them more fairy tales."
|
||||
* -- Albert Einstein
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
Phaser.VERSION = 'Phaser version 1.0.0';
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../RenderManager.ts" />
|
||||
/// <reference path="../gameobjects/Sprite.ts" />
|
||||
/// <reference path="../cameras/Camera.ts" />
|
||||
/// <reference path="IRenderer.ts" />
|
||||
@@ -8,16 +7,14 @@ module Phaser {
|
||||
|
||||
export class CanvasRenderer implements Phaser.IRenderer {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
constructor(game: Phaser.Game) {
|
||||
this._game = game;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The essential reference to the main game object
|
||||
*/
|
||||
private _game: Game;
|
||||
private _game: Phaser.Game;
|
||||
|
||||
// local rendering related temp vars to help avoid gc spikes with var creation
|
||||
private _sx: number = 0;
|
||||
@@ -28,6 +25,8 @@ module Phaser {
|
||||
private _dy: number = 0;
|
||||
private _dw: number = 0;
|
||||
private _dh: number = 0;
|
||||
private _fx: number = 1;
|
||||
private _fy: number = 1;
|
||||
|
||||
private _cameraList;
|
||||
private _camera: Camera;
|
||||
@@ -73,15 +72,29 @@ module Phaser {
|
||||
sprite.texture.context.globalAlpha = sprite.texture.alpha;
|
||||
}
|
||||
|
||||
this._fx = sprite.scale.x;
|
||||
this._fy = sprite.scale.y;
|
||||
this._sx = 0;
|
||||
this._sy = 0;
|
||||
this._sw = sprite.frameBounds.width;
|
||||
this._sh = sprite.frameBounds.height;
|
||||
|
||||
//if (sprite.texture.flippedX)
|
||||
//{
|
||||
// this._fx = -1;
|
||||
//}
|
||||
|
||||
//if (sprite.texture.flippedY)
|
||||
//{
|
||||
// this._fy = -1;
|
||||
//}
|
||||
|
||||
this._dx = (camera.scaledX * sprite.scrollFactor.x) + sprite.frameBounds.x - (camera.worldView.x * sprite.scrollFactor.x);
|
||||
this._dy = (camera.scaledY * sprite.scrollFactor.y) + sprite.frameBounds.y - (camera.worldView.y * sprite.scrollFactor.y);
|
||||
this._dw = sprite.frameBounds.width * sprite.scale.x;
|
||||
this._dh = sprite.frameBounds.height * sprite.scale.y;
|
||||
//this._dw = sprite.frameBounds.width * sprite.scale.x;
|
||||
//this._dh = sprite.frameBounds.height * sprite.scale.y;
|
||||
this._dw = sprite.frameBounds.width;
|
||||
this._dh = sprite.frameBounds.height;
|
||||
|
||||
/*
|
||||
if (this._dynamicTexture == false && this.animations.currentFrame !== null)
|
||||
@@ -104,11 +117,35 @@ module Phaser {
|
||||
//this._dy -= (camera.worldView.y * this.scrollFactor.y);
|
||||
}
|
||||
|
||||
// Apply origin / alignment
|
||||
if (sprite.origin.x != 0 || sprite.origin.y != 0)
|
||||
{
|
||||
//this._dx += (sprite.origin.x * sprite.scale.x);
|
||||
//this._dy += (sprite.origin.y * sprite.scale.y);
|
||||
}
|
||||
|
||||
// Rotation and Flipped
|
||||
if (sprite.position.rotation !== 0 || sprite.position.rotationOffset !== 0 || sprite.texture.flippedX || sprite.texture.flippedY)
|
||||
if (sprite.scale.x != 1 || sprite.scale.y != 1 || sprite.position.rotation != 0 || sprite.position.rotationOffset != 0 || sprite.texture.flippedX || sprite.texture.flippedY)
|
||||
//if (sprite.position.rotation != 0 || sprite.position.rotationOffset != 0 || sprite.texture.flippedX || sprite.texture.flippedY)
|
||||
{
|
||||
sprite.texture.context.save();
|
||||
sprite.texture.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
||||
|
||||
if (sprite.texture.flippedX)
|
||||
{
|
||||
this._dx += this._dw * sprite.scale.x;
|
||||
}
|
||||
|
||||
if (sprite.texture.flippedY)
|
||||
{
|
||||
this._dy += this._dh * sprite.scale.y;
|
||||
}
|
||||
|
||||
sprite.texture.context.translate(this._dx, this._dy);
|
||||
|
||||
//sprite.texture.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
||||
//sprite.texture.context.translate(this._dx + (sprite.origin.x * sprite.scale.x), this._dy + (sprite.origin.y * sprite.scale.y));
|
||||
//sprite.texture.context.translate(this._dx + sprite.origin.x, this._dy + sprite.origin.y);
|
||||
//sprite.texture.context.translate(this._dx + sprite.origin.x - (this._dw / 2), this._dy + sprite.origin.y - (this._dh / 2));
|
||||
|
||||
if (sprite.texture.renderRotation == true && (sprite.position.rotation !== 0 || sprite.position.rotationOffset !== 0))
|
||||
{
|
||||
@@ -116,15 +153,42 @@ module Phaser {
|
||||
sprite.texture.context.rotate((sprite.position.rotationOffset + sprite.position.rotation) * (Math.PI / 180));
|
||||
}
|
||||
|
||||
this._dx = -(this._dw / 2);
|
||||
this._dy = -(this._dh / 2);
|
||||
|
||||
if (sprite.texture.flippedX || sprite.texture.flippedY)
|
||||
if (sprite.scale.x != 1 || sprite.scale.y != 1 || sprite.texture.flippedX || sprite.texture.flippedY)
|
||||
{
|
||||
if (sprite.texture.flippedX)
|
||||
{
|
||||
sprite.texture.context.scale(-1, 1);
|
||||
this._fx = -sprite.scale.x;
|
||||
}
|
||||
|
||||
if (sprite.texture.flippedY)
|
||||
{
|
||||
this._fy = -sprite.scale.y;
|
||||
}
|
||||
|
||||
sprite.texture.context.scale(this._fx, this._fy);
|
||||
|
||||
}
|
||||
|
||||
//if (sprite.texture.flippedX || sprite.texture.flippedY)
|
||||
//{
|
||||
// sprite.texture.context.scale(this._fx, this._fy);
|
||||
//}
|
||||
|
||||
this._dx = -(sprite.origin.x * sprite.scale.x);
|
||||
this._dy = -(sprite.origin.y * sprite.scale.y);
|
||||
//this._dx = -(sprite.origin.x * sprite.scale.x);
|
||||
//this._dy = -(sprite.origin.y * sprite.scale.y);
|
||||
//this._dx = -(this._dw / 2) * sprite.scale.x;
|
||||
//this._dy = -(this._dh / 2) * sprite.scale.y;
|
||||
//this._dx = 0;
|
||||
//this._dy = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sprite.origin.x != 0 || sprite.origin.y != 0)
|
||||
{
|
||||
//this._dx -= (sprite.origin.x * sprite.scale.x);
|
||||
//this._dy -= (sprite.origin.y * sprite.scale.y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +221,8 @@ module Phaser {
|
||||
// this.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
||||
//}
|
||||
|
||||
if (sprite.position.rotation !== 0 || sprite.position.rotationOffset !== 0 || sprite.texture.flippedX || sprite.texture.flippedY)
|
||||
if (sprite.scale.x != 1 || sprite.scale.y != 1 || sprite.position.rotation != 0 || sprite.position.rotationOffset != 0 || sprite.texture.flippedX || sprite.texture.flippedY)
|
||||
//if (sprite.position.rotation != 0 || sprite.position.rotationOffset != 0 || sprite.texture.flippedX || sprite.texture.flippedY)
|
||||
{
|
||||
//this.context.translate(0, 0);
|
||||
sprite.texture.context.restore();
|
||||
|
||||
@@ -6,14 +6,14 @@ module Phaser {
|
||||
|
||||
export class HeadlessRenderer implements Phaser.IRenderer {
|
||||
|
||||
constructor(game: Game) {
|
||||
constructor(game: Phaser.Game) {
|
||||
this._game = game;
|
||||
}
|
||||
|
||||
/**
|
||||
* The essential reference to the main game object
|
||||
*/
|
||||
private _game: Game;
|
||||
private _game: Phaser.Game;
|
||||
|
||||
public render() {}
|
||||
|
||||
|
||||
@@ -4,10 +4,6 @@ module Phaser {
|
||||
|
||||
export interface IRenderer {
|
||||
|
||||
// properties
|
||||
_game: Game;
|
||||
|
||||
// methods
|
||||
render();
|
||||
renderSprite(camera: Camera, sprite: Sprite): bool;
|
||||
|
||||
|
||||
@@ -195,6 +195,18 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
public clear() {
|
||||
|
||||
this._chainedTweens = [];
|
||||
|
||||
this.onStart.removeAll();
|
||||
this.onUpdate.removeAll();
|
||||
this.onComplete.removeAll();
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop tweening.
|
||||
*/
|
||||
|
||||
@@ -36,7 +36,8 @@ 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 (a.radius * a.radius >= Collision.distanceSquared(a.x, a.y, x, y));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +60,8 @@ module Phaser {
|
||||
* @return {Boolean} True if the coordinates are within this circle, otherwise false.
|
||||
**/
|
||||
static containsCircle(a:Circle, b:Circle): bool {
|
||||
return ((a.radius + b.radius) * (a.radius + b.radius)) >= Collision.distanceSquared(a.x, a.y, b.x, b.y);
|
||||
//return ((a.radius + b.radius) * (a.radius + b.radius)) >= Collision.distanceSquared(a.x, a.y, b.x, b.y);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -341,65 +341,6 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load graphic for this sprite. (graphic can be SpriteSheet or Texture)
|
||||
* @param key {string} Key of the graphic you want to load for this sprite.
|
||||
* @param clearAnimations {boolean} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this boolean
|
||||
* @return {Sprite} Sprite instance itself.
|
||||
*/
|
||||
static loadTexture(sprite: Phaser.Sprite, key: string, clearAnimations: bool = true): Sprite {
|
||||
|
||||
//if (clearAnimations && sprite.animations.frameData !== null)
|
||||
//{
|
||||
// sprite.animations.destroy();
|
||||
//}
|
||||
|
||||
if (sprite.game.cache.getImage(key) !== null)
|
||||
{
|
||||
if (sprite.game.cache.isSpriteSheet(key))
|
||||
{
|
||||
sprite.texture.setTo(null, sprite.game.cache.getImage(key));
|
||||
//sprite.animations.loadFrameData(sprite._game.cache.getFrameData(key));
|
||||
//sprite.collisionMask.width = sprite.animations.currentFrame.width;
|
||||
//sprite.collisionMask.height = sprite.animations.currentFrame.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.texture.setTo(sprite.game.cache.getImage(key), null);
|
||||
sprite.frameBounds.width = sprite.texture.width;
|
||||
sprite.frameBounds.height = sprite.texture.height;
|
||||
//sprite.collisionMask.width = sprite._texture.width;
|
||||
//sprite.collisionMask.height = sprite._texture.height;
|
||||
}
|
||||
}
|
||||
|
||||
return sprite;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a DynamicTexture as its texture.
|
||||
* @param texture {DynamicTexture} The texture object to be used by this sprite.
|
||||
* @return {Sprite} Sprite instance itself.
|
||||
*/
|
||||
static loadDynamicTexture(sprite: Phaser.Sprite, texture: DynamicTexture): Sprite {
|
||||
|
||||
//if (sprite.animations.frameData !== null)
|
||||
//{
|
||||
// sprite.animations.destroy();
|
||||
//}
|
||||
|
||||
//sprite._texture = texture;
|
||||
|
||||
//sprite.frameBounds.width = sprite._texture.width;
|
||||
//sprite.frameBounds.height = sprite._texture.height;
|
||||
|
||||
//sprite._dynamicTexture = true;
|
||||
|
||||
return sprite;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates a flat colored square image dynamically.
|
||||
* @param width {number} The width of the sprite you want to generate.
|
||||
|
||||
Reference in New Issue
Block a user