mirror of
https://github.com/wassname/phaser.git
synced 2026-08-15 12:45:11 +08:00
Putting everything back together again :)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../Group.ts" />
|
||||
/// <reference path="../core/Group.ts" />
|
||||
/// <reference path="Particle.ts" />
|
||||
/// <reference path="../utils/SpriteUtils.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Emitter
|
||||
@@ -29,13 +31,13 @@ module Phaser {
|
||||
this.y = y;
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
this.minParticleSpeed = new MicroPoint(-100, -100);
|
||||
this.maxParticleSpeed = new MicroPoint(100, 100);
|
||||
this.minParticleSpeed = new Vec2(-100, -100);
|
||||
this.maxParticleSpeed = new Vec2(100, 100);
|
||||
this.minRotation = -360;
|
||||
this.maxRotation = 360;
|
||||
this.gravity = 0;
|
||||
this.particleClass = null;
|
||||
this.particleDrag = new MicroPoint();
|
||||
this.particleDrag = new Vec2();
|
||||
this.frequency = 0.1;
|
||||
this.lifespan = 3;
|
||||
this.bounce = 0;
|
||||
@@ -43,7 +45,6 @@ module Phaser {
|
||||
this._counter = 0;
|
||||
this._explode = true;
|
||||
this.on = false;
|
||||
this._point = new MicroPoint();
|
||||
|
||||
}
|
||||
|
||||
@@ -67,22 +68,27 @@ module Phaser {
|
||||
*/
|
||||
public height: number;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public alive: bool;
|
||||
|
||||
/**
|
||||
* The minimum possible velocity of a particle.
|
||||
* The default value is (-100,-100).
|
||||
*/
|
||||
public minParticleSpeed: MicroPoint;
|
||||
public minParticleSpeed: Vec2;
|
||||
|
||||
/**
|
||||
* The maximum possible velocity of a particle.
|
||||
* The default value is (100,100).
|
||||
*/
|
||||
public maxParticleSpeed: MicroPoint;
|
||||
public maxParticleSpeed: Vec2;
|
||||
|
||||
/**
|
||||
* The X and Y drag component of particles launched from the emitter.
|
||||
*/
|
||||
public particleDrag: MicroPoint;
|
||||
public particleDrag: Vec2;
|
||||
|
||||
/**
|
||||
* The minimum possible angular velocity of a particle. The default value is -360.
|
||||
@@ -152,7 +158,7 @@ module Phaser {
|
||||
/**
|
||||
* Internal point object, handy for reusing for memory mgmt purposes.
|
||||
*/
|
||||
private _point: MicroPoint;
|
||||
private _point: Vec2;
|
||||
|
||||
/**
|
||||
* Clean up memory.
|
||||
@@ -185,7 +191,7 @@ module Phaser {
|
||||
/*
|
||||
if(Multiple)
|
||||
{
|
||||
var sprite:Sprite = new Sprite(this._game);
|
||||
var sprite:Sprite = new Sprite(this.game);
|
||||
sprite.loadGraphic(Graphics,true);
|
||||
totalFrames = sprite.frames;
|
||||
sprite.destroy();
|
||||
@@ -200,17 +206,17 @@ module Phaser {
|
||||
{
|
||||
if (this.particleClass == null)
|
||||
{
|
||||
particle = new Particle(this._game);
|
||||
particle = new Particle(this.game);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle = new this.particleClass(this._game);
|
||||
particle = new this.particleClass(this.game);
|
||||
}
|
||||
|
||||
if (multiple)
|
||||
{
|
||||
/*
|
||||
randomFrame = this._game.math.random()*totalFrames;
|
||||
randomFrame = this.game.math.random()*totalFrames;
|
||||
if(BakedRotations > 0)
|
||||
particle.loadRotatedGraphic(Graphics,BakedRotations,randomFrame);
|
||||
else
|
||||
@@ -231,21 +237,21 @@ module Phaser {
|
||||
|
||||
if (graphics)
|
||||
{
|
||||
particle.loadGraphic(graphics);
|
||||
particle.texture.loadImage(graphics);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (collide > 0)
|
||||
{
|
||||
particle.allowCollisions = Collision.ANY;
|
||||
particle.body.allowCollisions = Types.ANY;
|
||||
particle.body.type = Types.BODY_DYNAMIC;
|
||||
particle.width *= collide;
|
||||
particle.height *= collide;
|
||||
//particle.centerOffsets();
|
||||
}
|
||||
else
|
||||
{
|
||||
particle.allowCollisions = Collision.NONE;
|
||||
particle.body.allowCollisions = Types.NONE;
|
||||
}
|
||||
|
||||
particle.exists = false;
|
||||
@@ -287,7 +293,7 @@ module Phaser {
|
||||
}
|
||||
else
|
||||
{
|
||||
this._timer += this._game.time.elapsed;
|
||||
this._timer += this.game.time.elapsed;
|
||||
|
||||
while ((this.frequency > 0) && (this._timer > this.frequency) && this.on)
|
||||
{
|
||||
@@ -311,11 +317,18 @@ module Phaser {
|
||||
* Call this function to turn off all the particles and the emitter.
|
||||
*/
|
||||
public kill() {
|
||||
|
||||
this.on = false;
|
||||
this.alive = false;
|
||||
this.exists = false;
|
||||
}
|
||||
|
||||
super.kill();
|
||||
|
||||
/**
|
||||
* 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>.
|
||||
*/
|
||||
public revive() {
|
||||
this.alive = true;
|
||||
this.exists = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -351,46 +364,46 @@ module Phaser {
|
||||
var particle: Particle = this.recycle(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.body.bounce.setTo(this.bounce, this.bounce);
|
||||
SpriteUtils.reset(particle, 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);
|
||||
particle.body.velocity.x = this.minParticleSpeed.x + this.game.math.random() * (this.maxParticleSpeed.x - this.minParticleSpeed.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle.velocity.x = this.minParticleSpeed.x;
|
||||
particle.body.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);
|
||||
particle.body.velocity.y = this.minParticleSpeed.y + this.game.math.random() * (this.maxParticleSpeed.y - this.minParticleSpeed.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle.velocity.y = this.minParticleSpeed.y;
|
||||
particle.body.velocity.y = this.minParticleSpeed.y;
|
||||
}
|
||||
|
||||
particle.acceleration.y = this.gravity;
|
||||
particle.body.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);
|
||||
particle.body.angularVelocity = this.minRotation + this.game.math.random() * (this.maxRotation - this.minRotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle.angularVelocity = this.minRotation;
|
||||
particle.body.angularVelocity = this.minRotation;
|
||||
}
|
||||
|
||||
if (particle.angularVelocity != 0)
|
||||
if (particle.body.angularVelocity != 0)
|
||||
{
|
||||
particle.angle = this._game.math.random() * 360 - 180;
|
||||
particle.angle = this.game.math.random() * 360 - 180;
|
||||
}
|
||||
|
||||
particle.drag.x = this.particleDrag.x;
|
||||
particle.drag.y = this.particleDrag.y;
|
||||
particle.body.drag.x = this.particleDrag.x;
|
||||
particle.body.drag.y = this.particleDrag.y;
|
||||
particle.onEmit();
|
||||
|
||||
}
|
||||
@@ -444,10 +457,9 @@ module Phaser {
|
||||
*
|
||||
* @param Object {object} The <code>Object</code> that you want to sync up with.
|
||||
*/
|
||||
public at(object) {
|
||||
object.getMidpoint(this._point);
|
||||
this.x = this._point.x - (this.width >> 1);
|
||||
this.y = this._point.y - (this.height >> 1);
|
||||
public at(object: Sprite) {
|
||||
this.x = object.body.bounds.halfWidth - (this.width >> 1);
|
||||
this.y = object.body.bounds.halfHeight - (this.height >> 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../tweens/Tween.ts" />
|
||||
/// <reference path="../physics/AABB.ts" />
|
||||
/// <reference path="../gameobjects/Emitter.ts" />
|
||||
/// <reference path="../gameobjects/Particle.ts" />
|
||||
/// <reference path="../gameobjects/Sprite.ts" />
|
||||
/// <reference path="../gameobjects/ScrollZone.ts" />
|
||||
/// <reference path="../gameobjects/DynamicTexture.ts" />
|
||||
/// <reference path="../gameobjects/Tilemap.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - GameObjectFactory
|
||||
@@ -97,9 +102,9 @@ module Phaser {
|
||||
*
|
||||
* @return {Particle} The newly created particle object.
|
||||
*/
|
||||
//public particle(): Particle {
|
||||
// return new Particle(this._game);
|
||||
//}
|
||||
public particle(): Particle {
|
||||
return new Particle(this._game);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Emitter.
|
||||
@@ -109,9 +114,9 @@ module Phaser {
|
||||
* @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): Emitter {
|
||||
// return <Emitter> this._world.group.add(new Emitter(this._game, x, y, size));
|
||||
//}
|
||||
public emitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
|
||||
return <Emitter> this._world.group.add(new Emitter(this._game, x, y, size));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ScrollZone object with image key, position and size.
|
||||
@@ -138,9 +143,9 @@ module Phaser {
|
||||
* @param [tileHeight] {number} height of each tile.
|
||||
* @return {Tilemap} The newly created tilemap object.
|
||||
*/
|
||||
//public tilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
|
||||
// return <Tilemap> this._world.group.add(new Tilemap(this._game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
|
||||
//}
|
||||
public tilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
|
||||
return <Tilemap> this._world.group.add(new Tilemap(this._game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a tween object for a specific object.
|
||||
@@ -181,9 +186,9 @@ module Phaser {
|
||||
* @param emitter The Emitter to add to the Game World
|
||||
* @return {Phaser.Emitter} The Emitter object
|
||||
*/
|
||||
//public existingEmitter(emitter: Emitter): Emitter {
|
||||
// return this._world.group.add(emitter);
|
||||
//}
|
||||
public existingEmitter(emitter: Emitter): Emitter {
|
||||
return this._world.group.add(emitter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an existing ScrollZone to the current world.
|
||||
@@ -203,9 +208,9 @@ module Phaser {
|
||||
* @param tilemap The Tilemap to add to the Game World
|
||||
* @return {Phaser.Tilemap} The Tilemap object
|
||||
*/
|
||||
//public existingTilemap(tilemap: Tilemap): Tilemap {
|
||||
// return this._world.group.add(tilemap);
|
||||
//}
|
||||
public existingTilemap(tilemap: Tilemap): Tilemap {
|
||||
return this._world.group.add(tilemap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an existing Tween to the current world.
|
||||
|
||||
@@ -1,645 +0,0 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../geom/Polygon.ts" />
|
||||
/// <reference path="../utils/RectangleUtils.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.
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class GeomSprite extends Sprite {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
constructor(game: Game, x?: number = 0, y?: number = 0) {
|
||||
|
||||
super(game, x, y);
|
||||
|
||||
this.type = GeomSprite.UNASSIGNED;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
// local rendering related temp vars to help avoid gc spikes
|
||||
private _dx: number = 0;
|
||||
private _dy: number = 0;
|
||||
private _dw: number = 0;
|
||||
private _dh: number = 0;
|
||||
|
||||
/**
|
||||
* Geom type of this sprite. (available: UNASSIGNED, CIRCLE, LINE, POINT, RECTANGLE)
|
||||
* @type {number}
|
||||
*/
|
||||
public type: number = 0;
|
||||
|
||||
/**
|
||||
* Not completely set yet. (the default type)
|
||||
*/
|
||||
public static UNASSIGNED: number = 0;
|
||||
|
||||
/**
|
||||
* Circle.
|
||||
* @type {number}
|
||||
*/
|
||||
public static CIRCLE: number = 1;
|
||||
|
||||
/**
|
||||
* Line.
|
||||
* @type {number}
|
||||
*/
|
||||
public static LINE: number = 2;
|
||||
|
||||
/**
|
||||
* Point.
|
||||
* @type {number}
|
||||
*/
|
||||
public static POINT: number = 3;
|
||||
|
||||
/**
|
||||
* Rectangle.
|
||||
* @type {number}
|
||||
*/
|
||||
public static RECTANGLE: number = 4;
|
||||
|
||||
/**
|
||||
* Polygon.
|
||||
* @type {number}
|
||||
*/
|
||||
public static POLYGON: number = 5;
|
||||
|
||||
/**
|
||||
* Circle shape container. A Circle instance.
|
||||
* @type {Circle}
|
||||
*/
|
||||
public circle: Circle;
|
||||
|
||||
/**
|
||||
* Line shape container. A Line instance.
|
||||
* @type {Line}
|
||||
*/
|
||||
public line: Line;
|
||||
|
||||
/**
|
||||
* Point shape container. A Point instance.
|
||||
* @type {Point}
|
||||
*/
|
||||
public point: Point;
|
||||
|
||||
/**
|
||||
* Rectangle shape container. A Rectangle instance.
|
||||
* @type {Rectangle}
|
||||
*/
|
||||
public rect: Rectangle;
|
||||
|
||||
/**
|
||||
* Polygon shape container. A Polygon instance.
|
||||
* @type {Polygon}
|
||||
*/
|
||||
public polygon: Polygon;
|
||||
|
||||
/**
|
||||
* Render outline of this sprite or not. (default is true)
|
||||
* @type {boolean}
|
||||
*/
|
||||
public renderOutline: bool = true;
|
||||
|
||||
/**
|
||||
* Fill the shape or not. (default is true)
|
||||
* @type {boolean}
|
||||
*/
|
||||
public renderFill: bool = true;
|
||||
|
||||
/**
|
||||
* Width of outline. (default is 1)
|
||||
* @type {number}
|
||||
*/
|
||||
public lineWidth: number = 1;
|
||||
|
||||
/**
|
||||
* Width of outline. (default is 1)
|
||||
* @type {number}
|
||||
*/
|
||||
public lineColor: string = '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
|
||||
*/
|
||||
public fillColor: string = 'rgb(0,100,0)';
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
loadCircle(circle:Circle): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.circle = circle;
|
||||
this.type = GeomSprite.CIRCLE;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
loadLine(line:Line): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.line = line;
|
||||
this.type = GeomSprite.LINE;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
loadPoint(point:Point): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.point = point;
|
||||
this.type = GeomSprite.POINT;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
loadRectangle(rect:Rectangle): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.rect = rect;
|
||||
this.type = GeomSprite.RECTANGLE;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a circle shape with specific diameter.
|
||||
* @param diameter {number} Diameter of the circle.
|
||||
* @return {GeomSprite} GeomSprite instance itself.
|
||||
*/
|
||||
createCircle(diameter: number): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.circle = new Circle(this.x, this.y, diameter);
|
||||
this.type = 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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
createLine(x: number, y: number): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.line = new Line(this.x, this.y, x, y);
|
||||
this.type = GeomSprite.LINE;
|
||||
this.frameBounds.setTo(this.x, this.y, this.line.width, this.line.height);
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a point shape at spriter's position.
|
||||
* @return {GeomSprite} GeomSprite instance itself.
|
||||
*/
|
||||
createPoint(): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.point = new Point(this.x, this.y);
|
||||
this.type = GeomSprite.POINT;
|
||||
this.frameBounds.width = 1;
|
||||
this.frameBounds.height = 1;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a rectangle shape of the given width and height size
|
||||
* @param width {Number} Width of the rectangle
|
||||
* @param height {Number} Height of the rectangle
|
||||
* @return {GeomSprite} GeomSprite instance.
|
||||
*/
|
||||
createRectangle(width: number, height: number): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.rect = new Rectangle(this.x, this.y, width, height);
|
||||
this.type = GeomSprite.RECTANGLE;
|
||||
this.frameBounds.copyFrom(this.rect);
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a polygon object
|
||||
* @param width {Number} Width of the rectangle
|
||||
* @param height {Number} Height of the rectangle
|
||||
* @return {GeomSprite} GeomSprite instance.
|
||||
*/
|
||||
createPolygon(points?: Vec2[] = []): GeomSprite {
|
||||
|
||||
//this.refresh();
|
||||
//this.polygon = new Polygon(new Vec2(this.x, this.y), points);
|
||||
//this.type = GeomSprite.POLYGON;
|
||||
//this.frameBounds.copyFrom(this.rect);
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all geom shapes of this sprite.
|
||||
*/
|
||||
refresh() {
|
||||
|
||||
this.circle = null;
|
||||
this.line = null;
|
||||
this.point = null;
|
||||
this.rect = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update bounds.
|
||||
*/
|
||||
update() {
|
||||
|
||||
// Update bounds and position?
|
||||
if (this.type == GeomSprite.UNASSIGNED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (this.type == 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 == 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 == GeomSprite.POINT)
|
||||
{
|
||||
this.point.x = this.x;
|
||||
this.point.y = this.y;
|
||||
}
|
||||
else if (this.type == GeomSprite.RECTANGLE)
|
||||
{
|
||||
this.rect.x = this.x;
|
||||
this.rect.y = this.y;
|
||||
this.frameBounds.copyFrom(this.rect);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
public inCamera(camera: Rectangle): bool {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool {
|
||||
|
||||
// Render checks
|
||||
//if (this.type == 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 == 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 == 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 == GeomSprite.POINT)
|
||||
{
|
||||
this.context.fillRect(this._dx, this._dy, 2, 2);
|
||||
}
|
||||
else if (this.type == 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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public renderPoint(point, offsetX?: number = 0, offsetY?: number = 0, size?: number = 1) {
|
||||
|
||||
this.context.fillRect(offsetX + point.x, offsetY + point.y, size, size);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
public renderDebugInfo(x: number, y: number, color?: string = '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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public collide(source: GeomSprite): bool {
|
||||
|
||||
// Circle vs. Circle
|
||||
if (this.type == GeomSprite.CIRCLE && source.type == GeomSprite.CIRCLE)
|
||||
{
|
||||
return Collision.circleToCircle(this.circle, source.circle).result;
|
||||
}
|
||||
|
||||
// Circle vs. Rect
|
||||
if (this.type == GeomSprite.CIRCLE && source.type == GeomSprite.RECTANGLE)
|
||||
{
|
||||
return Collision.circleToRectangle(this.circle, source.rect).result;
|
||||
}
|
||||
|
||||
// Circle vs. Point
|
||||
if (this.type == GeomSprite.CIRCLE && source.type == GeomSprite.POINT)
|
||||
{
|
||||
return Collision.circleContainsPoint(this.circle, source.point).result;
|
||||
}
|
||||
|
||||
// Circle vs. Line
|
||||
if (this.type == GeomSprite.CIRCLE && source.type == GeomSprite.LINE)
|
||||
{
|
||||
return Collision.lineToCircle(source.line, this.circle).result;
|
||||
}
|
||||
|
||||
// Rect vs. Rect
|
||||
if (this.type == GeomSprite.RECTANGLE && source.type == GeomSprite.RECTANGLE)
|
||||
{
|
||||
return Collision.rectangleToRectangle(this.rect, source.rect).result;
|
||||
}
|
||||
|
||||
// Rect vs. Circle
|
||||
if (this.type == GeomSprite.RECTANGLE && source.type == GeomSprite.CIRCLE)
|
||||
{
|
||||
return Collision.circleToRectangle(source.circle, this.rect).result;
|
||||
}
|
||||
|
||||
// Rect vs. Point
|
||||
if (this.type == GeomSprite.RECTANGLE && source.type == GeomSprite.POINT)
|
||||
{
|
||||
return Collision.pointToRectangle(source.point, this.rect).result;
|
||||
}
|
||||
|
||||
// Rect vs. Line
|
||||
if (this.type == GeomSprite.RECTANGLE && source.type == GeomSprite.LINE)
|
||||
{
|
||||
return Collision.lineToRectangle(source.line, this.rect).result;
|
||||
}
|
||||
|
||||
// Point vs. Point
|
||||
if (this.type == GeomSprite.POINT && source.type == GeomSprite.POINT)
|
||||
{
|
||||
return this.point.equals(source.point);
|
||||
}
|
||||
|
||||
// Point vs. Circle
|
||||
if (this.type == GeomSprite.POINT && source.type == GeomSprite.CIRCLE)
|
||||
{
|
||||
return Collision.circleContainsPoint(source.circle, this.point).result;
|
||||
}
|
||||
|
||||
// Point vs. Rect
|
||||
if (this.type == GeomSprite.POINT && source.type == GeomSprite.RECTANGLE)
|
||||
{
|
||||
return Collision.pointToRectangle(this.point, source.rect).result;
|
||||
}
|
||||
|
||||
// Point vs. Line
|
||||
if (this.type == GeomSprite.POINT && source.type == GeomSprite.LINE)
|
||||
{
|
||||
return source.line.isPointOnLine(this.point.x, this.point.y);
|
||||
}
|
||||
|
||||
// Line vs. Line
|
||||
if (this.type == GeomSprite.LINE && source.type == GeomSprite.LINE)
|
||||
{
|
||||
return Collision.lineSegmentToLineSegment(this.line, source.line).result;
|
||||
}
|
||||
|
||||
// Line vs. Circle
|
||||
if (this.type == GeomSprite.LINE && source.type == GeomSprite.CIRCLE)
|
||||
{
|
||||
return Collision.lineToCircle(this.line, source.circle).result;
|
||||
}
|
||||
|
||||
// Line vs. Rect
|
||||
if (this.type == GeomSprite.LINE && source.type == GeomSprite.RECTANGLE)
|
||||
{
|
||||
return Collision.lineSegmentToRectangle(this.line, source.rect).result;
|
||||
}
|
||||
|
||||
// Line vs. Point
|
||||
if (this.type == GeomSprite.LINE && source.type == GeomSprite.POINT)
|
||||
{
|
||||
return this.line.isPointOnLine(source.point.x, source.point.y);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,355 +0,0 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../AnimationManager.ts" />
|
||||
/// <reference path="GameObject.ts" />
|
||||
/// <reference path="../system/Camera.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Sprite
|
||||
*
|
||||
* The Sprite GameObject is an extension of the core GameObject that includes support for animation and dynamic textures.
|
||||
* It's probably the most used GameObject of all.
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class OldSprite {
|
||||
|
||||
/**
|
||||
* Sprite constructor
|
||||
* 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.
|
||||
* @param [width] {number} The width of the object.
|
||||
* @param [height] {number} The height of the object.
|
||||
*/
|
||||
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, width?: number = 16, height?: number = 16) {
|
||||
|
||||
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);
|
||||
|
||||
|
||||
this._texture = null;
|
||||
|
||||
this.animations = new AnimationManager(this._game, this);
|
||||
|
||||
if (key !== null)
|
||||
{
|
||||
this.cacheKey = key;
|
||||
this.loadGraphic(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.frameBounds.width = 16;
|
||||
this.frameBounds.height = 16;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The essential reference to the main game object
|
||||
*/
|
||||
public _game: Game;
|
||||
|
||||
/**
|
||||
* Controls whether <code>update()</code> is automatically called by State/Group.
|
||||
*/
|
||||
public active: bool;
|
||||
|
||||
/**
|
||||
* Controls whether <code>draw()</code> is automatically called by State/Group.
|
||||
*/
|
||||
public visible: bool;
|
||||
|
||||
/**
|
||||
* Setting this to true will prevent the object from being updated during the main game loop (you will have to call update on it yourself)
|
||||
*/
|
||||
public ignoreGlobalUpdate: bool;
|
||||
|
||||
/**
|
||||
* Setting this to true will prevent the object from being rendered during the main game loop (you will have to call render on it yourself)
|
||||
*/
|
||||
public ignoreGlobalRender: bool;
|
||||
|
||||
/**
|
||||
* An Array of Cameras to which this GameObject won't render
|
||||
* @type {Array}
|
||||
*/
|
||||
public cameraBlacklist: number[];
|
||||
|
||||
/**
|
||||
* Orientation of the object.
|
||||
* @type {number}
|
||||
*/
|
||||
public facing: number;
|
||||
|
||||
/**
|
||||
* Set alpha to a number between 0 and 1 to change the opacity.
|
||||
* @type {number}
|
||||
*/
|
||||
public alpha: number;
|
||||
|
||||
/**
|
||||
* Scale factor of the object.
|
||||
* @type {MicroPoint}
|
||||
*/
|
||||
public scale: MicroPoint;
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
public renderRotation: bool = true;
|
||||
|
||||
/**
|
||||
* A point that can store numbers from 0 to 1 (for X and Y independently)
|
||||
* which governs how much this object is affected by the camera .
|
||||
* @type {MicroPoint}
|
||||
*/
|
||||
public scrollFactor: MicroPoint;
|
||||
|
||||
/**
|
||||
* Rectangle container of this object.
|
||||
* @type {Rectangle}
|
||||
*/
|
||||
public frameBounds: Rectangle;
|
||||
|
||||
/**
|
||||
* This objects CollisionMask
|
||||
* @type {CollisionMask}
|
||||
*/
|
||||
public collisionMask: CollisionMask;
|
||||
|
||||
/**
|
||||
* A rectangular area which is object is allowed to exist within. If it travels outside of this area it will perform the outOfBoundsAction.
|
||||
* @type {Quad}
|
||||
*/
|
||||
public worldBounds: Quad;
|
||||
|
||||
/**
|
||||
* A reference to the Canvas this GameObject will render to
|
||||
* @type {HTMLCanvasElement}
|
||||
*/
|
||||
public canvas: HTMLCanvasElement;
|
||||
|
||||
/**
|
||||
* A reference to the Canvas Context2D this GameObject will render to
|
||||
* @type {CanvasRenderingContext2D}
|
||||
*/
|
||||
public context: CanvasRenderingContext2D;
|
||||
|
||||
/**
|
||||
* Texture of this sprite to be rendered.
|
||||
*/
|
||||
private _texture;
|
||||
|
||||
/**
|
||||
* Texture of this sprite is DynamicTexture? (default to false)
|
||||
* @type {boolean}
|
||||
*/
|
||||
private _dynamicTexture: bool = false;
|
||||
|
||||
|
||||
/**
|
||||
* This manages animations of the sprite. You can modify animations though it. (see AnimationManager)
|
||||
* @type AnimationManager
|
||||
*/
|
||||
public animations: AnimationManager;
|
||||
|
||||
/**
|
||||
* The cache key that was used for this texture (if any)
|
||||
*/
|
||||
public cacheKey: string;
|
||||
|
||||
|
||||
/**
|
||||
* Flip the graphic horizontally? (defaults to false)
|
||||
* @type {boolean}
|
||||
*/
|
||||
public flipped: bool = false;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Pre-update is called right before update() on each object in the game loop.
|
||||
*/
|
||||
public preUpdate() {
|
||||
|
||||
this.last.x = this.frameBounds.x;
|
||||
this.last.y = this.frameBounds.y;
|
||||
|
||||
this.collisionMask.preUpdate();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this function to update your class's position and appearance.
|
||||
*/
|
||||
public update() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically called after update() by the game loop.
|
||||
*/
|
||||
public postUpdate() {
|
||||
|
||||
this.animations.update();
|
||||
|
||||
if (this.moves)
|
||||
{
|
||||
this.updateMotion();
|
||||
}
|
||||
|
||||
if (this.worldBounds != null)
|
||||
{
|
||||
if (this.outOfBoundsAction == GameObject.OUT_OF_BOUNDS_KILL)
|
||||
{
|
||||
if (this.x < this.worldBounds.x || this.x > this.worldBounds.right || this.y < this.worldBounds.y || this.y > this.worldBounds.bottom)
|
||||
{
|
||||
this.kill();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.x < this.worldBounds.x)
|
||||
{
|
||||
this.x = this.worldBounds.x;
|
||||
}
|
||||
else if (this.x > this.worldBounds.right)
|
||||
{
|
||||
this.x = this.worldBounds.right;
|
||||
}
|
||||
|
||||
if (this.y < this.worldBounds.y)
|
||||
{
|
||||
this.y = this.worldBounds.y;
|
||||
}
|
||||
else if (this.y > this.worldBounds.bottom)
|
||||
{
|
||||
this.y = this.worldBounds.bottom;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.collisionMask.update();
|
||||
|
||||
if (this.inputEnabled)
|
||||
{
|
||||
this.updateInput();
|
||||
}
|
||||
|
||||
this.wasTouching = this.touching;
|
||||
this.touching = Collision.NONE;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up memory.
|
||||
*/
|
||||
public destroy() {
|
||||
}
|
||||
|
||||
public set width(value:number) {
|
||||
this.frameBounds.width = value;
|
||||
}
|
||||
|
||||
public set height(value:number) {
|
||||
this.frameBounds.height = value;
|
||||
}
|
||||
|
||||
public get width(): number {
|
||||
return this.frameBounds.width;
|
||||
}
|
||||
|
||||
public get height(): number {
|
||||
return this.frameBounds.height;
|
||||
}
|
||||
|
||||
public set frame(value: number) {
|
||||
this.animations.frame = value;
|
||||
}
|
||||
|
||||
public get frame(): number {
|
||||
return this.animations.frame;
|
||||
}
|
||||
|
||||
public set frameName(value: string) {
|
||||
this.animations.frameName = value;
|
||||
}
|
||||
|
||||
public get frameName(): string {
|
||||
return this.animations.frameName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public kill() {
|
||||
this.alive = false;
|
||||
this.exists = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>.
|
||||
*/
|
||||
public revive() {
|
||||
this.alive = true;
|
||||
this.exists = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert object to readable string name. Useful for debugging, save games, etc.
|
||||
*/
|
||||
public toString(): string {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,7 +51,7 @@ module Phaser {
|
||||
return;
|
||||
}
|
||||
|
||||
this.lifespan -= this._game.time.elapsed;
|
||||
this.lifespan -= this.game.time.elapsed;
|
||||
|
||||
if (this.lifespan <= 0)
|
||||
{
|
||||
@@ -59,39 +59,39 @@ module Phaser {
|
||||
}
|
||||
|
||||
//simpler bounce/spin behavior for now
|
||||
if (this.touching)
|
||||
if (this.body.touching)
|
||||
{
|
||||
if (this.angularVelocity != 0)
|
||||
if (this.body.angularVelocity != 0)
|
||||
{
|
||||
this.angularVelocity = -this.angularVelocity;
|
||||
this.body.angularVelocity = -this.body.angularVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.acceleration.y > 0) //special behavior for particles with gravity
|
||||
if (this.body.acceleration.y > 0) //special behavior for particles with gravity
|
||||
{
|
||||
if (this.touching & Collision.FLOOR)
|
||||
if (this.body.touching & Types.FLOOR)
|
||||
{
|
||||
this.drag.x = this.friction;
|
||||
this.body.drag.x = this.friction;
|
||||
|
||||
if (!(this.wasTouching & Collision.FLOOR))
|
||||
if (!(this.body.wasTouching & Types.FLOOR))
|
||||
{
|
||||
if (this.velocity.y < -this.elasticity * 10)
|
||||
if (this.body.velocity.y < -this.body.bounce.y * 10)
|
||||
{
|
||||
if (this.angularVelocity != 0)
|
||||
if (this.body.angularVelocity != 0)
|
||||
{
|
||||
this.angularVelocity *= -this.elasticity;
|
||||
this.body.angularVelocity *= -this.body.bounce.y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.velocity.y = 0;
|
||||
this.angularVelocity = 0;
|
||||
this.body.velocity.y = 0;
|
||||
this.body.angularVelocity = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.drag.x = 0;
|
||||
this.body.drag.x = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,10 @@ module Phaser {
|
||||
*/
|
||||
constructor(game: Game, key:string, x: number = 0, y: number = 0, width?: number = 0, height?: number = 0) {
|
||||
|
||||
super(game, x, y, key, width, height);
|
||||
super(game, x, y, key);
|
||||
|
||||
this.type = Phaser.Types.SCROLLZONE;
|
||||
this.render = game.renderer.renderScrollZone;
|
||||
this.physics.moves = false;
|
||||
|
||||
this.regions = [];
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
/// <reference path="../core/Rectangle.ts" />
|
||||
/// <reference path="../components/animation/AnimationManager.ts" />
|
||||
/// <reference path="../components/sprite/Texture.ts" />
|
||||
/// <reference path="../components/sprite/Physics.ts" />
|
||||
/// <reference path="../physics/Body.ts" />
|
||||
|
||||
/**
|
||||
@@ -24,7 +23,6 @@ module Phaser {
|
||||
* @param [key] {string} Key of the graphic you want to load for this sprite.
|
||||
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
|
||||
*/
|
||||
//constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, width?: number = 16, height?: number = 16) {
|
||||
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, bodyType?: number = Phaser.Types.BODY_DISABLED) {
|
||||
|
||||
this.game = game;
|
||||
@@ -46,6 +44,7 @@ module Phaser {
|
||||
|
||||
this.animations = new Phaser.Components.AnimationManager(this);
|
||||
this.texture = new Phaser.Components.Texture(this, key);
|
||||
this.cameraBlacklist = [];
|
||||
|
||||
// Transform related (if we add any more then move to a component)
|
||||
this.origin = new Phaser.Vec2(0, 0);
|
||||
@@ -108,6 +107,12 @@ module Phaser {
|
||||
*/
|
||||
public animations: Phaser.Components.AnimationManager;
|
||||
|
||||
/**
|
||||
* An Array of Cameras to which this GameObject won't render
|
||||
* @type {Array}
|
||||
*/
|
||||
public cameraBlacklist: number[];
|
||||
|
||||
/**
|
||||
* The frame boundary around this Sprite.
|
||||
* For non-animated sprites this matches the loaded texture dimensions.
|
||||
@@ -290,7 +295,7 @@ module Phaser {
|
||||
|
||||
*/
|
||||
|
||||
if (this.modified == true && this.scale.equals(1) && this.skew.equals(0) && this.rotation == 0 && this.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false)
|
||||
if (this.modified == true && this.scale.equals(1) && this.skew.equals(0) && this.angle == 0 && this.angleOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false)
|
||||
{
|
||||
this.modified = false;
|
||||
}
|
||||
@@ -303,6 +308,27 @@ module Phaser {
|
||||
public 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.
|
||||
*/
|
||||
public kill() {
|
||||
this.alive = false;
|
||||
this.exists = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>.
|
||||
*/
|
||||
public revive() {
|
||||
this.alive = true;
|
||||
this.exists = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,12 +27,17 @@ module Phaser {
|
||||
*/
|
||||
constructor(game: Game, key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0) {
|
||||
|
||||
//super(game);
|
||||
this.game = game;
|
||||
this.type = Phaser.Types.TILEMAP;
|
||||
|
||||
this.isGroup = false;
|
||||
this.exists = true;
|
||||
this.active = true;
|
||||
this.visible = true;
|
||||
this.alive = true;
|
||||
|
||||
this.tiles = [];
|
||||
this.layers = [];
|
||||
this.cameraBlacklist = [];
|
||||
|
||||
this.mapFormat = format;
|
||||
|
||||
@@ -49,18 +54,49 @@ module Phaser {
|
||||
|
||||
if (this.currentLayer && resizeWorld)
|
||||
{
|
||||
this._game.world.setSize(this.currentLayer.widthInPixels, this.currentLayer.heightInPixels, true);
|
||||
this.game.world.setSize(this.currentLayer.widthInPixels, this.currentLayer.heightInPixels, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private _tempCollisionData;
|
||||
|
||||
/**
|
||||
* Reference to the main game object
|
||||
*/
|
||||
public game: Game;
|
||||
|
||||
/**
|
||||
* The type of game object.
|
||||
*/
|
||||
public type: number;
|
||||
|
||||
/**
|
||||
* Controls if both <code>update</code> and render are called by the core game loop.
|
||||
*/
|
||||
public exists: bool;
|
||||
|
||||
/**
|
||||
* Controls if <code>update()</code> is automatically called by the core game loop.
|
||||
*/
|
||||
public active: bool;
|
||||
|
||||
/**
|
||||
* Controls if this Sprite is rendered or skipped during the core game loop.
|
||||
*/
|
||||
public visible: bool;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public alive: bool;
|
||||
|
||||
/**
|
||||
* Tilemap data format enum: CSV.
|
||||
* @type {number}
|
||||
*/
|
||||
public static FORMAT_CSV: number = 0;
|
||||
|
||||
/**
|
||||
* Tilemap data format enum: Tiled JSON.
|
||||
* @type {number}
|
||||
@@ -72,36 +108,48 @@ module Phaser {
|
||||
* @type {Tile[]}
|
||||
*/
|
||||
public tiles : Tile[];
|
||||
|
||||
/**
|
||||
* Array contains tilemap layer objects of this map.
|
||||
* @type {TilemapLayer[]}
|
||||
*/
|
||||
public layers : TilemapLayer[];
|
||||
|
||||
/**
|
||||
* Current tilemap layer.
|
||||
* @type {TilemapLayer}
|
||||
*/
|
||||
public currentLayer: TilemapLayer;
|
||||
|
||||
/**
|
||||
* The tilemap layer for collision.
|
||||
* @type {TilemapLayer}
|
||||
*/
|
||||
public collisionLayer: TilemapLayer;
|
||||
|
||||
/**
|
||||
* Tilemap collision callback.
|
||||
* @type {function}
|
||||
*/
|
||||
public collisionCallback = null;
|
||||
|
||||
/**
|
||||
* Context for the collision callback called with.
|
||||
*/
|
||||
public collisionCallbackContext;
|
||||
|
||||
/**
|
||||
* Format of this tilemap data. Available values: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON.
|
||||
* @type {number}
|
||||
*/
|
||||
public mapFormat: number;
|
||||
|
||||
/**
|
||||
* An Array of Cameras to which this GameObject won't render
|
||||
* @type {Array}
|
||||
*/
|
||||
public cameraBlacklist: number[];
|
||||
|
||||
/**
|
||||
* Inherited update method.
|
||||
*/
|
||||
@@ -136,7 +184,7 @@ module Phaser {
|
||||
*/
|
||||
private parseCSV(data: string, key: string, tileWidth: number, tileHeight: number) {
|
||||
|
||||
var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_CSV, 'TileLayerCSV' + this.layers.length.toString(), tileWidth, tileHeight);
|
||||
var layer: TilemapLayer = new TilemapLayer(this.game, this, key, Tilemap.FORMAT_CSV, 'TileLayerCSV' + this.layers.length.toString(), tileWidth, tileHeight);
|
||||
|
||||
// Trim any rogue whitespace from the data
|
||||
data = data.trim();
|
||||
@@ -179,7 +227,7 @@ module Phaser {
|
||||
|
||||
for (var i = 0; i < json.layers.length; i++)
|
||||
{
|
||||
var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight);
|
||||
var layer: TilemapLayer = new TilemapLayer(this.game, this, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight);
|
||||
|
||||
layer.alpha = json.layers[i].opacity;
|
||||
layer.visible = json.layers[i].visible;
|
||||
@@ -230,7 +278,7 @@ module Phaser {
|
||||
|
||||
for (var i = 0; i < qty; i++)
|
||||
{
|
||||
this.tiles.push(new Tile(this._game, this, i, this.currentLayer.tileWidth, this.currentLayer.tileHeight));
|
||||
this.tiles.push(new Tile(this.game, this, i, this.currentLayer.tileWidth, this.currentLayer.tileHeight));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -266,7 +314,7 @@ module Phaser {
|
||||
* @param separateX {boolean} Enable seprate at x-axis.
|
||||
* @param separateY {boolean} Enable seprate at y-axis.
|
||||
*/
|
||||
public setCollisionRange(start: number, end: number, collision?:number = Collision.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
|
||||
public setCollisionRange(start: number, end: number, collision?:number = Types.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
|
||||
|
||||
for (var i = start; i < end; i++)
|
||||
{
|
||||
@@ -283,7 +331,7 @@ module Phaser {
|
||||
* @param separateX {boolean} Enable seprate at x-axis.
|
||||
* @param separateY {boolean} Enable seprate at y-axis.
|
||||
*/
|
||||
public setCollisionByIndex(values:number[], collision?:number = Collision.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
|
||||
public setCollisionByIndex(values:number[], collision?:number = Types.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
|
||||
|
||||
for (var i = 0; i < values.length; i++)
|
||||
{
|
||||
@@ -338,7 +386,7 @@ module Phaser {
|
||||
|
||||
public getTileFromInputXY(layer?: number = 0):Tile {
|
||||
|
||||
return this.tiles[this.layers[layer].getTileFromWorldXY(this._game.input.getWorldX(), this._game.input.getWorldY())];
|
||||
return this.tiles[this.layers[layer].getTileFromWorldXY(this.game.input.getWorldX(), this.game.input.getWorldY())];
|
||||
|
||||
}
|
||||
|
||||
@@ -347,7 +395,7 @@ module Phaser {
|
||||
* @param object {GameObject} Tiles you want to get that overlaps this.
|
||||
* @return {array} Array with tiles informations. (Each contains x, y and the tile.)
|
||||
*/
|
||||
public getTileOverlaps(object: GameObject) {
|
||||
public getTileOverlaps(object: Sprite) {
|
||||
|
||||
return this.currentLayer.getTileOverlaps(object);
|
||||
|
||||
@@ -371,7 +419,7 @@ module Phaser {
|
||||
|
||||
if (objectOrGroup == null)
|
||||
{
|
||||
objectOrGroup = this._game.world.group;
|
||||
objectOrGroup = this.game.world.group;
|
||||
}
|
||||
|
||||
// Group?
|
||||
@@ -391,9 +439,9 @@ module Phaser {
|
||||
* @param object {GameObject} Target object you want to check.
|
||||
* @return {boolean} Return true if this collides with given object, otherwise return false.
|
||||
*/
|
||||
public collideGameObject(object: GameObject): bool {
|
||||
public collideGameObject(object: Sprite): bool {
|
||||
|
||||
if (object !== this && object.immovable == false && object.exists == true && object.allowCollisions != Collision.NONE)
|
||||
if (object.body.type == Types.BODY_DYNAMIC && object.exists == true && object.body.allowCollisions != Types.NONE)
|
||||
{
|
||||
this._tempCollisionData = this.collisionLayer.getTileOverlaps(object);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user