mirror of
https://github.com/wassname/phaser.git
synced 2026-08-15 12:45:11 +08:00
Tidying up and trying to fix more stupid TypeScript errors.
This commit is contained in:
@@ -1,285 +0,0 @@
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../Group.ts" />
|
||||
/**
|
||||
* Phaser - Emitter
|
||||
*
|
||||
* Emitter is a lightweight particle emitter. It can be used for one-time explosions or for
|
||||
* continuous effects like rain and fire. All it really does is launch Particle objects out
|
||||
* at set intervals, and fixes their positions and velocities accorindgly.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Emitter = (function (_super) {
|
||||
__extends(Emitter, _super);
|
||||
/**
|
||||
* Creates a new <code>Emitter</code> object at a specific position.
|
||||
* Does NOT automatically generate or attach particles!
|
||||
*
|
||||
* @param x {number} The X position of the emitter.
|
||||
* @param y {number} The Y position of the emitter.
|
||||
* @param [size] {number} Specifies a maximum capacity for this emitter.
|
||||
*/
|
||||
function Emitter(game, x, y, size) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof size === "undefined") { size = 0; }
|
||||
_super.call(this, game, size);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
this.minParticleSpeed = new MicroPoint(-100, -100);
|
||||
this.maxParticleSpeed = new MicroPoint(100, 100);
|
||||
this.minRotation = -360;
|
||||
this.maxRotation = 360;
|
||||
this.gravity = 0;
|
||||
this.particleClass = null;
|
||||
this.particleDrag = new MicroPoint();
|
||||
this.frequency = 0.1;
|
||||
this.lifespan = 3;
|
||||
this.bounce = 0;
|
||||
this._quantity = 0;
|
||||
this._counter = 0;
|
||||
this._explode = true;
|
||||
this.on = false;
|
||||
this._point = new MicroPoint();
|
||||
}
|
||||
Emitter.prototype.destroy = /**
|
||||
* Clean up memory.
|
||||
*/
|
||||
function () {
|
||||
this.minParticleSpeed = null;
|
||||
this.maxParticleSpeed = null;
|
||||
this.particleDrag = null;
|
||||
this.particleClass = null;
|
||||
this._point = null;
|
||||
_super.prototype.destroy.call(this);
|
||||
};
|
||||
Emitter.prototype.makeParticles = /**
|
||||
* This function generates a new array of particle sprites to attach to the emitter.
|
||||
*
|
||||
* @param graphics If you opted to not pre-configure an array of Sprite objects, you can simply pass in a particle image or sprite sheet.
|
||||
* @param quantity {number} The number of particles to generate when using the "create from image" option.
|
||||
* @param multiple {boolean} Whether the image in the Graphics param is a single particle or a bunch of particles (if it's a bunch, they need to be square!).
|
||||
* @param collide {number} Whether the particles should be flagged as not 'dead' (non-colliding particles are higher performance). 0 means no collisions, 0-1 controls scale of particle's bounding box.
|
||||
*
|
||||
* @return This Emitter instance (nice for chaining stuff together, if you're into that).
|
||||
*/
|
||||
function (graphics, quantity, multiple, collide) {
|
||||
if (typeof quantity === "undefined") { quantity = 50; }
|
||||
if (typeof multiple === "undefined") { multiple = false; }
|
||||
if (typeof collide === "undefined") { collide = 0; }
|
||||
this.maxSize = quantity;
|
||||
var totalFrames = 1;
|
||||
/*
|
||||
if(Multiple)
|
||||
{
|
||||
var sprite:Sprite = new Sprite(this._game);
|
||||
sprite.loadGraphic(Graphics,true);
|
||||
totalFrames = sprite.frames;
|
||||
sprite.destroy();
|
||||
}
|
||||
*/
|
||||
var randomFrame;
|
||||
var particle;
|
||||
var i = 0;
|
||||
while(i < quantity) {
|
||||
if(this.particleClass == null) {
|
||||
particle = new Phaser.Particle(this._game);
|
||||
} else {
|
||||
particle = new this.particleClass(this._game);
|
||||
}
|
||||
if(multiple) {
|
||||
/*
|
||||
randomFrame = this._game.math.random()*totalFrames;
|
||||
if(BakedRotations > 0)
|
||||
particle.loadRotatedGraphic(Graphics,BakedRotations,randomFrame);
|
||||
else
|
||||
{
|
||||
particle.loadGraphic(Graphics,true);
|
||||
particle.frame = randomFrame;
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
/*
|
||||
if (BakedRotations > 0)
|
||||
particle.loadRotatedGraphic(Graphics,BakedRotations);
|
||||
else
|
||||
particle.loadGraphic(Graphics);
|
||||
*/
|
||||
if(graphics) {
|
||||
particle.loadGraphic(graphics);
|
||||
}
|
||||
}
|
||||
if(collide > 0) {
|
||||
particle.allowCollisions = Phaser.Collision.ANY;
|
||||
particle.width *= collide;
|
||||
particle.height *= collide;
|
||||
//particle.centerOffsets();
|
||||
} else {
|
||||
particle.allowCollisions = Phaser.Collision.NONE;
|
||||
}
|
||||
particle.exists = false;
|
||||
this.add(particle);
|
||||
i++;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
Emitter.prototype.update = /**
|
||||
* Called automatically by the game loop, decides when to launch particles and when to "die".
|
||||
*/
|
||||
function () {
|
||||
if(this.on) {
|
||||
if(this._explode) {
|
||||
this.on = false;
|
||||
var i = 0;
|
||||
var l = this._quantity;
|
||||
if((l <= 0) || (l > this.length)) {
|
||||
l = this.length;
|
||||
}
|
||||
while(i < l) {
|
||||
this.emitParticle();
|
||||
i++;
|
||||
}
|
||||
this._quantity = 0;
|
||||
} else {
|
||||
this._timer += this._game.time.elapsed;
|
||||
while((this.frequency > 0) && (this._timer > this.frequency) && this.on) {
|
||||
this._timer -= this.frequency;
|
||||
this.emitParticle();
|
||||
if((this._quantity > 0) && (++this._counter >= this._quantity)) {
|
||||
this.on = false;
|
||||
this._quantity = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_super.prototype.update.call(this);
|
||||
};
|
||||
Emitter.prototype.kill = /**
|
||||
* Call this function to turn off all the particles and the emitter.
|
||||
*/
|
||||
function () {
|
||||
this.on = false;
|
||||
_super.prototype.kill.call(this);
|
||||
};
|
||||
Emitter.prototype.start = /**
|
||||
* Call this function to start emitting particles.
|
||||
*
|
||||
* @param explode {boolean} Whether the particles should all burst out at once.
|
||||
* @param lifespan {number} How long each particle lives once emitted. 0 = forever.
|
||||
* @param frequency {number} Ignored if Explode is set to true. Frequency is how often to emit a particle. 0 = never emit, 0.1 = 1 particle every 0.1 seconds, 5 = 1 particle every 5 seconds.
|
||||
* @param quantity {number} How many particles to launch. 0 = "all of the particles".
|
||||
*/
|
||||
function (explode, lifespan, frequency, quantity) {
|
||||
if (typeof explode === "undefined") { explode = true; }
|
||||
if (typeof lifespan === "undefined") { lifespan = 0; }
|
||||
if (typeof frequency === "undefined") { frequency = 0.1; }
|
||||
if (typeof quantity === "undefined") { quantity = 0; }
|
||||
this.revive();
|
||||
this.visible = true;
|
||||
this.on = true;
|
||||
this._explode = explode;
|
||||
this.lifespan = lifespan;
|
||||
this.frequency = frequency;
|
||||
this._quantity += quantity;
|
||||
this._counter = 0;
|
||||
this._timer = 0;
|
||||
};
|
||||
Emitter.prototype.emitParticle = /**
|
||||
* This function can be used both internally and externally to emit the next particle.
|
||||
*/
|
||||
function () {
|
||||
var particle = this.recycle(Phaser.Particle);
|
||||
particle.lifespan = this.lifespan;
|
||||
particle.elasticity = this.bounce;
|
||||
particle.reset(this.x - (particle.width >> 1) + this._game.math.random() * this.width, this.y - (particle.height >> 1) + this._game.math.random() * this.height);
|
||||
particle.visible = true;
|
||||
if(this.minParticleSpeed.x != this.maxParticleSpeed.x) {
|
||||
particle.velocity.x = this.minParticleSpeed.x + this._game.math.random() * (this.maxParticleSpeed.x - this.minParticleSpeed.x);
|
||||
} else {
|
||||
particle.velocity.x = this.minParticleSpeed.x;
|
||||
}
|
||||
if(this.minParticleSpeed.y != this.maxParticleSpeed.y) {
|
||||
particle.velocity.y = this.minParticleSpeed.y + this._game.math.random() * (this.maxParticleSpeed.y - this.minParticleSpeed.y);
|
||||
} else {
|
||||
particle.velocity.y = this.minParticleSpeed.y;
|
||||
}
|
||||
particle.acceleration.y = this.gravity;
|
||||
if(this.minRotation != this.maxRotation && this.minRotation !== 0 && this.maxRotation !== 0) {
|
||||
particle.angularVelocity = this.minRotation + this._game.math.random() * (this.maxRotation - this.minRotation);
|
||||
} else {
|
||||
particle.angularVelocity = this.minRotation;
|
||||
}
|
||||
if(particle.angularVelocity != 0) {
|
||||
particle.angle = this._game.math.random() * 360 - 180;
|
||||
}
|
||||
particle.drag.x = this.particleDrag.x;
|
||||
particle.drag.y = this.particleDrag.y;
|
||||
particle.onEmit();
|
||||
};
|
||||
Emitter.prototype.setSize = /**
|
||||
* A more compact way of setting the width and height of the emitter.
|
||||
*
|
||||
* @param width {number} The desired width of the emitter (particles are spawned randomly within these dimensions).
|
||||
* @param height {number} The desired height of the emitter.
|
||||
*/
|
||||
function (width, height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
};
|
||||
Emitter.prototype.setXSpeed = /**
|
||||
* A more compact way of setting the X velocity range of the emitter.
|
||||
*
|
||||
* @param Min {number} The minimum value for this range.
|
||||
* @param Max {number} The maximum value for this range.
|
||||
*/
|
||||
function (min, max) {
|
||||
if (typeof min === "undefined") { min = 0; }
|
||||
if (typeof max === "undefined") { max = 0; }
|
||||
this.minParticleSpeed.x = min;
|
||||
this.maxParticleSpeed.x = max;
|
||||
};
|
||||
Emitter.prototype.setYSpeed = /**
|
||||
* A more compact way of setting the Y velocity range of the emitter.
|
||||
*
|
||||
* @param Min {number} The minimum value for this range.
|
||||
* @param Max {number} The maximum value for this range.
|
||||
*/
|
||||
function (min, max) {
|
||||
if (typeof min === "undefined") { min = 0; }
|
||||
if (typeof max === "undefined") { max = 0; }
|
||||
this.minParticleSpeed.y = min;
|
||||
this.maxParticleSpeed.y = max;
|
||||
};
|
||||
Emitter.prototype.setRotation = /**
|
||||
* A more compact way of setting the angular velocity constraints of the emitter.
|
||||
*
|
||||
* @param Min {number} The minimum value for this range.
|
||||
* @param Max {number} The maximum value for this range.
|
||||
*/
|
||||
function (min, max) {
|
||||
if (typeof min === "undefined") { min = 0; }
|
||||
if (typeof max === "undefined") { max = 0; }
|
||||
this.minRotation = min;
|
||||
this.maxRotation = max;
|
||||
};
|
||||
Emitter.prototype.at = /**
|
||||
* Change the emitter's midpoint to match the midpoint of a <code>Object</code>.
|
||||
*
|
||||
* @param Object {object} The <code>Object</code> that you want to sync up with.
|
||||
*/
|
||||
function (object) {
|
||||
object.getMidpoint(this._point);
|
||||
this.x = this._point.x - (this.width >> 1);
|
||||
this.y = this._point.y - (this.height >> 1);
|
||||
};
|
||||
return Emitter;
|
||||
})(Phaser.Group);
|
||||
Phaser.Emitter = Emitter;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,30 +0,0 @@
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Components - Events
|
||||
*
|
||||
* Signals that are dispatched by the Sprite and its various components
|
||||
*/
|
||||
(function (Components) {
|
||||
var Events = (function () {
|
||||
/**
|
||||
* The Events component is a collection of events fired by the parent game object and its components.
|
||||
* @param parent The game object using this Input component
|
||||
*/
|
||||
function Events(parent) {
|
||||
this.game = parent.game;
|
||||
this._parent = parent;
|
||||
|
||||
this.onAddedToGroup = new Phaser.Signal();
|
||||
this.onRemovedFromGroup = new Phaser.Signal();
|
||||
this.onKilled = new Phaser.Signal();
|
||||
this.onRevived = new Phaser.Signal();
|
||||
this.onOutOfBounds = new Phaser.Signal();
|
||||
}
|
||||
return Events;
|
||||
})();
|
||||
Components.Events = Events;
|
||||
})(Phaser.Components || (Phaser.Components = {}));
|
||||
var Components = Phaser.Components;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,534 +0,0 @@
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../Basic.ts" />
|
||||
/// <reference path="../Signal.ts" />
|
||||
/// <reference path="../system/CollisionMask.ts" />
|
||||
/**
|
||||
* Phaser - GameObject
|
||||
*
|
||||
* This is the base GameObject on which all other game objects are derived. It contains all the logic required for position,
|
||||
* motion, size, collision and input.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var GameObject = (function (_super) {
|
||||
__extends(GameObject, _super);
|
||||
/**
|
||||
* GameObject constructor
|
||||
*
|
||||
* Create a new <code>GameObject</code> object at specific position with specific width and height.
|
||||
*
|
||||
* @param [x] {number} The x position of the object.
|
||||
* @param [y] {number} The y position of the object.
|
||||
* @param [width] {number} The width of the object.
|
||||
* @param [height] {number} The height of the object.
|
||||
*/
|
||||
function GameObject(game, x, y, width, height) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof width === "undefined") { width = 16; }
|
||||
if (typeof height === "undefined") { height = 16; }
|
||||
_super.call(this, game);
|
||||
/**
|
||||
* Angle of this object.
|
||||
* @type {number}
|
||||
*/
|
||||
this._angle = 0;
|
||||
/**
|
||||
* What action will be performed when object is out of the worldBounds.
|
||||
* This will default to GameObject.OUT_OF_BOUNDS_STOP.
|
||||
* @type {number}
|
||||
*/
|
||||
this.outOfBoundsAction = 0;
|
||||
/**
|
||||
* Z-order value of the object.
|
||||
*/
|
||||
this.z = 0;
|
||||
/**
|
||||
* This value is added to the angle of the GameObject.
|
||||
* For example if you had a sprite drawn facing straight up then you could set
|
||||
* rotationOffset to 90 and it would correspond correctly with Phasers rotation system
|
||||
* @type {number}
|
||||
*/
|
||||
this.rotationOffset = 0;
|
||||
/**
|
||||
* Controls if the GameObject is rendered rotated or not.
|
||||
* If renderRotation is false then the object can still rotate but it will never be rendered rotated.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.renderRotation = true;
|
||||
/**
|
||||
* Set this to false if you want to skip the automatic motion/movement stuff
|
||||
* (see updateMotion()).
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.moves = true;
|
||||
// Input
|
||||
this.inputEnabled = false;
|
||||
this._inputOver = false;
|
||||
this.canvas = game.stage.canvas;
|
||||
this.context = game.stage.context;
|
||||
this.frameBounds = new Rectangle(x, y, width, height);
|
||||
this.exists = true;
|
||||
this.active = true;
|
||||
this.visible = true;
|
||||
this.alive = true;
|
||||
this.isGroup = false;
|
||||
this.alpha = 1;
|
||||
this.scale = new MicroPoint(1, 1);
|
||||
this.last = new MicroPoint(x, y);
|
||||
this.align = GameObject.ALIGN_TOP_LEFT;
|
||||
this.mass = 1;
|
||||
this.elasticity = 0;
|
||||
this.health = 1;
|
||||
this.immovable = false;
|
||||
this.moves = true;
|
||||
this.worldBounds = null;
|
||||
this.touching = Collision.NONE;
|
||||
this.wasTouching = Collision.NONE;
|
||||
this.allowCollisions = Collision.ANY;
|
||||
this.velocity = new MicroPoint();
|
||||
this.acceleration = new MicroPoint();
|
||||
this.drag = new MicroPoint();
|
||||
this.maxVelocity = new MicroPoint(10000, 10000);
|
||||
this.angle = 0;
|
||||
this.angularVelocity = 0;
|
||||
this.angularAcceleration = 0;
|
||||
this.angularDrag = 0;
|
||||
this.maxAngular = 10000;
|
||||
this.cameraBlacklist = [];
|
||||
this.scrollFactor = new MicroPoint(1, 1);
|
||||
this.collisionMask = new CollisionMask(game, this, x, y, width, height);
|
||||
}
|
||||
GameObject.ALIGN_TOP_LEFT = 0;
|
||||
GameObject.ALIGN_TOP_CENTER = 1;
|
||||
GameObject.ALIGN_TOP_RIGHT = 2;
|
||||
GameObject.ALIGN_CENTER_LEFT = 3;
|
||||
GameObject.ALIGN_CENTER = 4;
|
||||
GameObject.ALIGN_CENTER_RIGHT = 5;
|
||||
GameObject.ALIGN_BOTTOM_LEFT = 6;
|
||||
GameObject.ALIGN_BOTTOM_CENTER = 7;
|
||||
GameObject.ALIGN_BOTTOM_RIGHT = 8;
|
||||
GameObject.OUT_OF_BOUNDS_STOP = 0;
|
||||
GameObject.OUT_OF_BOUNDS_KILL = 1;
|
||||
GameObject.prototype.preUpdate = /**
|
||||
* Pre-update is called right before update() on each object in the game loop.
|
||||
*/
|
||||
function () {
|
||||
this.last.x = this.frameBounds.x;
|
||||
this.last.y = this.frameBounds.y;
|
||||
this.collisionMask.preUpdate();
|
||||
};
|
||||
GameObject.prototype.update = /**
|
||||
* Override this function to update your class's position and appearance.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
GameObject.prototype.postUpdate = /**
|
||||
* Automatically called after update() by the game loop.
|
||||
*/
|
||||
function () {
|
||||
if(this.moves) {
|
||||
this.updateMotion();
|
||||
}
|
||||
if(this.worldBounds != null) {
|
||||
if(this.outOfBoundsAction == Phaser.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 = Phaser.Collision.NONE;
|
||||
};
|
||||
GameObject.prototype.updateInput = /**
|
||||
* Update input.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
GameObject.prototype.updateMotion = /**
|
||||
* Internal function for updating the position and speed of this object.
|
||||
*/
|
||||
function () {
|
||||
var delta;
|
||||
var velocityDelta;
|
||||
velocityDelta = (this._game.motion.computeVelocity(this.angularVelocity, this.angularAcceleration, this.angularDrag, this.maxAngular) - this.angularVelocity) / 2;
|
||||
this.angularVelocity += velocityDelta;
|
||||
this._angle += this.angularVelocity * this._game.time.elapsed;
|
||||
this.angularVelocity += velocityDelta;
|
||||
velocityDelta = (this._game.motion.computeVelocity(this.velocity.x, this.acceleration.x, this.drag.x, this.maxVelocity.x) - this.velocity.x) / 2;
|
||||
this.velocity.x += velocityDelta;
|
||||
delta = this.velocity.x * this._game.time.elapsed;
|
||||
this.velocity.x += velocityDelta;
|
||||
this.frameBounds.x += delta;
|
||||
velocityDelta = (this._game.motion.computeVelocity(this.velocity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y) - this.velocity.y) / 2;
|
||||
this.velocity.y += velocityDelta;
|
||||
delta = this.velocity.y * this._game.time.elapsed;
|
||||
this.velocity.y += velocityDelta;
|
||||
this.frameBounds.y += delta;
|
||||
};
|
||||
GameObject.prototype.overlaps = /**
|
||||
* Checks to see if some <code>GameObject</code> overlaps this <code>GameObject</code> or <code>Group</code>.
|
||||
* If the group has a LOT of things in it, it might be faster to use <code>Collision.overlaps()</code>.
|
||||
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
|
||||
*
|
||||
* @param objectOrGroup {object} The object or group being tested.
|
||||
* @param inScreenSpace {boolean} Whether to take scroll factors numbero account when checking for overlap. Default is false, or "only compare in world space."
|
||||
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
*
|
||||
* @return {boolean} Whether or not the objects overlap this.
|
||||
*/
|
||||
function (objectOrGroup, inScreenSpace, camera) {
|
||||
if (typeof inScreenSpace === "undefined") { inScreenSpace = false; }
|
||||
if (typeof camera === "undefined") { camera = null; }
|
||||
if(objectOrGroup.isGroup) {
|
||||
var results = false;
|
||||
var i = 0;
|
||||
var members = objectOrGroup.members;
|
||||
while(i < length) {
|
||||
if(this.overlaps(members[i++], inScreenSpace, camera)) {
|
||||
results = true;
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
if(!inScreenSpace) {
|
||||
return (objectOrGroup.x + objectOrGroup.width > this.x) && (objectOrGroup.x < this.x + this.width) && (objectOrGroup.y + objectOrGroup.height > this.y) && (objectOrGroup.y < this.y + this.height);
|
||||
}
|
||||
if(camera == null) {
|
||||
camera = this._game.camera;
|
||||
}
|
||||
var objectScreenPos = objectOrGroup.getScreenXY(null, camera);
|
||||
this.getScreenXY(this._point, camera);
|
||||
return (objectScreenPos.x + objectOrGroup.width > this._point.x) && (objectScreenPos.x < this._point.x + this.width) && (objectScreenPos.y + objectOrGroup.height > this._point.y) && (objectScreenPos.y < this._point.y + this.height);
|
||||
};
|
||||
GameObject.prototype.overlapsAt = /**
|
||||
* Checks to see if this <code>GameObject</code> were located at the given position, would it overlap the <code>GameObject</code> or <code>Group</code>?
|
||||
* This is distinct from overlapsPoint(), which just checks that point, rather than taking the object's size numbero account.
|
||||
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
|
||||
*
|
||||
* @param X {number} The X position you want to check. Pretends this object (the caller, not the parameter) is located here.
|
||||
* @param Y {number} The Y position you want to check. Pretends this object (the caller, not the parameter) is located here.
|
||||
* @param objectOrGroup {object} The object or group being tested.
|
||||
* @param inScreenSpace {boolean} Whether to take scroll factors numbero account when checking for overlap. Default is false, or "only compare in world space."
|
||||
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
*
|
||||
* @return {boolean} Whether or not the two objects overlap.
|
||||
*/
|
||||
function (X, Y, objectOrGroup, inScreenSpace, camera) {
|
||||
if (typeof inScreenSpace === "undefined") { inScreenSpace = false; }
|
||||
if (typeof camera === "undefined") { camera = null; }
|
||||
if(objectOrGroup.isGroup) {
|
||||
var results = false;
|
||||
var basic;
|
||||
var i = 0;
|
||||
var members = objectOrGroup.members;
|
||||
while(i < length) {
|
||||
if(this.overlapsAt(X, Y, members[i++], inScreenSpace, camera)) {
|
||||
results = true;
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
if(!inScreenSpace) {
|
||||
return (objectOrGroup.x + objectOrGroup.width > X) && (objectOrGroup.x < X + this.width) && (objectOrGroup.y + objectOrGroup.height > Y) && (objectOrGroup.y < Y + this.height);
|
||||
}
|
||||
if(camera == null) {
|
||||
camera = this._game.camera;
|
||||
}
|
||||
var objectScreenPos = objectOrGroup.getScreenXY(null, Phaser.Camera);
|
||||
this._point.x = X - camera.scroll.x * this.scrollFactor.x//copied from getScreenXY()
|
||||
;
|
||||
this._point.y = Y - camera.scroll.y * this.scrollFactor.y;
|
||||
this._point.x += (this._point.x > 0) ? 0.0000001 : -0.0000001;
|
||||
this._point.y += (this._point.y > 0) ? 0.0000001 : -0.0000001;
|
||||
return (objectScreenPos.x + objectOrGroup.width > this._point.x) && (objectScreenPos.x < this._point.x + this.width) && (objectScreenPos.y + objectOrGroup.height > this._point.y) && (objectScreenPos.y < this._point.y + this.height);
|
||||
};
|
||||
GameObject.prototype.overlapsPoint = /**
|
||||
* Checks to see if a point in 2D world space overlaps this <code>GameObject</code>.
|
||||
*
|
||||
* @param point {Point} The point in world space you want to check.
|
||||
* @param inScreenSpace {boolean} Whether to take scroll factors into account when checking for overlap.
|
||||
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
*
|
||||
* @return Whether or not the point overlaps this object.
|
||||
*/
|
||||
function (point, inScreenSpace, camera) {
|
||||
if (typeof inScreenSpace === "undefined") { inScreenSpace = false; }
|
||||
if (typeof camera === "undefined") { camera = null; }
|
||||
if(!inScreenSpace) {
|
||||
return (point.x > this.x) && (point.x < this.x + this.width) && (point.y > this.y) && (point.y < this.y + this.height);
|
||||
}
|
||||
if(camera == null) {
|
||||
camera = this._game.camera;
|
||||
}
|
||||
var X = point.x - camera.scroll.x;
|
||||
var Y = point.y - camera.scroll.y;
|
||||
this.getScreenXY(this._point, camera);
|
||||
return (X > this._point.x) && (X < this._point.x + this.width) && (Y > this._point.y) && (Y < this._point.y + this.height);
|
||||
};
|
||||
GameObject.prototype.onScreen = /**
|
||||
* Check and see if this object is currently on screen.
|
||||
*
|
||||
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
*
|
||||
* @return {boolean} Whether the object is on screen or not.
|
||||
*/
|
||||
function (camera) {
|
||||
if (typeof camera === "undefined") { camera = null; }
|
||||
if(camera == null) {
|
||||
camera = this._game.camera;
|
||||
}
|
||||
this.getScreenXY(this._point, camera);
|
||||
return (this._point.x + this.width > 0) && (this._point.x < camera.width) && (this._point.y + this.height > 0) && (this._point.y < camera.height);
|
||||
};
|
||||
GameObject.prototype.getScreenXY = /**
|
||||
* Call this to figure out the on-screen position of the object.
|
||||
*
|
||||
* @param point {Point} Takes a <code>MicroPoint</code> object and assigns the post-scrolled X and Y values of this object to it.
|
||||
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
*
|
||||
* @return {MicroPoint} The <code>MicroPoint</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.
|
||||
*/
|
||||
function (point, camera) {
|
||||
if (typeof point === "undefined") { point = null; }
|
||||
if (typeof camera === "undefined") { camera = null; }
|
||||
if(point == null) {
|
||||
point = new Phaser.MicroPoint();
|
||||
}
|
||||
if(camera == null) {
|
||||
camera = this._game.camera;
|
||||
}
|
||||
point.x = this.x - camera.scroll.x * this.scrollFactor.x;
|
||||
point.y = this.y - camera.scroll.y * this.scrollFactor.y;
|
||||
point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
|
||||
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
|
||||
return point;
|
||||
};
|
||||
Object.defineProperty(GameObject.prototype, "solid", {
|
||||
get: /**
|
||||
* Whether the object collides or not. For more control over what directions
|
||||
* the object will collide from, use collision constants (like LEFT, FLOOR, etc)
|
||||
* to set the value of allowCollisions directly.
|
||||
*/
|
||||
function () {
|
||||
return (this.allowCollisions & Phaser.Collision.ANY) > Phaser.Collision.NONE;
|
||||
},
|
||||
set: function (value) {
|
||||
if(value) {
|
||||
this.allowCollisions = Phaser.Collision.ANY;
|
||||
} else {
|
||||
this.allowCollisions = Phaser.Collision.NONE;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
GameObject.prototype.getMidpoint = /**
|
||||
* Retrieve the midpoint of this object in world coordinates.
|
||||
*
|
||||
* @param point {Point} Allows you to pass in an existing <code>Point</code> object if you're so inclined. Otherwise a new one is created.
|
||||
*
|
||||
* @return {MicroPoint} A <code>Point</code> object containing the midpoint of this object in world coordinates.
|
||||
*/
|
||||
function (point) {
|
||||
if (typeof point === "undefined") { point = null; }
|
||||
if(point == null) {
|
||||
point = new Phaser.MicroPoint();
|
||||
}
|
||||
point.copyFrom(this.frameBounds.center);
|
||||
return point;
|
||||
};
|
||||
GameObject.prototype.reset = /**
|
||||
* Handy for reviving game objects.
|
||||
* Resets their existence flags and position.
|
||||
*
|
||||
* @param x {number} The new X position of this object.
|
||||
* @param y {number} The new Y position of this object.
|
||||
*/
|
||||
function (x, y) {
|
||||
this.revive();
|
||||
this.touching = Phaser.Collision.NONE;
|
||||
this.wasTouching = Phaser.Collision.NONE;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.last.x = x;
|
||||
this.last.y = y;
|
||||
this.velocity.x = 0;
|
||||
this.velocity.y = 0;
|
||||
};
|
||||
GameObject.prototype.isTouching = /**
|
||||
* Handy for checking if this object is touching a particular surface.
|
||||
* For slightly better performance you can just & the value directly into <code>touching</code>.
|
||||
* However, this method is good for readability and accessibility.
|
||||
*
|
||||
* @param Direction {number} Any of the collision flags (e.g. LEFT, FLOOR, etc).
|
||||
*
|
||||
* @return {boolean} Whether the object is touching an object in (any of) the specified direction(s) this frame.
|
||||
*/
|
||||
function (direction) {
|
||||
return (this.touching & direction) > Phaser.Collision.NONE;
|
||||
};
|
||||
GameObject.prototype.justTouched = /**
|
||||
* Handy function for checking if this object just landed on a particular surface.
|
||||
*
|
||||
* @param Direction {number} Any of the collision flags (e.g. LEFT, FLOOR, etc).
|
||||
*
|
||||
* @returns {boolean} Whether the object just landed on any specicied surfaces.
|
||||
*/
|
||||
function (direction) {
|
||||
return ((this.touching & direction) > Phaser.Collision.NONE) && ((this.wasTouching & direction) <= Phaser.Collision.NONE);
|
||||
};
|
||||
GameObject.prototype.hurt = /**
|
||||
* Reduces the "health" variable of this sprite by the amount specified in Damage.
|
||||
* Calls kill() if health drops to or below zero.
|
||||
*
|
||||
* @param Damage {number} How much health to take away (use a negative number to give a health bonus).
|
||||
*/
|
||||
function (damage) {
|
||||
this.health = this.health - damage;
|
||||
if(this.health <= 0) {
|
||||
this.kill();
|
||||
}
|
||||
};
|
||||
GameObject.prototype.setBounds = /**
|
||||
* Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere
|
||||
* in the world. But by setting the bounds (which are given in world dimensions, not screen dimensions)
|
||||
* it can be stopped from leaving the world, or a section of it.
|
||||
*
|
||||
* @param x {number} x position of the bound
|
||||
* @param y {number} y position of the bound
|
||||
* @param width {number} width of its bound
|
||||
* @param height {number} height of its bound
|
||||
*/
|
||||
function (x, y, width, height) {
|
||||
this.worldBounds = new Phaser.Quad(x, y, width, height);
|
||||
};
|
||||
GameObject.prototype.setBoundsFromWorld = /**
|
||||
* Set the world bounds that this GameObject can exist within based on the size of the current game world.
|
||||
*
|
||||
* @param action {number} The action to take if the object hits the world bounds, either OUT_OF_BOUNDS_KILL or OUT_OF_BOUNDS_STOP
|
||||
*/
|
||||
function (action) {
|
||||
if (typeof action === "undefined") { action = Phaser.GameObject.OUT_OF_BOUNDS_STOP; }
|
||||
this.setBounds(this._game.world.bounds.x, this._game.world.bounds.y, this._game.world.bounds.width, this._game.world.bounds.height);
|
||||
this.outOfBoundsAction = action;
|
||||
};
|
||||
GameObject.prototype.hideFromCamera = /**
|
||||
* If you do not wish this object to be visible to a specific camera, pass the camera here.
|
||||
*
|
||||
* @param camera {Camera} The specific camera.
|
||||
*/
|
||||
function (camera) {
|
||||
if(this.cameraBlacklist.indexOf(camera.ID) == -1) {
|
||||
this.cameraBlacklist.push(camera.ID);
|
||||
}
|
||||
};
|
||||
GameObject.prototype.showToCamera = /**
|
||||
* Make this object only visible to a specific camera.
|
||||
*
|
||||
* @param camera {Camera} The camera you wish it to be visible.
|
||||
*/
|
||||
function (camera) {
|
||||
if(this.cameraBlacklist.indexOf(camera.ID) !== -1) {
|
||||
this.cameraBlacklist.slice(this.cameraBlacklist.indexOf(camera.ID), 1);
|
||||
}
|
||||
};
|
||||
GameObject.prototype.clearCameraList = /**
|
||||
* This clears the camera black list, making the GameObject visible to all cameras.
|
||||
*/
|
||||
function () {
|
||||
this.cameraBlacklist.length = 0;
|
||||
};
|
||||
GameObject.prototype.destroy = /**
|
||||
* Clean up memory.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
GameObject.prototype.setPosition = function (x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
};
|
||||
Object.defineProperty(GameObject.prototype, "x", {
|
||||
get: function () {
|
||||
return this.frameBounds.x;
|
||||
},
|
||||
set: function (value) {
|
||||
this.frameBounds.x = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(GameObject.prototype, "y", {
|
||||
get: function () {
|
||||
return this.frameBounds.y;
|
||||
},
|
||||
set: function (value) {
|
||||
this.frameBounds.y = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(GameObject.prototype, "rotation", {
|
||||
get: function () {
|
||||
return this._angle;
|
||||
},
|
||||
set: function (value) {
|
||||
this._angle = this._game.math.wrap(value, 360, 0);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(GameObject.prototype, "angle", {
|
||||
get: function () {
|
||||
return this._angle;
|
||||
},
|
||||
set: function (value) {
|
||||
this._angle = this._game.math.wrap(value, 360, 0);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(GameObject.prototype, "width", {
|
||||
get: function () {
|
||||
return this.frameBounds.width;
|
||||
},
|
||||
set: function (value) {
|
||||
this.frameBounds.width = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(GameObject.prototype, "height", {
|
||||
get: function () {
|
||||
return this.frameBounds.height;
|
||||
},
|
||||
set: function (value) {
|
||||
this.frameBounds.height = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return GameObject;
|
||||
})(Phaser.Basic);
|
||||
Phaser.GameObject = GameObject;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,291 +0,0 @@
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - GameObjectFactory
|
||||
*
|
||||
* A quick way to create new world objects and add existing objects to the current world.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var GameObjectFactory = (function () {
|
||||
/**
|
||||
* GameObjectFactory constructor
|
||||
* @param game {Game} A reference to the current Game.
|
||||
*/
|
||||
function GameObjectFactory(game) {
|
||||
this.game = game;
|
||||
this._world = this.game.world;
|
||||
}
|
||||
/**
|
||||
* Create a new camera with specific position and size.
|
||||
*
|
||||
* @param x {number} X position of the new camera.
|
||||
* @param y {number} Y position of the new camera.
|
||||
* @param width {number} Width of the new camera.
|
||||
* @param height {number} Height of the new camera.
|
||||
* @returns {Camera} The newly created camera object.
|
||||
*/
|
||||
GameObjectFactory.prototype.camera = function (x, y, width, height) {
|
||||
return this._world.cameras.addCamera(x, y, width, height);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new GeomSprite with specific position.
|
||||
*
|
||||
* @param x {number} X position of the new geom sprite.
|
||||
* @param y {number} Y position of the new geom sprite.
|
||||
* @returns {GeomSprite} The newly created geom sprite object.
|
||||
*/
|
||||
//public geomSprite(x: number, y: number): GeomSprite {
|
||||
// return <GeomSprite> this._world.group.add(new GeomSprite(this.game, x, y));
|
||||
//}
|
||||
/**
|
||||
* Create a new Button game object.
|
||||
*
|
||||
* @param [x] {number} X position of the button.
|
||||
* @param [y] {number} Y position of the button.
|
||||
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this button.
|
||||
* @param [callback] {function} The function to call when this button is pressed
|
||||
* @param [callbackContext] {object} The context in which the callback will be called (usually 'this')
|
||||
* @param [overFrame] {string|number} This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @param [outFrame] {string|number} This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @param [downFrame] {string|number} This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @returns {Button} The newly created button object.
|
||||
*/
|
||||
GameObjectFactory.prototype.button = function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof key === "undefined") { key = null; }
|
||||
if (typeof callback === "undefined") { callback = null; }
|
||||
if (typeof callbackContext === "undefined") { callbackContext = null; }
|
||||
if (typeof overFrame === "undefined") { overFrame = null; }
|
||||
if (typeof outFrame === "undefined") { outFrame = null; }
|
||||
if (typeof downFrame === "undefined") { downFrame = null; }
|
||||
return this._world.group.add(new Phaser.UI.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new Sprite with specific position and sprite sheet key.
|
||||
*
|
||||
* @param x {number} X position of the new sprite.
|
||||
* @param y {number} Y position of the new sprite.
|
||||
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
|
||||
* @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
|
||||
* @returns {Sprite} The newly created sprite object.
|
||||
*/
|
||||
GameObjectFactory.prototype.sprite = function (x, y, key, frame) {
|
||||
if (typeof key === "undefined") { key = ''; }
|
||||
if (typeof frame === "undefined") { frame = null; }
|
||||
return this._world.group.add(new Phaser.Sprite(this.game, x, y, key, frame));
|
||||
};
|
||||
|
||||
GameObjectFactory.prototype.audio = function (key, volume, loop) {
|
||||
if (typeof volume === "undefined") { volume = 1; }
|
||||
if (typeof loop === "undefined") { loop = false; }
|
||||
return this.game.sound.add(key, volume, loop);
|
||||
};
|
||||
|
||||
GameObjectFactory.prototype.circle = function (x, y, radius) {
|
||||
return new Phaser.Physics.Circle(this.game, x, y, radius);
|
||||
};
|
||||
|
||||
GameObjectFactory.prototype.aabb = function (x, y, width, height) {
|
||||
return new Phaser.Physics.AABB(this.game, x, y, Math.floor(width / 2), Math.floor(height / 2));
|
||||
};
|
||||
|
||||
GameObjectFactory.prototype.cell = function (x, y, width, height, state) {
|
||||
if (typeof state === "undefined") { state = Phaser.Physics.TileMapCell.TID_FULL; }
|
||||
return new Phaser.Physics.TileMapCell(this.game, x, y, width, height).SetState(state);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new Sprite with the physics automatically created and set to DYNAMIC. The Sprite position offset is set to its center.
|
||||
*
|
||||
* @param x {number} X position of the new sprite.
|
||||
* @param y {number} Y position of the new sprite.
|
||||
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
|
||||
* @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
|
||||
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DYNAMIC)
|
||||
* @param [shapeType] The default body shape is either 0 for a Box or 1 for a Circle. See Sprite.body.addShape for custom shapes (polygons, etc)
|
||||
* @returns {Sprite} The newly created sprite object.
|
||||
*/
|
||||
//public physicsSprite(x: number, y: number, key: string = '', frame? = null, bodyType: number = Phaser.Types.BODY_DYNAMIC, shapeType:number = 0): Sprite {
|
||||
// return <Sprite> this._world.group.add(new Sprite(this.game, x, y, key, frame, bodyType, shapeType));
|
||||
//}
|
||||
/**
|
||||
* Create a new DynamicTexture with specific size.
|
||||
*
|
||||
* @param width {number} Width of the texture.
|
||||
* @param height {number} Height of the texture.
|
||||
* @returns {DynamicTexture} The newly created dynamic texture object.
|
||||
*/
|
||||
GameObjectFactory.prototype.dynamicTexture = function (width, height) {
|
||||
return new Phaser.Display.DynamicTexture(this.game, width, height);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new object container.
|
||||
*
|
||||
* @param maxSize {number} Optional, capacity of this group.
|
||||
* @returns {Group} The newly created group.
|
||||
*/
|
||||
GameObjectFactory.prototype.group = function (maxSize) {
|
||||
if (typeof maxSize === "undefined") { maxSize = 0; }
|
||||
return this._world.group.add(new Phaser.Group(this.game, maxSize));
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new Particle.
|
||||
*
|
||||
* @return {Particle} The newly created particle object.
|
||||
*/
|
||||
//public particle(): Phaser.ArcadeParticle {
|
||||
// return new Phaser.ArcadeParticle(this.game);
|
||||
//}
|
||||
/**
|
||||
* Create a new Emitter.
|
||||
*
|
||||
* @param x {number} Optional, x position of the emitter.
|
||||
* @param y {number} Optional, y position of the emitter.
|
||||
* @param size {number} Optional, size of this emitter.
|
||||
* @return {Emitter} The newly created emitter object.
|
||||
*/
|
||||
//public emitter(x: number = 0, y: number = 0, size: number = 0): Phaser.ArcadeEmitter {
|
||||
// return <Phaser.ArcadeEmitter> this._world.group.add(new Phaser.ArcadeEmitter(this.game, x, y, size));
|
||||
//}
|
||||
/**
|
||||
* Create a new ScrollZone object with image key, position and size.
|
||||
*
|
||||
* @param key {string} Key to a image you wish this object to use.
|
||||
* @param x {number} X position of this object.
|
||||
* @param y {number} Y position of this object.
|
||||
* @param width number} Width of this object.
|
||||
* @param height {number} Height of this object.
|
||||
* @returns {ScrollZone} The newly created scroll zone object.
|
||||
*/
|
||||
GameObjectFactory.prototype.scrollZone = function (key, x, y, width, height) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof width === "undefined") { width = 0; }
|
||||
if (typeof height === "undefined") { height = 0; }
|
||||
return this._world.group.add(new Phaser.ScrollZone(this.game, key, x, y, width, height));
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new Tilemap.
|
||||
*
|
||||
* @param key {string} Key for tileset image.
|
||||
* @param mapData {string} Data of this tilemap.
|
||||
* @param format {number} Format of map data. (Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON)
|
||||
* @param [resizeWorld] {boolean} resize the world to make same as tilemap?
|
||||
* @param [tileWidth] {number} width of each tile.
|
||||
* @param [tileHeight] {number} height of each tile.
|
||||
* @return {Tilemap} The newly created tilemap object.
|
||||
*/
|
||||
GameObjectFactory.prototype.tilemap = function (key, mapData, format, resizeWorld, tileWidth, tileHeight) {
|
||||
if (typeof resizeWorld === "undefined") { resizeWorld = true; }
|
||||
if (typeof tileWidth === "undefined") { tileWidth = 0; }
|
||||
if (typeof tileHeight === "undefined") { tileHeight = 0; }
|
||||
return this._world.group.add(new Phaser.Tilemap(this.game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
|
||||
*
|
||||
* @param obj {object} Object the tween will be run on.
|
||||
* @param [localReference] {bool} If true the tween will be stored in the object.tween property so long as it exists. If already set it'll be over-written.
|
||||
* @return {Phaser.Tween} The newly created tween object.
|
||||
*/
|
||||
GameObjectFactory.prototype.tween = function (obj, localReference) {
|
||||
if (typeof localReference === "undefined") { localReference = false; }
|
||||
return this.game.tweens.create(obj, localReference);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an existing Sprite to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param sprite The Sprite to add to the Game World
|
||||
* @return {Phaser.Sprite} The Sprite object
|
||||
*/
|
||||
GameObjectFactory.prototype.existingSprite = function (sprite) {
|
||||
return this._world.group.add(sprite);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an existing Group to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param group The Group to add to the Game World
|
||||
* @return {Phaser.Group} The Group object
|
||||
*/
|
||||
GameObjectFactory.prototype.existingGroup = function (group) {
|
||||
return this._world.group.add(group);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an existing Button to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param button The Button to add to the Game World
|
||||
* @return {Phaser.Button} The Button object
|
||||
*/
|
||||
GameObjectFactory.prototype.existingButton = function (button) {
|
||||
return this._world.group.add(button);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an existing GeomSprite to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param sprite The GeomSprite to add to the Game World
|
||||
* @return {Phaser.GeomSprite} The GeomSprite object
|
||||
*/
|
||||
//public existingGeomSprite(sprite: GeomSprite): GeomSprite {
|
||||
// return this._world.group.add(sprite);
|
||||
//}
|
||||
/**
|
||||
* Add an existing Emitter to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param emitter The Emitter to add to the Game World
|
||||
* @return {Phaser.Emitter} The Emitter object
|
||||
*/
|
||||
//public existingEmitter(emitter: Phaser.ArcadeEmitter): Phaser.ArcadeEmitter {
|
||||
// return this._world.group.add(emitter);
|
||||
//}
|
||||
/**
|
||||
* Add an existing ScrollZone to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param scrollZone The ScrollZone to add to the Game World
|
||||
* @return {Phaser.ScrollZone} The ScrollZone object
|
||||
*/
|
||||
GameObjectFactory.prototype.existingScrollZone = function (scrollZone) {
|
||||
return this._world.group.add(scrollZone);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an existing Tilemap to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param tilemap The Tilemap to add to the Game World
|
||||
* @return {Phaser.Tilemap} The Tilemap object
|
||||
*/
|
||||
GameObjectFactory.prototype.existingTilemap = function (tilemap) {
|
||||
return this._world.group.add(tilemap);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an existing Tween to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param tween The Tween to add to the Game World
|
||||
* @return {Phaser.Tween} The Tween object
|
||||
*/
|
||||
GameObjectFactory.prototype.existingTween = function (tween) {
|
||||
return this.game.tweens.add(tween);
|
||||
};
|
||||
return GameObjectFactory;
|
||||
})();
|
||||
Phaser.GameObjectFactory = GameObjectFactory;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -89,6 +89,7 @@ module Phaser {
|
||||
return <Phaser.Sound> this.game.sound.add(key, volume, loop);
|
||||
}
|
||||
|
||||
/*
|
||||
public circle(x: number, y: number, radius: number): Phaser.Physics.Circle {
|
||||
return new Phaser.Physics.Circle(this.game, x, y, radius);
|
||||
}
|
||||
@@ -100,6 +101,7 @@ module Phaser {
|
||||
public cell(x: number, y: number, width: number, height: number, state: number = Phaser.Physics.TileMapCell.TID_FULL): Phaser.Physics.TileMapCell {
|
||||
return new Phaser.Physics.TileMapCell(this.game, x, y, width, height).SetState(state);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a new Sprite with the physics automatically created and set to DYNAMIC. The Sprite position offset is set to its center.
|
||||
|
||||
@@ -1,449 +0,0 @@
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../geom/Polygon.ts" />
|
||||
/**
|
||||
* Phaser - GeomSprite
|
||||
*
|
||||
* A GeomSprite is a special kind of GameObject that contains a base geometry class (Circle, Line, Point, Rectangle).
|
||||
* They can be rendered in the game and used for collision just like any other game object. Display of them is controlled
|
||||
* via the lineWidth / lineColor / fillColor and renderOutline / renderFill properties.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var GeomSprite = (function (_super) {
|
||||
__extends(GeomSprite, _super);
|
||||
/**
|
||||
* GeomSprite constructor
|
||||
* Create a new <code>GeomSprite</code>.
|
||||
*
|
||||
* @param game {Phaser.Game} Current game instance.
|
||||
* @param [x] {number} the initial x position of the sprite.
|
||||
* @param [y] {number} the initial y position of the sprite.
|
||||
*/
|
||||
function GeomSprite(game, x, y) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
_super.call(this, game, x, y);
|
||||
// local rendering related temp vars to help avoid gc spikes
|
||||
this._dx = 0;
|
||||
this._dy = 0;
|
||||
this._dw = 0;
|
||||
this._dh = 0;
|
||||
/**
|
||||
* Geom type of this sprite. (available: UNASSIGNED, CIRCLE, LINE, POINT, RECTANGLE)
|
||||
* @type {number}
|
||||
*/
|
||||
this.type = 0;
|
||||
/**
|
||||
* Render outline of this sprite or not. (default is true)
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.renderOutline = true;
|
||||
/**
|
||||
* Fill the shape or not. (default is true)
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.renderFill = true;
|
||||
/**
|
||||
* Width of outline. (default is 1)
|
||||
* @type {number}
|
||||
*/
|
||||
this.lineWidth = 1;
|
||||
/**
|
||||
* Width of outline. (default is 1)
|
||||
* @type {number}
|
||||
*/
|
||||
this.lineColor = 'rgb(0,255,0)';
|
||||
/**
|
||||
* The color of the filled area in rgb or rgba string format
|
||||
* @type {string} Defaults to rgb(0,100,0) - a green color
|
||||
*/
|
||||
this.fillColor = 'rgb(0,100,0)';
|
||||
this.type = GeomSprite.UNASSIGNED;
|
||||
return this;
|
||||
}
|
||||
GeomSprite.UNASSIGNED = 0;
|
||||
GeomSprite.CIRCLE = 1;
|
||||
GeomSprite.LINE = 2;
|
||||
GeomSprite.POINT = 3;
|
||||
GeomSprite.RECTANGLE = 4;
|
||||
GeomSprite.POLYGON = 5;
|
||||
GeomSprite.prototype.loadCircle = /**
|
||||
* Just like Sprite.loadGraphic(), this will load a circle and set its shape to Circle.
|
||||
* @param circle {Circle} Circle geometry define.
|
||||
* @return {GeomSprite} GeomSprite instance itself.
|
||||
*/
|
||||
function (circle) {
|
||||
this.refresh();
|
||||
this.circle = circle;
|
||||
this.type = Phaser.GeomSprite.CIRCLE;
|
||||
return this;
|
||||
};
|
||||
GeomSprite.prototype.loadLine = /**
|
||||
* Just like Sprite.loadGraphic(), this will load a line and set its shape to Line.
|
||||
* @param line {Line} Line geometry define.
|
||||
* @return {GeomSprite} GeomSprite instance itself.
|
||||
*/
|
||||
function (line) {
|
||||
this.refresh();
|
||||
this.line = line;
|
||||
this.type = Phaser.GeomSprite.LINE;
|
||||
return this;
|
||||
};
|
||||
GeomSprite.prototype.loadPoint = /**
|
||||
* Just like Sprite.loadGraphic(), this will load a point and set its shape to Point.
|
||||
* @param point {Point} Point geometry define.
|
||||
* @return {GeomSprite} GeomSprite instance itself.
|
||||
*/
|
||||
function (point) {
|
||||
this.refresh();
|
||||
this.point = point;
|
||||
this.type = Phaser.GeomSprite.POINT;
|
||||
return this;
|
||||
};
|
||||
GeomSprite.prototype.loadRectangle = /**
|
||||
* Just like Sprite.loadGraphic(), this will load a rect and set its shape to Rectangle.
|
||||
* @param rect {Rectangle} Rectangle geometry define.
|
||||
* @return {GeomSprite} GeomSprite instance itself.
|
||||
*/
|
||||
function (rect) {
|
||||
this.refresh();
|
||||
this.rect = rect;
|
||||
this.type = Phaser.GeomSprite.RECTANGLE;
|
||||
return this;
|
||||
};
|
||||
GeomSprite.prototype.createCircle = /**
|
||||
* Create a circle shape with specific diameter.
|
||||
* @param diameter {number} Diameter of the circle.
|
||||
* @return {GeomSprite} GeomSprite instance itself.
|
||||
*/
|
||||
function (diameter) {
|
||||
this.refresh();
|
||||
this.circle = new Phaser.Circle(this.x, this.y, diameter);
|
||||
this.type = Phaser.GeomSprite.CIRCLE;
|
||||
this.frameBounds.setTo(this.circle.x - this.circle.radius, this.circle.y - this.circle.radius, this.circle.diameter, this.circle.diameter);
|
||||
return this;
|
||||
};
|
||||
GeomSprite.prototype.createLine = /**
|
||||
* Create a line shape with specific end point.
|
||||
* @param x {number} X position of the end point.
|
||||
* @param y {number} Y position of the end point.
|
||||
* @return {GeomSprite} GeomSprite instance itself.
|
||||
*/
|
||||
function (x, y) {
|
||||
this.refresh();
|
||||
this.line = new Phaser.Line(this.x, this.y, x, y);
|
||||
this.type = Phaser.GeomSprite.LINE;
|
||||
this.frameBounds.setTo(this.x, this.y, this.line.width, this.line.height);
|
||||
return this;
|
||||
};
|
||||
GeomSprite.prototype.createPoint = /**
|
||||
* Create a point shape at spriter's position.
|
||||
* @return {GeomSprite} GeomSprite instance itself.
|
||||
*/
|
||||
function () {
|
||||
this.refresh();
|
||||
this.point = new Phaser.Point(this.x, this.y);
|
||||
this.type = Phaser.GeomSprite.POINT;
|
||||
this.frameBounds.width = 1;
|
||||
this.frameBounds.height = 1;
|
||||
return this;
|
||||
};
|
||||
GeomSprite.prototype.createRectangle = /**
|
||||
* 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.
|
||||
*/
|
||||
function (width, height) {
|
||||
this.refresh();
|
||||
this.rect = new Phaser.Rectangle(this.x, this.y, width, height);
|
||||
this.type = Phaser.GeomSprite.RECTANGLE;
|
||||
this.frameBounds.copyFrom(this.rect);
|
||||
return this;
|
||||
};
|
||||
GeomSprite.prototype.createPolygon = /**
|
||||
* Create a polygon object
|
||||
* @param width {Number} Width of the rectangle
|
||||
* @param height {Number} Height of the rectangle
|
||||
* @return {GeomSprite} GeomSprite instance.
|
||||
*/
|
||||
function (points) {
|
||||
if (typeof points === "undefined") { points = []; }
|
||||
this.refresh();
|
||||
this.polygon = new Phaser.Polygon(new Vector2(this.x, this.y), points);
|
||||
this.type = Phaser.GeomSprite.POLYGON;
|
||||
//this.frameBounds.copyFrom(this.rect);
|
||||
return this;
|
||||
};
|
||||
GeomSprite.prototype.refresh = /**
|
||||
* Destroy all geom shapes of this sprite.
|
||||
*/
|
||||
function () {
|
||||
this.circle = null;
|
||||
this.line = null;
|
||||
this.point = null;
|
||||
this.rect = null;
|
||||
};
|
||||
GeomSprite.prototype.update = /**
|
||||
* Update bounds.
|
||||
*/
|
||||
function () {
|
||||
// Update bounds and position?
|
||||
if(this.type == Phaser.GeomSprite.UNASSIGNED) {
|
||||
return;
|
||||
} else if(this.type == Phaser.GeomSprite.CIRCLE) {
|
||||
this.circle.x = this.x;
|
||||
this.circle.y = this.y;
|
||||
this.frameBounds.width = this.circle.diameter;
|
||||
this.frameBounds.height = this.circle.diameter;
|
||||
} else if(this.type == Phaser.GeomSprite.LINE) {
|
||||
this.line.x1 = this.x;
|
||||
this.line.y1 = this.y;
|
||||
this.frameBounds.setTo(this.x, this.y, this.line.width, this.line.height);
|
||||
} else if(this.type == Phaser.GeomSprite.POINT) {
|
||||
this.point.x = this.x;
|
||||
this.point.y = this.y;
|
||||
} else if(this.type == Phaser.GeomSprite.RECTANGLE) {
|
||||
this.rect.x = this.x;
|
||||
this.rect.y = this.y;
|
||||
this.frameBounds.copyFrom(this.rect);
|
||||
}
|
||||
};
|
||||
GeomSprite.prototype.inCamera = /**
|
||||
* Check whether this object is visible in a specific camera rectangle.
|
||||
* @param camera {Rectangle} The rectangle you want to check.
|
||||
* @return {boolean} Return true if bounds of this sprite intersects the given rectangle, otherwise return false.
|
||||
*/
|
||||
function (camera) {
|
||||
if(this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0) {
|
||||
this._dx = this.frameBounds.x - (camera.x * this.scrollFactor.x);
|
||||
this._dy = this.frameBounds.y - (camera.y * this.scrollFactor.x);
|
||||
this._dw = this.frameBounds.width * this.scale.x;
|
||||
this._dh = this.frameBounds.height * this.scale.y;
|
||||
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
|
||||
} else {
|
||||
return camera.intersects(this.frameBounds);
|
||||
}
|
||||
};
|
||||
GeomSprite.prototype.render = /**
|
||||
* Render this sprite to specific camera. Called by game loop after update().
|
||||
* @param camera {Camera} Camera this sprite will be rendered to.
|
||||
* @cameraOffsetX {number} X offset to the camera.
|
||||
* @cameraOffsetY {number} Y offset to the camera.
|
||||
* @return {boolean} Return false if not rendered, otherwise return true.
|
||||
*/
|
||||
function (camera, cameraOffsetX, cameraOffsetY) {
|
||||
// Render checks
|
||||
if(this.type == Phaser.GeomSprite.UNASSIGNED || this.visible === false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.cameraBlacklist.indexOf(camera.ID) !== -1 || this.inCamera(camera.worldView) == false) {
|
||||
return false;
|
||||
}
|
||||
// Alpha
|
||||
if(this.alpha !== 1) {
|
||||
var globalAlpha = this.context.globalAlpha;
|
||||
this.context.globalAlpha = this.alpha;
|
||||
}
|
||||
this._dx = cameraOffsetX + (this.frameBounds.x - camera.worldView.x);
|
||||
this._dy = cameraOffsetY + (this.frameBounds.y - camera.worldView.y);
|
||||
this._dw = this.frameBounds.width * this.scale.x;
|
||||
this._dh = this.frameBounds.height * this.scale.y;
|
||||
// Apply camera difference
|
||||
if(this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0) {
|
||||
this._dx -= (camera.worldView.x * this.scrollFactor.x);
|
||||
this._dy -= (camera.worldView.y * this.scrollFactor.y);
|
||||
}
|
||||
// Rotation is disabled for now as I don't want it to be misleading re: collision
|
||||
/*
|
||||
if (this.angle !== 0)
|
||||
{
|
||||
this.context.save();
|
||||
this.context.translate(this._dx + (this._dw / 2) - this.origin.x, this._dy + (this._dh / 2) - this.origin.y);
|
||||
this.context.rotate(this.angle * (Math.PI / 180));
|
||||
this._dx = -(this._dw / 2);
|
||||
this._dy = -(this._dh / 2);
|
||||
}
|
||||
*/
|
||||
this._dx = Math.round(this._dx);
|
||||
this._dy = Math.round(this._dy);
|
||||
this._dw = Math.round(this._dw);
|
||||
this._dh = Math.round(this._dh);
|
||||
this._game.stage.saveCanvasValues();
|
||||
// Debug
|
||||
//this.context.fillStyle = 'rgba(255,0,0,0.5)';
|
||||
//this.context.fillRect(this.frameBounds.x, this.frameBounds.y, this.frameBounds.width, this.frameBounds.height);
|
||||
this.context.lineWidth = this.lineWidth;
|
||||
this.context.strokeStyle = this.lineColor;
|
||||
this.context.fillStyle = this.fillColor;
|
||||
if(this._game.stage.fillStyle !== this.fillColor) {
|
||||
}
|
||||
// Primitive Renderer
|
||||
if(this.type == Phaser.GeomSprite.CIRCLE) {
|
||||
this.context.beginPath();
|
||||
this.context.arc(this._dx, this._dy, this.circle.radius, 0, Math.PI * 2);
|
||||
if(this.renderOutline) {
|
||||
this.context.stroke();
|
||||
}
|
||||
if(this.renderFill) {
|
||||
this.context.fill();
|
||||
}
|
||||
this.context.closePath();
|
||||
} else if(this.type == Phaser.GeomSprite.LINE) {
|
||||
this.context.beginPath();
|
||||
this.context.moveTo(this._dx, this._dy);
|
||||
this.context.lineTo(this.line.x2, this.line.y2);
|
||||
this.context.stroke();
|
||||
this.context.closePath();
|
||||
} else if(this.type == Phaser.GeomSprite.POINT) {
|
||||
this.context.fillRect(this._dx, this._dy, 2, 2);
|
||||
} else if(this.type == Phaser.GeomSprite.RECTANGLE) {
|
||||
// We can use the faster fillRect if we don't need the outline
|
||||
if(this.renderOutline == false) {
|
||||
this.context.fillRect(this._dx, this._dy, this.rect.width, this.rect.height);
|
||||
} else {
|
||||
this.context.beginPath();
|
||||
this.context.rect(this._dx, this._dy, this.rect.width, this.rect.height);
|
||||
this.context.stroke();
|
||||
if(this.renderFill) {
|
||||
this.context.fill();
|
||||
}
|
||||
this.context.closePath();
|
||||
}
|
||||
// And now the edge points
|
||||
this.context.fillStyle = 'rgb(255,255,255)';
|
||||
//this.renderPoint(this.rect.topLeft, this._dx, this._dy, 2);
|
||||
//this.renderPoint(this.rect.topCenter, this._dx, this._dy, 2);
|
||||
//this.renderPoint(this.rect.topRight, this._dx, this._dy, 2);
|
||||
//this.renderPoint(this.rect.leftCenter, this._dx, this._dy, 2);
|
||||
//this.renderPoint(this.rect.center, this._dx, this._dy, 2);
|
||||
//this.renderPoint(this.rect.rightCenter, this._dx, this._dy, 2);
|
||||
//this.renderPoint(this.rect.bottomLeft, this._dx, this._dy, 2);
|
||||
//this.renderPoint(this.rect.bottomCenter, this._dx, this._dy, 2);
|
||||
//this.renderPoint(this.rect.bottomRight, this._dx, this._dy, 2);
|
||||
this.renderPoint(this.rect.topLeft, 0, 0, 2);
|
||||
this.renderPoint(this.rect.topCenter, 0, 0, 2);
|
||||
this.renderPoint(this.rect.topRight, 0, 0, 2);
|
||||
this.renderPoint(this.rect.leftCenter, 0, 0, 2);
|
||||
this.renderPoint(this.rect.center, 0, 0, 2);
|
||||
this.renderPoint(this.rect.rightCenter, 0, 0, 2);
|
||||
this.renderPoint(this.rect.bottomLeft, 0, 0, 2);
|
||||
this.renderPoint(this.rect.bottomCenter, 0, 0, 2);
|
||||
this.renderPoint(this.rect.bottomRight, 0, 0, 2);
|
||||
}
|
||||
this._game.stage.restoreCanvasValues();
|
||||
if(this.rotation !== 0) {
|
||||
this.context.translate(0, 0);
|
||||
this.context.restore();
|
||||
}
|
||||
if(globalAlpha > -1) {
|
||||
this.context.globalAlpha = globalAlpha;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
GeomSprite.prototype.renderPoint = /**
|
||||
* Render a point of geometry.
|
||||
* @param point {Point} Position of the point.
|
||||
* @param offsetX {number} X offset to its position.
|
||||
* @param offsetY {number} Y offset to its position.
|
||||
* @param [size] {number} point size.
|
||||
*/
|
||||
function (point, offsetX, offsetY, size) {
|
||||
if (typeof offsetX === "undefined") { offsetX = 0; }
|
||||
if (typeof offsetY === "undefined") { offsetY = 0; }
|
||||
if (typeof size === "undefined") { size = 1; }
|
||||
this.context.fillRect(offsetX + point.x, offsetY + point.y, size, size);
|
||||
};
|
||||
GeomSprite.prototype.renderDebugInfo = /**
|
||||
* Render debug infos. (this method does not work now)
|
||||
* @param x {number} X position of the debug info to be rendered.
|
||||
* @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)
|
||||
*/
|
||||
function (x, y, color) {
|
||||
if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
|
||||
//this.context.fillStyle = color;
|
||||
//this.context.fillText('Sprite: ' + this.name + ' (' + this.frameBounds.width + ' x ' + this.frameBounds.height + ')', x, y);
|
||||
//this.context.fillText('x: ' + this.frameBounds.x.toFixed(1) + ' y: ' + this.frameBounds.y.toFixed(1) + ' rotation: ' + this.angle.toFixed(1), x, y + 14);
|
||||
//this.context.fillText('dx: ' + this._dx.toFixed(1) + ' dy: ' + this._dy.toFixed(1) + ' dw: ' + this._dw.toFixed(1) + ' dh: ' + this._dh.toFixed(1), x, y + 28);
|
||||
//this.context.fillText('sx: ' + this._sx.toFixed(1) + ' sy: ' + this._sy.toFixed(1) + ' sw: ' + this._sw.toFixed(1) + ' sh: ' + this._sh.toFixed(1), x, y + 42);
|
||||
};
|
||||
GeomSprite.prototype.collide = /**
|
||||
* Gives a basic boolean response to a geometric collision.
|
||||
* If you need the details of the collision use the Collision functions instead and inspect the IntersectResult object.
|
||||
* @param source {GeomSprite} Sprite you want to check.
|
||||
* @return {boolean} Whether they overlaps or not.
|
||||
*/
|
||||
function (source) {
|
||||
// Circle vs. Circle
|
||||
if(this.type == Phaser.GeomSprite.CIRCLE && source.type == Phaser.GeomSprite.CIRCLE) {
|
||||
return Phaser.Collision.circleToCircle(this.circle, source.circle).result;
|
||||
}
|
||||
// Circle vs. Rect
|
||||
if(this.type == Phaser.GeomSprite.CIRCLE && source.type == Phaser.GeomSprite.RECTANGLE) {
|
||||
return Phaser.Collision.circleToRectangle(this.circle, source.rect).result;
|
||||
}
|
||||
// Circle vs. Point
|
||||
if(this.type == Phaser.GeomSprite.CIRCLE && source.type == Phaser.GeomSprite.POINT) {
|
||||
return Phaser.Collision.circleContainsPoint(this.circle, source.point).result;
|
||||
}
|
||||
// Circle vs. Line
|
||||
if(this.type == Phaser.GeomSprite.CIRCLE && source.type == Phaser.GeomSprite.LINE) {
|
||||
return Phaser.Collision.lineToCircle(source.line, this.circle).result;
|
||||
}
|
||||
// Rect vs. Rect
|
||||
if(this.type == Phaser.GeomSprite.RECTANGLE && source.type == Phaser.GeomSprite.RECTANGLE) {
|
||||
return Phaser.Collision.rectangleToRectangle(this.rect, source.rect).result;
|
||||
}
|
||||
// Rect vs. Circle
|
||||
if(this.type == Phaser.GeomSprite.RECTANGLE && source.type == Phaser.GeomSprite.CIRCLE) {
|
||||
return Phaser.Collision.circleToRectangle(source.circle, this.rect).result;
|
||||
}
|
||||
// Rect vs. Point
|
||||
if(this.type == Phaser.GeomSprite.RECTANGLE && source.type == Phaser.GeomSprite.POINT) {
|
||||
return Phaser.Collision.pointToRectangle(source.point, this.rect).result;
|
||||
}
|
||||
// Rect vs. Line
|
||||
if(this.type == Phaser.GeomSprite.RECTANGLE && source.type == Phaser.GeomSprite.LINE) {
|
||||
return Phaser.Collision.lineToRectangle(source.line, this.rect).result;
|
||||
}
|
||||
// Point vs. Point
|
||||
if(this.type == Phaser.GeomSprite.POINT && source.type == Phaser.GeomSprite.POINT) {
|
||||
return this.point.equals(source.point);
|
||||
}
|
||||
// Point vs. Circle
|
||||
if(this.type == Phaser.GeomSprite.POINT && source.type == Phaser.GeomSprite.CIRCLE) {
|
||||
return Phaser.Collision.circleContainsPoint(source.circle, this.point).result;
|
||||
}
|
||||
// Point vs. Rect
|
||||
if(this.type == Phaser.GeomSprite.POINT && source.type == Phaser.GeomSprite.RECTANGLE) {
|
||||
return Phaser.Collision.pointToRectangle(this.point, source.rect).result;
|
||||
}
|
||||
// Point vs. Line
|
||||
if(this.type == Phaser.GeomSprite.POINT && source.type == Phaser.GeomSprite.LINE) {
|
||||
return source.line.isPointOnLine(this.point.x, this.point.y);
|
||||
}
|
||||
// Line vs. Line
|
||||
if(this.type == Phaser.GeomSprite.LINE && source.type == Phaser.GeomSprite.LINE) {
|
||||
return Phaser.Collision.lineSegmentToLineSegment(this.line, source.line).result;
|
||||
}
|
||||
// Line vs. Circle
|
||||
if(this.type == Phaser.GeomSprite.LINE && source.type == Phaser.GeomSprite.CIRCLE) {
|
||||
return Phaser.Collision.lineToCircle(this.line, source.circle).result;
|
||||
}
|
||||
// Line vs. Rect
|
||||
if(this.type == Phaser.GeomSprite.LINE && source.type == Phaser.GeomSprite.RECTANGLE) {
|
||||
return Phaser.Collision.lineSegmentToRectangle(this.line, source.rect).result;
|
||||
}
|
||||
// Line vs. Point
|
||||
if(this.type == Phaser.GeomSprite.LINE && source.type == Phaser.GeomSprite.POINT) {
|
||||
return this.line.isPointOnLine(source.point.x, source.point.y);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
return GeomSprite;
|
||||
})(Phaser.GameObject);
|
||||
Phaser.GeomSprite = GeomSprite;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1 +0,0 @@
|
||||
/// <reference path="../_definitions.ts" />
|
||||
@@ -1,74 +0,0 @@
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="Sprite.ts" />
|
||||
/**
|
||||
* Phaser - Particle
|
||||
*
|
||||
* This is a simple particle class that extends a Sprite to have a slightly more
|
||||
* specialised behaviour. It is used exclusively by the Emitter class and can be extended as required.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Particle = (function (_super) {
|
||||
__extends(Particle, _super);
|
||||
/**
|
||||
* Instantiate a new particle. Like <code>Sprite</code>, all meaningful creation
|
||||
* happens during <code>loadGraphic()</code> or <code>makeGraphic()</code> or whatever.
|
||||
*/
|
||||
function Particle(game) {
|
||||
_super.call(this, game);
|
||||
this.lifespan = 0;
|
||||
this.friction = 500;
|
||||
}
|
||||
Particle.prototype.update = /**
|
||||
* The particle's main update logic. Basically it checks to see if it should
|
||||
* be dead yet, and then has some special bounce behavior if there is some gravity on it.
|
||||
*/
|
||||
function () {
|
||||
//lifespan behavior
|
||||
if(this.lifespan <= 0) {
|
||||
return;
|
||||
}
|
||||
this.lifespan -= this._game.time.elapsed;
|
||||
if(this.lifespan <= 0) {
|
||||
this.kill();
|
||||
}
|
||||
//simpler bounce/spin behavior for now
|
||||
if(this.touching) {
|
||||
if(this.angularVelocity != 0) {
|
||||
this.angularVelocity = -this.angularVelocity;
|
||||
}
|
||||
}
|
||||
if(this.acceleration.y > 0)//special behavior for particles with gravity
|
||||
{
|
||||
if(this.touching & Phaser.Collision.FLOOR) {
|
||||
this.drag.x = this.friction;
|
||||
if(!(this.wasTouching & Phaser.Collision.FLOOR)) {
|
||||
if(this.velocity.y < -this.elasticity * 10) {
|
||||
if(this.angularVelocity != 0) {
|
||||
this.angularVelocity *= -this.elasticity;
|
||||
}
|
||||
} else {
|
||||
this.velocity.y = 0;
|
||||
this.angularVelocity = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.drag.x = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
Particle.prototype.onEmit = /**
|
||||
* Triggered whenever this object is launched by a <code>Emitter</code>.
|
||||
* You can override this to add custom behavior like a sound or AI or something.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
return Particle;
|
||||
})(Phaser.Sprite);
|
||||
Phaser.Particle = Particle;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,167 +0,0 @@
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - ScrollRegion
|
||||
*
|
||||
* Creates a scrolling region within a ScrollZone.
|
||||
* It is scrolled via the scrollSpeed.x/y properties.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var ScrollRegion = (function () {
|
||||
/**
|
||||
* ScrollRegion constructor
|
||||
* Create a new <code>ScrollRegion</code>.
|
||||
*
|
||||
* @param x {number} X position in world coordinate.
|
||||
* @param y {number} Y position in world coordinate.
|
||||
* @param width {number} Width of this object.
|
||||
* @param height {number} Height of this object.
|
||||
* @param speedX {number} X-axis scrolling speed.
|
||||
* @param speedY {number} Y-axis scrolling speed.
|
||||
*/
|
||||
function ScrollRegion(x, y, width, height, speedX, speedY) {
|
||||
this._anchorWidth = 0;
|
||||
this._anchorHeight = 0;
|
||||
this._inverseWidth = 0;
|
||||
this._inverseHeight = 0;
|
||||
/**
|
||||
* Will this region be rendered? (default to true)
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.visible = true;
|
||||
// Our seamless scrolling quads
|
||||
this._A = new Phaser.Rectangle(x, y, width, height);
|
||||
this._B = new Phaser.Rectangle(x, y, width, height);
|
||||
this._C = new Phaser.Rectangle(x, y, width, height);
|
||||
this._D = new Phaser.Rectangle(x, y, width, height);
|
||||
this._scroll = new Phaser.Vec2();
|
||||
this._bounds = new Phaser.Rectangle(x, y, width, height);
|
||||
this.scrollSpeed = new Phaser.Vec2(speedX, speedY);
|
||||
}
|
||||
/**
|
||||
* Update region scrolling with tick time.
|
||||
* @param delta {number} Elapsed time since last update.
|
||||
*/
|
||||
ScrollRegion.prototype.update = function (delta) {
|
||||
this._scroll.x += this.scrollSpeed.x;
|
||||
this._scroll.y += this.scrollSpeed.y;
|
||||
|
||||
if (this._scroll.x > this._bounds.right) {
|
||||
this._scroll.x = this._bounds.x;
|
||||
}
|
||||
|
||||
if (this._scroll.x < this._bounds.x) {
|
||||
this._scroll.x = this._bounds.right;
|
||||
}
|
||||
|
||||
if (this._scroll.y > this._bounds.bottom) {
|
||||
this._scroll.y = this._bounds.y;
|
||||
}
|
||||
|
||||
if (this._scroll.y < this._bounds.y) {
|
||||
this._scroll.y = this._bounds.bottom;
|
||||
}
|
||||
|
||||
// Anchor Dimensions
|
||||
this._anchorWidth = (this._bounds.width - this._scroll.x) + this._bounds.x;
|
||||
this._anchorHeight = (this._bounds.height - this._scroll.y) + this._bounds.y;
|
||||
|
||||
if (this._anchorWidth > this._bounds.width) {
|
||||
this._anchorWidth = this._bounds.width;
|
||||
}
|
||||
|
||||
if (this._anchorHeight > this._bounds.height) {
|
||||
this._anchorHeight = this._bounds.height;
|
||||
}
|
||||
|
||||
this._inverseWidth = this._bounds.width - this._anchorWidth;
|
||||
this._inverseHeight = this._bounds.height - this._anchorHeight;
|
||||
|
||||
// Rectangle A
|
||||
this._A.setTo(this._scroll.x, this._scroll.y, this._anchorWidth, this._anchorHeight);
|
||||
|
||||
// Rectangle B
|
||||
this._B.y = this._scroll.y;
|
||||
this._B.width = this._inverseWidth;
|
||||
this._B.height = this._anchorHeight;
|
||||
|
||||
// Rectangle C
|
||||
this._C.x = this._scroll.x;
|
||||
this._C.width = this._anchorWidth;
|
||||
this._C.height = this._inverseHeight;
|
||||
|
||||
// Rectangle D
|
||||
this._D.width = this._inverseWidth;
|
||||
this._D.height = this._inverseHeight;
|
||||
};
|
||||
|
||||
/**
|
||||
* Render this region to specific context.
|
||||
* @param context {CanvasRenderingContext2D} Canvas context this region will be rendered to.
|
||||
* @param texture {object} The texture to be rendered.
|
||||
* @param dx {number} X position in world coordinate.
|
||||
* @param dy {number} Y position in world coordinate.
|
||||
* @param width {number} Width of this region to be rendered.
|
||||
* @param height {number} Height of this region to be rendered.
|
||||
*/
|
||||
ScrollRegion.prototype.render = function (context, texture, dx, dy, dw, dh) {
|
||||
if (this.visible == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// dx/dy are the world coordinates to render the FULL ScrollZone into.
|
||||
// This ScrollRegion may be smaller than that and offset from the dx/dy coordinates.
|
||||
this.crop(context, texture, this._A.x, this._A.y, this._A.width, this._A.height, dx, dy, dw, dh, 0, 0);
|
||||
this.crop(context, texture, this._B.x, this._B.y, this._B.width, this._B.height, dx, dy, dw, dh, this._A.width, 0);
|
||||
this.crop(context, texture, this._C.x, this._C.y, this._C.width, this._C.height, dx, dy, dw, dh, 0, this._A.height);
|
||||
this.crop(context, texture, this._D.x, this._D.y, this._D.width, this._D.height, dx, dy, dw, dh, this._C.width, this._A.height);
|
||||
//context.fillStyle = 'rgb(255,255,255)';
|
||||
//context.font = '18px Arial';
|
||||
//context.fillText('RectangleA: ' + this._A.toString(), 32, 450);
|
||||
//context.fillText('RectangleB: ' + this._B.toString(), 32, 480);
|
||||
//context.fillText('RectangleC: ' + this._C.toString(), 32, 510);
|
||||
//context.fillText('RectangleD: ' + this._D.toString(), 32, 540);
|
||||
};
|
||||
|
||||
/**
|
||||
* Crop part of the texture and render it to the given context.
|
||||
* @param context {CanvasRenderingContext2D} Canvas context the texture will be rendered to.
|
||||
* @param texture {object} Texture to be rendered.
|
||||
* @param srcX {number} Target region top-left x coordinate in the texture.
|
||||
* @param srcX {number} Target region top-left y coordinate in the texture.
|
||||
* @param srcW {number} Target region width in the texture.
|
||||
* @param srcH {number} Target region height in the texture.
|
||||
* @param destX {number} Render region top-left x coordinate in the context.
|
||||
* @param destX {number} Render region top-left y coordinate in the context.
|
||||
* @param destW {number} Target region width in the context.
|
||||
* @param destH {number} Target region height in the context.
|
||||
* @param offsetX {number} X offset to the context.
|
||||
* @param offsetY {number} Y offset to the context.
|
||||
*/
|
||||
ScrollRegion.prototype.crop = function (context, texture, srcX, srcY, srcW, srcH, destX, destY, destW, destH, offsetX, offsetY) {
|
||||
offsetX += destX;
|
||||
offsetY += destY;
|
||||
|
||||
if (srcW > (destX + destW) - offsetX) {
|
||||
srcW = (destX + destW) - offsetX;
|
||||
}
|
||||
|
||||
if (srcH > (destY + destH) - offsetY) {
|
||||
srcH = (destY + destH) - offsetY;
|
||||
}
|
||||
|
||||
srcX = Math.floor(srcX);
|
||||
srcY = Math.floor(srcY);
|
||||
srcW = Math.floor(srcW);
|
||||
srcH = Math.floor(srcH);
|
||||
offsetX = Math.floor(offsetX + this._bounds.x);
|
||||
offsetY = Math.floor(offsetY + this._bounds.y);
|
||||
|
||||
if (srcW > 0 && srcH > 0) {
|
||||
context.drawImage(texture, srcX, srcY, srcW, srcH, offsetX, offsetY, srcW, srcH);
|
||||
}
|
||||
};
|
||||
return ScrollRegion;
|
||||
})();
|
||||
Phaser.ScrollRegion = ScrollRegion;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,126 +0,0 @@
|
||||
/// <reference path="../_definitions.ts" />
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
/**
|
||||
* Phaser - ScrollZone
|
||||
*
|
||||
* Creates a scrolling region of the given width and height from an image in the cache.
|
||||
* The ScrollZone can be positioned anywhere in-world like a normal game object, re-act to physics, collision, etc.
|
||||
* The image within it is scrolled via ScrollRegions and their scrollSpeed.x/y properties.
|
||||
* If you create a scroll zone larger than the given source image it will create a DynamicTexture and fill it with a pattern of the source image.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var ScrollZone = (function (_super) {
|
||||
__extends(ScrollZone, _super);
|
||||
/**
|
||||
* ScrollZone constructor
|
||||
* Create a new <code>ScrollZone</code>.
|
||||
*
|
||||
* @param game {Phaser.Game} Current game instance.
|
||||
* @param key {string} Asset key for image texture of this object.
|
||||
* @param x {number} X position in world coordinate.
|
||||
* @param y {number} Y position in world coordinate.
|
||||
* @param [width] {number} width of this object.
|
||||
* @param [height] {number} height of this object.
|
||||
*/
|
||||
function ScrollZone(game, key, x, y, width, height) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof width === "undefined") { width = 0; }
|
||||
if (typeof height === "undefined") { height = 0; }
|
||||
_super.call(this, game, x, y, key);
|
||||
|
||||
this.type = Phaser.Types.SCROLLZONE;
|
||||
|
||||
this.regions = [];
|
||||
|
||||
if (this.texture.loaded) {
|
||||
if (width > this.width || height > this.height) {
|
||||
// Create our repeating texture (as the source image wasn't large enough for the requested size)
|
||||
this.createRepeatingTexture(width, height);
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
// Create a default ScrollRegion at the requested size
|
||||
this.addRegion(0, 0, this.width, this.height);
|
||||
|
||||
if ((width < this.width || height < this.height) && width !== 0 && height !== 0) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Add a new region to this zone.
|
||||
* @param x {number} X position of the new region.
|
||||
* @param y {number} Y position of the new region.
|
||||
* @param width {number} Width of the new region.
|
||||
* @param height {number} Height of the new region.
|
||||
* @param [speedX] {number} x-axis scrolling speed.
|
||||
* @param [speedY] {number} y-axis scrolling speed.
|
||||
* @return {ScrollRegion} The newly added region.
|
||||
*/
|
||||
ScrollZone.prototype.addRegion = function (x, y, width, height, speedX, speedY) {
|
||||
if (typeof speedX === "undefined") { speedX = 0; }
|
||||
if (typeof speedY === "undefined") { speedY = 0; }
|
||||
if (x > this.width || y > this.height || x < 0 || y < 0 || (x + width) > this.width || (y + height) > this.height) {
|
||||
throw Error('Invalid ScrollRegion defined. Cannot be larger than parent ScrollZone');
|
||||
return null;
|
||||
}
|
||||
|
||||
this.currentRegion = new Phaser.ScrollRegion(x, y, width, height, speedX, speedY);
|
||||
|
||||
this.regions.push(this.currentRegion);
|
||||
|
||||
return this.currentRegion;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set scrolling speed of current region.
|
||||
* @param x {number} X speed of current region.
|
||||
* @param y {number} Y speed of current region.
|
||||
*/
|
||||
ScrollZone.prototype.setSpeed = function (x, y) {
|
||||
if (this.currentRegion) {
|
||||
this.currentRegion.scrollSpeed.setTo(x, y);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Update regions.
|
||||
*/
|
||||
ScrollZone.prototype.update = function () {
|
||||
for (var i = 0; i < this.regions.length; i++) {
|
||||
this.regions[i].update(this.game.time.delta);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create repeating texture with _texture, and store it into the _dynamicTexture.
|
||||
* Used to create texture when texture image is small than size of the zone.
|
||||
*/
|
||||
ScrollZone.prototype.createRepeatingTexture = function (regionWidth, regionHeight) {
|
||||
// Work out how many we'll need of the source image to make it tile properly
|
||||
var tileWidth = Math.ceil(this.width / regionWidth) * regionWidth;
|
||||
var tileHeight = Math.ceil(this.height / regionHeight) * regionHeight;
|
||||
|
||||
var dt = new Phaser.Display.DynamicTexture(this.game, tileWidth, tileHeight);
|
||||
|
||||
dt.context.rect(0, 0, tileWidth, tileHeight);
|
||||
dt.context.fillStyle = dt.context.createPattern(this.texture.imageTexture, "repeat");
|
||||
dt.context.fill();
|
||||
|
||||
this.texture.loadDynamicTexture(dt);
|
||||
};
|
||||
return ScrollZone;
|
||||
})(Phaser.Sprite);
|
||||
Phaser.ScrollZone = ScrollZone;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,301 +0,0 @@
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Sprite
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Sprite = (function () {
|
||||
/**
|
||||
* Create a new <code>Sprite</code>.
|
||||
*
|
||||
* @param game {Phaser.Game} Current game instance.
|
||||
* @param [x] {number} the initial x position of the sprite.
|
||||
* @param [y] {number} the initial y position of the sprite.
|
||||
* @param [key] {string} Key of the graphic you want to load for this sprite.
|
||||
*/
|
||||
function Sprite(game, x, y, key, frame) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof key === "undefined") { key = null; }
|
||||
if (typeof frame === "undefined") { frame = null; }
|
||||
/**
|
||||
* A boolean representing if the Sprite has been modified in any way via a scale, rotate, flip or skew.
|
||||
*/
|
||||
this.modified = false;
|
||||
/**
|
||||
* x value of the object.
|
||||
*/
|
||||
this.x = 0;
|
||||
/**
|
||||
* y value of the object.
|
||||
*/
|
||||
this.y = 0;
|
||||
/**
|
||||
* z order value of the object.
|
||||
*/
|
||||
this.z = -1;
|
||||
/**
|
||||
* Render iteration counter
|
||||
*/
|
||||
this.renderOrderID = 0;
|
||||
this.game = game;
|
||||
this.type = Phaser.Types.SPRITE;
|
||||
|
||||
this.exists = true;
|
||||
this.active = true;
|
||||
this.visible = true;
|
||||
this.alive = true;
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = -1;
|
||||
this.group = null;
|
||||
this.name = '';
|
||||
|
||||
this.events = new Phaser.Components.Events(this);
|
||||
this.animations = new Phaser.Components.AnimationManager(this);
|
||||
this.input = new Phaser.Components.InputHandler(this);
|
||||
this.texture = new Phaser.Display.Texture(this);
|
||||
this.transform = new Phaser.Components.TransformManager(this);
|
||||
|
||||
if (key !== null) {
|
||||
this.texture.loadImage(key, false);
|
||||
} else {
|
||||
this.texture.opaque = true;
|
||||
}
|
||||
|
||||
if (frame !== null) {
|
||||
if (typeof frame == 'string') {
|
||||
this.frameName = frame;
|
||||
} else {
|
||||
this.frame = frame;
|
||||
}
|
||||
}
|
||||
|
||||
this.worldView = new Phaser.Rectangle(x, y, this.width, this.height);
|
||||
this.cameraView = new Phaser.Rectangle(x, y, this.width, this.height);
|
||||
|
||||
this.transform.setCache();
|
||||
|
||||
this.outOfBounds = false;
|
||||
this.outOfBoundsAction = Phaser.Types.OUT_OF_BOUNDS_PERSIST;
|
||||
|
||||
// Handy proxies
|
||||
this.scale = this.transform.scale;
|
||||
this.alpha = this.texture.alpha;
|
||||
this.origin = this.transform.origin;
|
||||
this.crop = this.texture.crop;
|
||||
}
|
||||
Object.defineProperty(Sprite.prototype, "rotation", {
|
||||
get: /**
|
||||
* The rotation of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
|
||||
*/
|
||||
function () {
|
||||
return this.transform.rotation;
|
||||
},
|
||||
set: /**
|
||||
* Set the rotation of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
|
||||
* The value is automatically wrapped to be between 0 and 360.
|
||||
*/
|
||||
function (value) {
|
||||
this.transform.rotation = this.game.math.wrap(value, 360, 0);
|
||||
|
||||
if (this.body) {
|
||||
//this.body.angle = this.game.math.degreesToRadians(this.game.math.wrap(value, 360, 0));
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Brings this Sprite to the top of its current Group, if set.
|
||||
*/
|
||||
Sprite.prototype.bringToTop = function () {
|
||||
if (this.group) {
|
||||
this.group.bringToTop(this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Object.defineProperty(Sprite.prototype, "alpha", {
|
||||
get: /**
|
||||
* The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
|
||||
*/
|
||||
function () {
|
||||
return this.texture.alpha;
|
||||
},
|
||||
set: /**
|
||||
* The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
|
||||
*/
|
||||
function (value) {
|
||||
this.texture.alpha = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
|
||||
Object.defineProperty(Sprite.prototype, "frame", {
|
||||
get: /**
|
||||
* Get the animation frame number.
|
||||
*/
|
||||
function () {
|
||||
return this.animations.frame;
|
||||
},
|
||||
set: /**
|
||||
* Set the animation frame by frame number.
|
||||
*/
|
||||
function (value) {
|
||||
this.animations.frame = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
|
||||
Object.defineProperty(Sprite.prototype, "frameName", {
|
||||
get: /**
|
||||
* Get the animation frame name.
|
||||
*/
|
||||
function () {
|
||||
return this.animations.frameName;
|
||||
},
|
||||
set: /**
|
||||
* Set the animation frame by frame name.
|
||||
*/
|
||||
function (value) {
|
||||
this.animations.frameName = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
|
||||
Object.defineProperty(Sprite.prototype, "width", {
|
||||
get: function () {
|
||||
return this.texture.width * this.transform.scale.x;
|
||||
},
|
||||
set: function (value) {
|
||||
this.transform.scale.x = value / this.texture.width;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
|
||||
Object.defineProperty(Sprite.prototype, "height", {
|
||||
get: function () {
|
||||
return this.texture.height * this.transform.scale.y;
|
||||
},
|
||||
set: function (value) {
|
||||
this.transform.scale.y = value / this.texture.height;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
* Pre-update is called right before update() on each object in the game loop.
|
||||
*/
|
||||
Sprite.prototype.preUpdate = function () {
|
||||
this.transform.update();
|
||||
|
||||
if (this.transform.scrollFactor.x != 1 && this.transform.scrollFactor.x != 0) {
|
||||
this.worldView.x = (this.x * this.transform.scrollFactor.x) - (this.width * this.transform.origin.x);
|
||||
} else {
|
||||
this.worldView.x = this.x - (this.width * this.transform.origin.x);
|
||||
}
|
||||
|
||||
if (this.transform.scrollFactor.y != 1 && this.transform.scrollFactor.y != 0) {
|
||||
this.worldView.y = (this.y * this.transform.scrollFactor.y) - (this.height * this.transform.origin.y);
|
||||
} else {
|
||||
this.worldView.y = this.y - (this.height * this.transform.origin.y);
|
||||
}
|
||||
|
||||
this.worldView.width = this.width;
|
||||
this.worldView.height = this.height;
|
||||
|
||||
if (this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
|
||||
this.modified = true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Override this function to update your sprites position and appearance.
|
||||
*/
|
||||
Sprite.prototype.update = function () {
|
||||
};
|
||||
|
||||
/**
|
||||
* Automatically called after update() by the game loop for all 'alive' objects.
|
||||
*/
|
||||
Sprite.prototype.postUpdate = function () {
|
||||
this.animations.update();
|
||||
|
||||
this.checkBounds();
|
||||
|
||||
if (this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
|
||||
this.modified = false;
|
||||
}
|
||||
};
|
||||
|
||||
Sprite.prototype.checkBounds = function () {
|
||||
if (Phaser.RectangleUtils.intersects(this.worldView, this.game.world.bounds)) {
|
||||
this.outOfBounds = false;
|
||||
} else {
|
||||
if (this.outOfBounds == false) {
|
||||
this.events.onOutOfBounds.dispatch(this);
|
||||
}
|
||||
|
||||
this.outOfBounds = true;
|
||||
|
||||
if (this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_KILL) {
|
||||
this.kill();
|
||||
} else if (this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_DESTROY) {
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clean up memory.
|
||||
*/
|
||||
Sprite.prototype.destroy = function () {
|
||||
this.input.destroy();
|
||||
};
|
||||
|
||||
/**
|
||||
* Handy for "killing" game objects.
|
||||
* Default behavior is to flag them as nonexistent AND dead.
|
||||
* However, if you want the "corpse" to remain in the game,
|
||||
* like to animate an effect or whatever, you should override this,
|
||||
* setting only alive to false, and leaving exists true.
|
||||
*/
|
||||
Sprite.prototype.kill = function (removeFromGroup) {
|
||||
if (typeof removeFromGroup === "undefined") { removeFromGroup = false; }
|
||||
this.alive = false;
|
||||
this.exists = false;
|
||||
|
||||
if (removeFromGroup && this.group) {
|
||||
//this.group.remove(this);
|
||||
}
|
||||
|
||||
this.events.onKilled.dispatch(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handy for bringing game objects "back to life". Just sets alive and exists back to true.
|
||||
* In practice, this is most often called by <code>Object.reset()</code>.
|
||||
*/
|
||||
Sprite.prototype.revive = function () {
|
||||
this.alive = true;
|
||||
this.exists = true;
|
||||
|
||||
this.events.onRevived.dispatch(this);
|
||||
};
|
||||
return Sprite;
|
||||
})();
|
||||
Phaser.Sprite = Sprite;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -64,6 +64,8 @@ module Phaser {
|
||||
|
||||
this.transform.setCache();
|
||||
|
||||
//this.body = new Phaser.Physics.Body(this, 0);
|
||||
|
||||
this.outOfBounds = false;
|
||||
this.outOfBoundsAction = Phaser.Types.OUT_OF_BOUNDS_PERSIST;
|
||||
|
||||
@@ -126,12 +128,6 @@ module Phaser {
|
||||
*/
|
||||
public outOfBoundsAction: number;
|
||||
|
||||
/**
|
||||
* Sprite physics body.
|
||||
*/
|
||||
//public body: Phaser.Physics.Body = null;
|
||||
public body;
|
||||
|
||||
/**
|
||||
* The texture used to render the Sprite.
|
||||
*/
|
||||
@@ -152,6 +148,12 @@ module Phaser {
|
||||
*/
|
||||
public events: Phaser.Components.Events;
|
||||
|
||||
/**
|
||||
* The Physics Body
|
||||
*/
|
||||
//public body: Phaser.Physics.Body;
|
||||
public body;
|
||||
|
||||
/**
|
||||
* This manages animations of the sprite. You can modify animations through it. (see AnimationManager)
|
||||
* @type AnimationManager
|
||||
|
||||
@@ -1,314 +0,0 @@
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="GameObject.ts" />
|
||||
/// <reference path="../system/TilemapLayer.ts" />
|
||||
/// <reference path="../system/Tile.ts" />
|
||||
/**
|
||||
* Phaser - Tilemap
|
||||
*
|
||||
* This GameObject allows for the display of a tilemap within the game world. Tile maps consist of an image, tile data and a size.
|
||||
* Internally it creates a TilemapLayer for each layer in the tilemap.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Tilemap = (function (_super) {
|
||||
__extends(Tilemap, _super);
|
||||
/**
|
||||
* Tilemap constructor
|
||||
* Create a new <code>Tilemap</code>.
|
||||
*
|
||||
* @param game {Phaser.Game} Current game instance.
|
||||
* @param key {string} Asset key for this map.
|
||||
* @param mapData {string} Data of this map. (a big 2d array, normally in csv)
|
||||
* @param format {number} Format of this map data, available: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON.
|
||||
* @param resizeWorld {boolean} Resize the world bound automatically based on this tilemap?
|
||||
* @param tileWidth {number} Width of tiles in this map.
|
||||
* @param tileHeight {number} Height of tiles in this map.
|
||||
*/
|
||||
function Tilemap(game, key, mapData, format, resizeWorld, tileWidth, tileHeight) {
|
||||
if (typeof resizeWorld === "undefined") { resizeWorld = true; }
|
||||
if (typeof tileWidth === "undefined") { tileWidth = 0; }
|
||||
if (typeof tileHeight === "undefined") { tileHeight = 0; }
|
||||
_super.call(this, game);
|
||||
/**
|
||||
* Tilemap collision callback.
|
||||
* @type {function}
|
||||
*/
|
||||
this.collisionCallback = null;
|
||||
this.isGroup = false;
|
||||
this.tiles = [];
|
||||
this.layers = [];
|
||||
this.mapFormat = format;
|
||||
switch(format) {
|
||||
case Tilemap.FORMAT_CSV:
|
||||
this.parseCSV(game.cache.getText(mapData), key, tileWidth, tileHeight);
|
||||
break;
|
||||
case Tilemap.FORMAT_TILED_JSON:
|
||||
this.parseTiledJSON(game.cache.getText(mapData), key);
|
||||
break;
|
||||
}
|
||||
if(this.currentLayer && resizeWorld) {
|
||||
this._game.world.setSize(this.currentLayer.widthInPixels, this.currentLayer.heightInPixels, true);
|
||||
}
|
||||
}
|
||||
Tilemap.FORMAT_CSV = 0;
|
||||
Tilemap.FORMAT_TILED_JSON = 1;
|
||||
Tilemap.prototype.update = /**
|
||||
* Inherited update method.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
Tilemap.prototype.render = /**
|
||||
* Render this tilemap to a specific camera with specific offset.
|
||||
* @param camera {Camera} The camera this tilemap will be rendered to.
|
||||
* @param cameraOffsetX {number} X offset of the camera.
|
||||
* @param cameraOffsetY {number} Y offset of the camera.
|
||||
*/
|
||||
function (camera, cameraOffsetX, cameraOffsetY) {
|
||||
if(this.cameraBlacklist.indexOf(camera.ID) == -1) {
|
||||
// Loop through the layers
|
||||
for(var i = 0; i < this.layers.length; i++) {
|
||||
this.layers[i].render(camera, cameraOffsetX, cameraOffsetY);
|
||||
}
|
||||
}
|
||||
};
|
||||
Tilemap.prototype.parseCSV = /**
|
||||
* Parset csv map data and generate tiles.
|
||||
* @param data {string} CSV map data.
|
||||
* @param key {string} Asset key for tileset image.
|
||||
* @param tileWidth {number} Width of its tile.
|
||||
* @param tileHeight {number} Height of its tile.
|
||||
*/
|
||||
function (data, key, tileWidth, tileHeight) {
|
||||
var layer = new Phaser.TilemapLayer(this._game, this, key, Phaser.Tilemap.FORMAT_CSV, 'TileLayerCSV' + this.layers.length.toString(), tileWidth, tileHeight);
|
||||
// Trim any rogue whitespace from the data
|
||||
data = data.trim();
|
||||
var rows = data.split("\n");
|
||||
for(var i = 0; i < rows.length; i++) {
|
||||
var column = rows[i].split(",");
|
||||
if(column.length > 0) {
|
||||
layer.addColumn(column);
|
||||
}
|
||||
}
|
||||
layer.updateBounds();
|
||||
var tileQuantity = layer.parseTileOffsets();
|
||||
this.currentLayer = layer;
|
||||
this.collisionLayer = layer;
|
||||
this.layers.push(layer);
|
||||
this.generateTiles(tileQuantity);
|
||||
};
|
||||
Tilemap.prototype.parseTiledJSON = /**
|
||||
* Parset JSON map data and generate tiles.
|
||||
* @param data {string} JSON map data.
|
||||
* @param key {string} Asset key for tileset image.
|
||||
*/
|
||||
function (data, key) {
|
||||
// Trim any rogue whitespace from the data
|
||||
data = data.trim();
|
||||
var json = JSON.parse(data);
|
||||
for(var i = 0; i < json.layers.length; i++) {
|
||||
var layer = new Phaser.TilemapLayer(this._game, this, key, Phaser.Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight);
|
||||
layer.alpha = json.layers[i].opacity;
|
||||
layer.visible = json.layers[i].visible;
|
||||
layer.tileMargin = json.tilesets[0].margin;
|
||||
layer.tileSpacing = json.tilesets[0].spacing;
|
||||
var c = 0;
|
||||
var row;
|
||||
for(var t = 0; t < json.layers[i].data.length; t++) {
|
||||
if(c == 0) {
|
||||
row = [];
|
||||
}
|
||||
row.push(json.layers[i].data[t]);
|
||||
c++;
|
||||
if(c == json.layers[i].width) {
|
||||
layer.addColumn(row);
|
||||
c = 0;
|
||||
}
|
||||
}
|
||||
layer.updateBounds();
|
||||
var tileQuantity = layer.parseTileOffsets();
|
||||
this.currentLayer = layer;
|
||||
this.collisionLayer = layer;
|
||||
this.layers.push(layer);
|
||||
}
|
||||
this.generateTiles(tileQuantity);
|
||||
};
|
||||
Tilemap.prototype.generateTiles = /**
|
||||
* Create tiles of given quantity.
|
||||
* @param qty {number} Quentity of tiles to be generated.
|
||||
*/
|
||||
function (qty) {
|
||||
for(var i = 0; i < qty; i++) {
|
||||
this.tiles.push(new Phaser.Tile(this._game, this, i, this.currentLayer.tileWidth, this.currentLayer.tileHeight));
|
||||
}
|
||||
};
|
||||
Object.defineProperty(Tilemap.prototype, "widthInPixels", {
|
||||
get: function () {
|
||||
return this.currentLayer.widthInPixels;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Tilemap.prototype, "heightInPixels", {
|
||||
get: function () {
|
||||
return this.currentLayer.heightInPixels;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Tilemap.prototype.setCollisionCallback = // Tile Collision
|
||||
/**
|
||||
* Set callback to be called when this tilemap collides.
|
||||
* @param context {object} Callback will be called with this context.
|
||||
* @param callback {function} Callback function.
|
||||
*/
|
||||
function (context, callback) {
|
||||
this.collisionCallbackContext = context;
|
||||
this.collisionCallback = callback;
|
||||
};
|
||||
Tilemap.prototype.setCollisionRange = /**
|
||||
* Set collision configs of tiles in a range index.
|
||||
* @param start {number} First index of tiles.
|
||||
* @param end {number} Last index of tiles.
|
||||
* @param collision {number} Bit field of flags. (see Tile.allowCollision)
|
||||
* @param resetCollisions {boolean} Reset collision flags before set.
|
||||
* @param separateX {boolean} Enable seprate at x-axis.
|
||||
* @param separateY {boolean} Enable seprate at y-axis.
|
||||
*/
|
||||
function (start, end, collision, resetCollisions, separateX, separateY) {
|
||||
if (typeof collision === "undefined") { collision = Phaser.Collision.ANY; }
|
||||
if (typeof resetCollisions === "undefined") { resetCollisions = false; }
|
||||
if (typeof separateX === "undefined") { separateX = true; }
|
||||
if (typeof separateY === "undefined") { separateY = true; }
|
||||
for(var i = start; i < end; i++) {
|
||||
this.tiles[i].setCollision(collision, resetCollisions, separateX, separateY);
|
||||
}
|
||||
};
|
||||
Tilemap.prototype.setCollisionByIndex = /**
|
||||
* Set collision configs of tiles with given index.
|
||||
* @param values {number[]} Index array which contains all tile indexes. The tiles with those indexes will be setup with rest parameters.
|
||||
* @param collision {number} Bit field of flags. (see Tile.allowCollision)
|
||||
* @param resetCollisions {boolean} Reset collision flags before set.
|
||||
* @param separateX {boolean} Enable seprate at x-axis.
|
||||
* @param separateY {boolean} Enable seprate at y-axis.
|
||||
*/
|
||||
function (values, collision, resetCollisions, separateX, separateY) {
|
||||
if (typeof collision === "undefined") { collision = Phaser.Collision.ANY; }
|
||||
if (typeof resetCollisions === "undefined") { resetCollisions = false; }
|
||||
if (typeof separateX === "undefined") { separateX = true; }
|
||||
if (typeof separateY === "undefined") { separateY = true; }
|
||||
for(var i = 0; i < values.length; i++) {
|
||||
this.tiles[values[i]].setCollision(collision, resetCollisions, separateX, separateY);
|
||||
}
|
||||
};
|
||||
Tilemap.prototype.getTileByIndex = // Tile Management
|
||||
/**
|
||||
* Get the tile by its index.
|
||||
* @param value {number} Index of the tile you want to get.
|
||||
* @return {Tile} The tile with given index.
|
||||
*/
|
||||
function (value) {
|
||||
if(this.tiles[value]) {
|
||||
return this.tiles[value];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Tilemap.prototype.getTile = /**
|
||||
* Get the tile located at specific position and layer.
|
||||
* @param x {number} X position of this tile located.
|
||||
* @param y {number} Y position of this tile located.
|
||||
* @param [layer] {number} layer of this tile located.
|
||||
* @return {Tile} The tile with specific properties.
|
||||
*/
|
||||
function (x, y, layer) {
|
||||
if (typeof layer === "undefined") { layer = 0; }
|
||||
return this.tiles[this.layers[layer].getTileIndex(x, y)];
|
||||
};
|
||||
Tilemap.prototype.getTileFromWorldXY = /**
|
||||
* Get the tile located at specific position (in world coordinate) and layer. (thus you give a position of a point which is within the tile)
|
||||
* @param x {number} X position of the point in target tile.
|
||||
* @param x {number} Y position of the point in target tile.
|
||||
* @param [layer] {number} layer of this tile located.
|
||||
* @return {Tile} The tile with specific properties.
|
||||
*/
|
||||
function (x, y, layer) {
|
||||
if (typeof layer === "undefined") { layer = 0; }
|
||||
return this.tiles[this.layers[layer].getTileFromWorldXY(x, y)];
|
||||
};
|
||||
Tilemap.prototype.getTileFromInputXY = function (layer) {
|
||||
if (typeof layer === "undefined") { layer = 0; }
|
||||
return this.tiles[this.layers[layer].getTileFromWorldXY(this._game.input.getWorldX(), this._game.input.getWorldY())];
|
||||
};
|
||||
Tilemap.prototype.getTileOverlaps = /**
|
||||
* Get tiles overlaps the given object.
|
||||
* @param object {GameObject} Tiles you want to get that overlaps this.
|
||||
* @return {array} Array with tiles informations. (Each contains x, y and the tile.)
|
||||
*/
|
||||
function (object) {
|
||||
return this.currentLayer.getTileOverlaps(object);
|
||||
};
|
||||
Tilemap.prototype.collide = // COLLIDE
|
||||
/**
|
||||
* Check whether this tilemap collides with the given game object or group of objects.
|
||||
* @param objectOrGroup {function} Target object of group you want to check.
|
||||
* @param callback {function} This is called if objectOrGroup collides the tilemap.
|
||||
* @param context {object} Callback will be called with this context.
|
||||
* @return {boolean} Return true if this collides with given object, otherwise return false.
|
||||
*/
|
||||
function (objectOrGroup, callback, context) {
|
||||
if (typeof objectOrGroup === "undefined") { objectOrGroup = null; }
|
||||
if (typeof callback === "undefined") { callback = null; }
|
||||
if (typeof context === "undefined") { context = null; }
|
||||
if(callback !== null && context !== null) {
|
||||
this.collisionCallback = callback;
|
||||
this.collisionCallbackContext = context;
|
||||
}
|
||||
if(objectOrGroup == null) {
|
||||
objectOrGroup = this._game.world.group;
|
||||
}
|
||||
// Group?
|
||||
if(objectOrGroup.isGroup == false) {
|
||||
this.collideGameObject(objectOrGroup);
|
||||
} else {
|
||||
objectOrGroup.forEachAlive(this, this.collideGameObject, true);
|
||||
}
|
||||
};
|
||||
Tilemap.prototype.collideGameObject = /**
|
||||
* Check whether this tilemap collides with the given game object.
|
||||
* @param object {GameObject} Target object you want to check.
|
||||
* @return {boolean} Return true if this collides with given object, otherwise return false.
|
||||
*/
|
||||
function (object) {
|
||||
if(object !== this && object.immovable == false && object.exists == true && object.allowCollisions != Phaser.Collision.NONE) {
|
||||
this._tempCollisionData = this.collisionLayer.getTileOverlaps(object);
|
||||
if(this.collisionCallback !== null && this._tempCollisionData.length > 0) {
|
||||
this.collisionCallback.call(this.collisionCallbackContext, object, this._tempCollisionData);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Tilemap.prototype.putTile = /**
|
||||
* Set a tile to a specific layer.
|
||||
* @param x {number} X position of this tile.
|
||||
* @param y {number} Y position of this tile.
|
||||
* @param index {number} The index of this tile type in the core map data.
|
||||
* @param [layer] {number} which layer you want to set the tile to.
|
||||
*/
|
||||
function (x, y, index, layer) {
|
||||
if (typeof layer === "undefined") { layer = 0; }
|
||||
this.layers[layer].putTile(x, y, index);
|
||||
};
|
||||
return Tilemap;
|
||||
})(Phaser.GameObject);
|
||||
Phaser.Tilemap = Tilemap;
|
||||
// Set current layer
|
||||
// Set layer order?
|
||||
// Delete tiles of certain type
|
||||
// Erase tiles
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,279 +0,0 @@
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Components - TransformManager
|
||||
*/
|
||||
(function (Components) {
|
||||
var TransformManager = (function () {
|
||||
/**
|
||||
* Creates a new TransformManager component
|
||||
* @param parent The game object using this transform
|
||||
*/
|
||||
function TransformManager(parent) {
|
||||
this._dirty = false;
|
||||
/**
|
||||
* This value is added to the rotation of the object.
|
||||
* For example if you had a texture drawn facing straight up then you could set
|
||||
* rotationOffset to 90 and it would correspond correctly with Phasers right-handed coordinate system.
|
||||
* @type {number}
|
||||
*/
|
||||
this.rotationOffset = 0;
|
||||
/**
|
||||
* The rotation of the object in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
|
||||
*/
|
||||
this.rotation = 0;
|
||||
this.game = parent.game;
|
||||
this.parent = parent;
|
||||
|
||||
this.local = new Phaser.Mat3();
|
||||
|
||||
this.scrollFactor = new Phaser.Vec2(1, 1);
|
||||
this.origin = new Phaser.Vec2();
|
||||
this.scale = new Phaser.Vec2(1, 1);
|
||||
this.skew = new Phaser.Vec2();
|
||||
|
||||
this.center = new Phaser.Point();
|
||||
this.upperLeft = new Phaser.Point();
|
||||
this.upperRight = new Phaser.Point();
|
||||
this.bottomLeft = new Phaser.Point();
|
||||
this.bottomRight = new Phaser.Point();
|
||||
|
||||
this._pos = new Phaser.Point();
|
||||
this._scale = new Phaser.Point();
|
||||
this._size = new Phaser.Point();
|
||||
this._halfSize = new Phaser.Point();
|
||||
this._offset = new Phaser.Point();
|
||||
this._origin = new Phaser.Point();
|
||||
this._sc = new Phaser.Point();
|
||||
this._scA = new Phaser.Point();
|
||||
}
|
||||
Object.defineProperty(TransformManager.prototype, "distance", {
|
||||
get: /**
|
||||
* The distance from the center of the transform to the rotation origin.
|
||||
*/
|
||||
function () {
|
||||
return this._distance;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(TransformManager.prototype, "angleToCenter", {
|
||||
get: /**
|
||||
* The angle between the center of the transform to the rotation origin.
|
||||
*/
|
||||
function () {
|
||||
return this._angle;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(TransformManager.prototype, "offsetX", {
|
||||
get: /**
|
||||
* The offset on the X axis of the origin That is the difference between the top left of the Sprite and the origin.x.
|
||||
* So if the origin.x is 0 the offsetX will be 0. If the origin.x is 0.5 then offsetX will be sprite width / 2, and so on.
|
||||
*/
|
||||
function () {
|
||||
return this._offset.x;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(TransformManager.prototype, "offsetY", {
|
||||
get: /**
|
||||
* The offset on the Y axis of the origin
|
||||
*/
|
||||
function () {
|
||||
return this._offset.y;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(TransformManager.prototype, "halfWidth", {
|
||||
get: /**
|
||||
* Half the width of the parent sprite, taking into consideration scaling
|
||||
*/
|
||||
function () {
|
||||
return this._halfSize.x;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(TransformManager.prototype, "halfHeight", {
|
||||
get: /**
|
||||
* Half the height of the parent sprite, taking into consideration scaling
|
||||
*/
|
||||
function () {
|
||||
return this._halfSize.y;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(TransformManager.prototype, "sin", {
|
||||
get: /**
|
||||
* The equivalent of Math.sin(rotation + rotationOffset)
|
||||
*/
|
||||
function () {
|
||||
return this._sc.x;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(TransformManager.prototype, "cos", {
|
||||
get: /**
|
||||
* The equivalent of Math.cos(rotation + rotationOffset)
|
||||
*/
|
||||
function () {
|
||||
return this._sc.y;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
* Moves the sprite so its center is located on the given x and y coordinates.
|
||||
* Doesn't change the origin of the sprite.
|
||||
*/
|
||||
TransformManager.prototype.centerOn = function (x, y) {
|
||||
this.parent.x = x + (this.parent.x - this.center.x);
|
||||
this.parent.y = y + (this.parent.y - this.center.y);
|
||||
//this.setCache();
|
||||
};
|
||||
|
||||
/**
|
||||
* Populates the transform cache. Called by the parent object on creation.
|
||||
*/
|
||||
TransformManager.prototype.setCache = function () {
|
||||
this._pos.x = this.parent.x;
|
||||
this._pos.y = this.parent.y;
|
||||
this._halfSize.x = this.parent.width / 2;
|
||||
this._halfSize.y = this.parent.height / 2;
|
||||
this._offset.x = this.origin.x * this.parent.width;
|
||||
this._offset.y = this.origin.y * this.parent.height;
|
||||
this._angle = Math.atan2(this.halfHeight - this._offset.x, this.halfWidth - this._offset.y);
|
||||
this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
|
||||
this._size.x = this.parent.width;
|
||||
this._size.y = this.parent.height;
|
||||
this._origin.x = this.origin.x;
|
||||
this._origin.y = this.origin.y;
|
||||
this._scA.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
|
||||
this._scA.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
|
||||
this._prevRotation = this.rotation;
|
||||
|
||||
if (this.parent.texture && this.parent.texture.renderRotation) {
|
||||
this._sc.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
|
||||
this._sc.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
|
||||
} else {
|
||||
this._sc.x = 0;
|
||||
this._sc.y = 1;
|
||||
}
|
||||
|
||||
this.center.x = this.parent.x + this._distance * this._scA.y;
|
||||
this.center.y = this.parent.y + this._distance * this._scA.x;
|
||||
|
||||
this.upperLeft.setTo(this.center.x - this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
|
||||
this.upperRight.setTo(this.center.x + this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
|
||||
this.bottomLeft.setTo(this.center.x - this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
|
||||
this.bottomRight.setTo(this.center.x + this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
|
||||
|
||||
this._pos.x = this.parent.x;
|
||||
this._pos.y = this.parent.y;
|
||||
|
||||
this._flippedX = this.parent.texture.flippedX;
|
||||
this._flippedY = this.parent.texture.flippedY;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the local transform matrix and the cache values if anything has changed in the parent.
|
||||
*/
|
||||
TransformManager.prototype.update = function () {
|
||||
// Check cache
|
||||
this._dirty = false;
|
||||
|
||||
if (this.parent.width !== this._size.x || this.parent.height !== this._size.y || this.origin.x !== this._origin.x || this.origin.y !== this._origin.y) {
|
||||
this._halfSize.x = this.parent.width / 2;
|
||||
this._halfSize.y = this.parent.height / 2;
|
||||
this._offset.x = this.origin.x * this.parent.width;
|
||||
this._offset.y = this.origin.y * this.parent.height;
|
||||
this._angle = Math.atan2(this.halfHeight - this._offset.y, this.halfWidth - this._offset.x);
|
||||
this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
|
||||
|
||||
// Store
|
||||
this._size.x = this.parent.width;
|
||||
this._size.y = this.parent.height;
|
||||
this._origin.x = this.origin.x;
|
||||
this._origin.y = this.origin.y;
|
||||
this._dirty = true;
|
||||
}
|
||||
|
||||
if (this.rotation != this._prevRotation || this._dirty) {
|
||||
this._scA.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
|
||||
this._scA.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
|
||||
|
||||
if (this.parent.texture.renderRotation) {
|
||||
this._sc.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
|
||||
this._sc.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
|
||||
} else {
|
||||
this._sc.x = 0;
|
||||
this._sc.y = 1;
|
||||
}
|
||||
|
||||
// Store
|
||||
this._prevRotation = this.rotation;
|
||||
this._dirty = true;
|
||||
}
|
||||
|
||||
if (this._dirty || this.parent.x != this._pos.x || this.parent.y != this._pos.y) {
|
||||
this.center.x = this.parent.x + this._distance * this._scA.y;
|
||||
this.center.y = this.parent.y + this._distance * this._scA.x;
|
||||
|
||||
this.upperLeft.setTo(this.center.x - this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
|
||||
this.upperRight.setTo(this.center.x + this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
|
||||
this.bottomLeft.setTo(this.center.x - this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
|
||||
this.bottomRight.setTo(this.center.x + this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
|
||||
|
||||
this._pos.x = this.parent.x;
|
||||
this._pos.y = this.parent.y;
|
||||
|
||||
// Translate
|
||||
this.local.data[2] = this.parent.x;
|
||||
this.local.data[5] = this.parent.y;
|
||||
}
|
||||
|
||||
if (this._dirty || this._flippedX != this.parent.texture.flippedX) {
|
||||
this._flippedX = this.parent.texture.flippedX;
|
||||
|
||||
if (this._flippedX) {
|
||||
this.local.data[0] = this._sc.y * -this.scale.x;
|
||||
this.local.data[3] = (this._sc.x * -this.scale.x) + this.skew.x;
|
||||
} else {
|
||||
this.local.data[0] = this._sc.y * this.scale.x;
|
||||
this.local.data[3] = (this._sc.x * this.scale.x) + this.skew.x;
|
||||
}
|
||||
}
|
||||
|
||||
if (this._dirty || this._flippedY != this.parent.texture.flippedY) {
|
||||
this._flippedY = this.parent.texture.flippedY;
|
||||
|
||||
if (this._flippedY) {
|
||||
this.local.data[4] = this._sc.y * -this.scale.y;
|
||||
this.local.data[1] = -(this._sc.x * -this.scale.y) + this.skew.y;
|
||||
} else {
|
||||
this.local.data[4] = this._sc.y * this.scale.y;
|
||||
this.local.data[1] = -(this._sc.x * this.scale.y) + this.skew.y;
|
||||
}
|
||||
}
|
||||
};
|
||||
return TransformManager;
|
||||
})();
|
||||
Components.TransformManager = TransformManager;
|
||||
})(Phaser.Components || (Phaser.Components = {}));
|
||||
var Components = Phaser.Components;
|
||||
})(Phaser || (Phaser = {}));
|
||||
Reference in New Issue
Block a user