mirror of
https://github.com/wassname/phaser.git
synced 2026-09-12 12:40:47 +08:00
Lots of updates across input, rendering and grouping
This commit is contained in:
@@ -34,6 +34,7 @@ module Phaser {
|
||||
* Local private reference to game.
|
||||
*/
|
||||
private _game: Game;
|
||||
|
||||
/**
|
||||
* Local private reference to its owner sprite.
|
||||
*/
|
||||
@@ -43,11 +44,13 @@ module Phaser {
|
||||
* Animation key-value container.
|
||||
*/
|
||||
private _anims: {};
|
||||
|
||||
/**
|
||||
* Index of current frame.
|
||||
* @type {number}
|
||||
*/
|
||||
private _frameIndex: number;
|
||||
|
||||
/**
|
||||
* Data contains animation frames.
|
||||
* @type {FrameData}
|
||||
@@ -58,6 +61,7 @@ module Phaser {
|
||||
* Keeps track of the current animation being played.
|
||||
*/
|
||||
public currentAnim: Animation;
|
||||
|
||||
/**
|
||||
* Keeps track of the current frame of animation.
|
||||
*/
|
||||
|
||||
+14
-2
@@ -23,6 +23,8 @@ module Phaser {
|
||||
this.visible = true;
|
||||
this.alive = true;
|
||||
this.isGroup = false;
|
||||
this.ignoreGlobalUpdate = false;
|
||||
this.ignoreGlobalRender = false;
|
||||
this.ignoreDrawDebug = false;
|
||||
|
||||
}
|
||||
@@ -70,6 +72,16 @@ module Phaser {
|
||||
*/
|
||||
public alive: 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;
|
||||
|
||||
/**
|
||||
* Setting this to true will prevent the object from appearing
|
||||
* when the visual debug mode in the debugger overlay is toggled on.
|
||||
@@ -93,7 +105,7 @@ module Phaser {
|
||||
* Override this to update your class's position and appearance.
|
||||
* This is where most of your game rules and behavioral code will go.
|
||||
*/
|
||||
public update() {
|
||||
public update(forceUpdate?: bool = false) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +114,7 @@ module Phaser {
|
||||
public postUpdate() {
|
||||
}
|
||||
|
||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number, forceRender?: bool = false) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -239,6 +239,20 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array of GameObjects it will update each of them so that their canvas/contexts reference this DynamicTexture
|
||||
* @param objects {Array} An array of GameObjects, or objects that inherit from it such as Sprites
|
||||
*/
|
||||
public assignCanvasToGameObjects(objects: GameObject[]) {
|
||||
|
||||
for (var i = 0; i < objects.length; i++)
|
||||
{
|
||||
objects[i].canvas = this.canvas;
|
||||
objects[i].context = this.context;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the whole canvas.
|
||||
*/
|
||||
@@ -248,6 +262,18 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders this DynamicTexture to the Stage at the given x/y coordinates
|
||||
*
|
||||
* @param x {number} The X coordinate to render on the stage to (given in screen coordinates, not world)
|
||||
* @param y {number} The Y coordinate to render on the stage to (given in screen coordinates, not world)
|
||||
*/
|
||||
public render(x?: number = 0, y?: number = 0) {
|
||||
|
||||
this._game.stage.context.drawImage(this.canvas, x, y);
|
||||
|
||||
}
|
||||
|
||||
public get width(): number {
|
||||
return this.bounds.width;
|
||||
}
|
||||
|
||||
+3
-3
@@ -661,11 +661,11 @@ module Phaser {
|
||||
/**
|
||||
* Create a new object container.
|
||||
*
|
||||
* @param MaxSize {number} Optional, capacity of this group.
|
||||
* @param maxSize {number} Optional, capacity of this group.
|
||||
* @returns {Group} The newly created group.
|
||||
*/
|
||||
public createGroup(MaxSize?: number = 0): Group {
|
||||
return this.world.createGroup(MaxSize);
|
||||
public createGroup(maxSize?: number = 0): Group {
|
||||
return this.world.createGroup(maxSize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+17
-7
@@ -98,7 +98,12 @@ module Phaser {
|
||||
/**
|
||||
* Automatically goes through and calls update on everything you added.
|
||||
*/
|
||||
public update() {
|
||||
public update(forceUpdate?: bool = false) {
|
||||
|
||||
if (this.ignoreGlobalUpdate && forceUpdate == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var basic: Basic;
|
||||
var i: number = 0;
|
||||
@@ -107,10 +112,10 @@ module Phaser {
|
||||
{
|
||||
basic = this.members[i++];
|
||||
|
||||
if ((basic != null) && basic.exists && basic.active)
|
||||
if ((basic != null) && basic.exists && basic.active && basic.ignoreGlobalUpdate == false)
|
||||
{
|
||||
basic.preUpdate();
|
||||
basic.update();
|
||||
basic.update(forceUpdate);
|
||||
basic.postUpdate();
|
||||
}
|
||||
}
|
||||
@@ -119,7 +124,12 @@ module Phaser {
|
||||
/**
|
||||
* Automatically goes through and calls render on everything you added.
|
||||
*/
|
||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number, forceRender?: bool = false) {
|
||||
|
||||
if (this.ignoreGlobalRender && forceRender == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var basic: Basic;
|
||||
var i: number = 0;
|
||||
@@ -128,9 +138,9 @@ module Phaser {
|
||||
{
|
||||
basic = this.members[i++];
|
||||
|
||||
if ((basic != null) && basic.exists && basic.visible)
|
||||
if ((basic != null) && basic.exists && basic.visible && basic.ignoreGlobalRender == false)
|
||||
{
|
||||
basic.render(camera, cameraOffsetX, cameraOffsetY);
|
||||
basic.render(camera, cameraOffsetX, cameraOffsetY, forceRender);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,7 +199,7 @@ module Phaser {
|
||||
* @param {Basic} Object The object you want to add to the group.
|
||||
* @return {Basic} The same <code>Basic</code> object that was passed in.
|
||||
*/
|
||||
public add(Object: Basic) {
|
||||
public add(Object: Basic): any {
|
||||
|
||||
//Don't bother adding an object twice.
|
||||
if (this.members.indexOf(Object) >= 0)
|
||||
|
||||
+9
-2
@@ -32,26 +32,32 @@ module Phaser {
|
||||
* Local private reference to game.
|
||||
*/
|
||||
private _game: Game;
|
||||
|
||||
/**
|
||||
* Array stors assets keys. So you can get that asset by its unique key.
|
||||
*/
|
||||
private _keys: string[];
|
||||
|
||||
/**
|
||||
* Contains all the assets file infos.
|
||||
*/
|
||||
private _fileList;
|
||||
|
||||
/**
|
||||
* Game initialial assets loading callback.
|
||||
*/
|
||||
private _gameCreateComplete;
|
||||
private _onComplete;
|
||||
private _onFileLoad;
|
||||
|
||||
/**
|
||||
* Indicates assets loading progress. (from 0 to 100)
|
||||
* @type {number}
|
||||
*/
|
||||
private _progressChunk: number;
|
||||
|
||||
private _xhr: XMLHttpRequest;
|
||||
|
||||
/**
|
||||
* Length of assets queue.
|
||||
* @type {number}
|
||||
@@ -63,6 +69,7 @@ module Phaser {
|
||||
* @type {boolean}
|
||||
*/
|
||||
public hasLoaded: bool;
|
||||
|
||||
/**
|
||||
* Loading progress (from 0 to 1)
|
||||
* @type {number}
|
||||
@@ -404,9 +411,9 @@ module Phaser {
|
||||
|
||||
this.progress = Math.round(this.progress + this._progressChunk);
|
||||
|
||||
if (this.progress > 1)
|
||||
if (this.progress > 100)
|
||||
{
|
||||
this.progress = 1;
|
||||
this.progress = 100;
|
||||
}
|
||||
|
||||
if (this._onFileLoad)
|
||||
|
||||
+3
-3
@@ -196,11 +196,11 @@ module Phaser {
|
||||
/**
|
||||
* Create a new object container.
|
||||
*
|
||||
* @param MaxSize {number} [optional] capacity of this group.
|
||||
* @param maxSize {number} [optional] capacity of this group.
|
||||
* @returns {Group} The newly created group.
|
||||
*/
|
||||
public createGroup(MaxSize?: number = 0): Group {
|
||||
return this.game.world.createGroup(MaxSize);
|
||||
public createGroup(maxSize?: number = 0): Group {
|
||||
return this.game.world.createGroup(maxSize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-3
@@ -222,11 +222,11 @@ module Phaser {
|
||||
/**
|
||||
* Create a new object container.
|
||||
*
|
||||
* @param [MaxSize] {number} capacity of this group.
|
||||
* @param [maxSize] {number} capacity of this group.
|
||||
* @returns {Group} The newly created group.
|
||||
*/
|
||||
public createGroup(MaxSize?: number = 0): Group {
|
||||
return <Group> this.group.add(new Group(this._game, MaxSize));
|
||||
public createGroup(maxSize?: number = 0): Group {
|
||||
return <Group> this.group.add(new Group(this._game, maxSize));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,14 +17,16 @@ module Phaser {
|
||||
* 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.
|
||||
* @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.
|
||||
*/
|
||||
constructor(game: Game, X: number = 0, Y: number = 0, Size: number = 0) {
|
||||
super(game, Size);
|
||||
this.x = X;
|
||||
this.y = Y;
|
||||
constructor(game: Game, x: number = 0, y: number = 0, size: number = 0) {
|
||||
|
||||
super(game, size);
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
this.minParticleSpeed = new MicroPoint(-100, -100);
|
||||
@@ -42,6 +44,7 @@ module Phaser {
|
||||
this._explode = true;
|
||||
this.on = false;
|
||||
this._point = new MicroPoint();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,9 @@ module Phaser {
|
||||
|
||||
super(game);
|
||||
|
||||
this.canvas = game.stage.canvas;
|
||||
this.context = game.stage.context;
|
||||
|
||||
this.bounds = new Rectangle(x, y, width, height);
|
||||
this.exists = true;
|
||||
this.active = true;
|
||||
@@ -126,7 +129,6 @@ module Phaser {
|
||||
*/
|
||||
public static ALIGN_BOTTOM_RIGHT: number = 8;
|
||||
|
||||
|
||||
/**
|
||||
* Enum value for outOfBoundsAction. Stop the object when is out of world bounds.
|
||||
* @type {number}
|
||||
@@ -139,12 +141,28 @@ module Phaser {
|
||||
*/
|
||||
public static OUT_OF_BOUNDS_KILL: number = 1;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Position of this object after scrolling.
|
||||
* @type {MicroPoint}
|
||||
*/
|
||||
public _point: MicroPoint;
|
||||
|
||||
/**
|
||||
* An Array of Cameras to which this GameObject won't render
|
||||
* @type {Array}
|
||||
*/
|
||||
public cameraBlacklist: number[];
|
||||
|
||||
/**
|
||||
@@ -352,8 +370,6 @@ module Phaser {
|
||||
*/
|
||||
public preUpdate() {
|
||||
|
||||
// flicker time
|
||||
|
||||
this.last.x = this.bounds.x;
|
||||
this.last.y = this.bounds.y;
|
||||
|
||||
@@ -761,6 +777,18 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public setBoundsFromWorld(action?: number = 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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* If you do not wish this object to be visible to a specific camera, pass the camera here.
|
||||
*
|
||||
|
||||
@@ -46,21 +46,25 @@ module Phaser {
|
||||
* 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}
|
||||
@@ -72,16 +76,19 @@ module Phaser {
|
||||
* @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}
|
||||
@@ -93,6 +100,7 @@ module Phaser {
|
||||
* @type {boolean}
|
||||
*/
|
||||
public renderOutline: bool = true;
|
||||
|
||||
/**
|
||||
* Fill the shape or not. (default is true)
|
||||
* @type {boolean}
|
||||
@@ -104,11 +112,13 @@ module Phaser {
|
||||
* @type {number}
|
||||
*/
|
||||
public lineWidth: number = 1;
|
||||
|
||||
/**
|
||||
* Width of outline. (default is 1)
|
||||
* @type {number}
|
||||
*/
|
||||
public lineColor: string = 'rgb(0,255,0)';
|
||||
|
||||
/**
|
||||
* Width of outline. (default is 1)
|
||||
* @type {number}
|
||||
@@ -322,8 +332,8 @@ module Phaser {
|
||||
// Alpha
|
||||
if (this.alpha !== 1)
|
||||
{
|
||||
var globalAlpha = this._game.stage.context.globalAlpha;
|
||||
this._game.stage.context.globalAlpha = this.alpha;
|
||||
var globalAlpha = this.context.globalAlpha;
|
||||
this.context.globalAlpha = this.alpha;
|
||||
}
|
||||
|
||||
this._dx = cameraOffsetX + (this.bounds.x - camera.worldView.x);
|
||||
@@ -349,9 +359,9 @@ module Phaser {
|
||||
/*
|
||||
if (this.angle !== 0)
|
||||
{
|
||||
this._game.stage.context.save();
|
||||
this._game.stage.context.translate(this._dx + (this._dw / 2) - this.origin.x, this._dy + (this._dh / 2) - this.origin.y);
|
||||
this._game.stage.context.rotate(this.angle * (Math.PI / 180));
|
||||
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);
|
||||
}
|
||||
@@ -365,12 +375,12 @@ module Phaser {
|
||||
this._game.stage.saveCanvasValues();
|
||||
|
||||
// Debug
|
||||
//this._game.stage.context.fillStyle = 'rgba(255,0,0,0.5)';
|
||||
//this._game.stage.context.fillRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
//this.context.fillStyle = 'rgba(255,0,0,0.5)';
|
||||
//this.context.fillRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
|
||||
this._game.stage.context.lineWidth = this.lineWidth;
|
||||
this._game.stage.context.strokeStyle = this.lineColor;
|
||||
this._game.stage.context.fillStyle = this.fillColor;
|
||||
this.context.lineWidth = this.lineWidth;
|
||||
this.context.strokeStyle = this.lineColor;
|
||||
this.context.fillStyle = this.fillColor;
|
||||
|
||||
if (this._game.stage.fillStyle !== this.fillColor)
|
||||
{
|
||||
@@ -379,52 +389,52 @@ module Phaser {
|
||||
// Primitive Renderer
|
||||
if (this.type == GeomSprite.CIRCLE)
|
||||
{
|
||||
this._game.stage.context.beginPath();
|
||||
this._game.stage.context.arc(this._dx, this._dy, this.circle.radius, 0, Math.PI * 2);
|
||||
this._game.stage.context.stroke();
|
||||
this.context.beginPath();
|
||||
this.context.arc(this._dx, this._dy, this.circle.radius, 0, Math.PI * 2);
|
||||
this.context.stroke();
|
||||
|
||||
if (this.renderFill)
|
||||
{
|
||||
this._game.stage.context.fill();
|
||||
this.context.fill();
|
||||
}
|
||||
|
||||
this._game.stage.context.closePath();
|
||||
this.context.closePath();
|
||||
}
|
||||
else if (this.type == GeomSprite.LINE)
|
||||
{
|
||||
this._game.stage.context.beginPath();
|
||||
this._game.stage.context.moveTo(this._dx, this._dy);
|
||||
this._game.stage.context.lineTo(this.line.x2, this.line.y2);
|
||||
this._game.stage.context.stroke();
|
||||
this._game.stage.context.closePath();
|
||||
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._game.stage.context.fillRect(this._dx, this._dy, 2, 2);
|
||||
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._game.stage.context.fillRect(this._dx, this._dy, this.rect.width, this.rect.height);
|
||||
this.context.fillRect(this._dx, this._dy, this.rect.width, this.rect.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._game.stage.context.beginPath();
|
||||
this._game.stage.context.rect(this._dx, this._dy, this.rect.width, this.rect.height);
|
||||
this._game.stage.context.stroke();
|
||||
this.context.beginPath();
|
||||
this.context.rect(this._dx, this._dy, this.rect.width, this.rect.height);
|
||||
this.context.stroke();
|
||||
|
||||
if (this.renderFill)
|
||||
{
|
||||
this._game.stage.context.fill();
|
||||
this.context.fill();
|
||||
}
|
||||
|
||||
this._game.stage.context.closePath();
|
||||
this.context.closePath();
|
||||
}
|
||||
|
||||
// And now the edge points
|
||||
this._game.stage.context.fillStyle = 'rgb(255,255,255)';
|
||||
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);
|
||||
@@ -450,13 +460,13 @@ module Phaser {
|
||||
|
||||
if (this.rotation !== 0)
|
||||
{
|
||||
this._game.stage.context.translate(0, 0);
|
||||
this._game.stage.context.restore();
|
||||
this.context.translate(0, 0);
|
||||
this.context.restore();
|
||||
}
|
||||
|
||||
if (globalAlpha > -1)
|
||||
{
|
||||
this._game.stage.context.globalAlpha = globalAlpha;
|
||||
this.context.globalAlpha = globalAlpha;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -472,7 +482,7 @@ module Phaser {
|
||||
*/
|
||||
public renderPoint(point, offsetX?: number = 0, offsetY?: number = 0, size?: number = 1) {
|
||||
|
||||
this._game.stage.context.fillRect(offsetX + point.x, offsetY + point.y, size, size);
|
||||
this.context.fillRect(offsetX + point.x, offsetY + point.y, size, size);
|
||||
|
||||
}
|
||||
|
||||
@@ -484,11 +494,11 @@ module Phaser {
|
||||
*/
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
|
||||
//this._game.stage.context.fillStyle = color;
|
||||
//this._game.stage.context.fillText('Sprite: ' + this.name + ' (' + this.bounds.width + ' x ' + this.bounds.height + ')', x, y);
|
||||
//this._game.stage.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' rotation: ' + this.angle.toFixed(1), x, y + 14);
|
||||
//this._game.stage.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._game.stage.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);
|
||||
//this.context.fillStyle = color;
|
||||
//this.context.fillText('Sprite: ' + this.name + ' (' + this.bounds.width + ' x ' + this.bounds.height + ')', x, y);
|
||||
//this.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class ScrollRegion{
|
||||
export class ScrollRegion {
|
||||
|
||||
/**
|
||||
* ScrollRegion constructor
|
||||
@@ -54,6 +54,7 @@ module Phaser {
|
||||
* @type {boolean}
|
||||
*/
|
||||
public visible: bool = true;
|
||||
|
||||
/**
|
||||
* Region scrolling speed.
|
||||
* @type {MicroPoint}
|
||||
|
||||
@@ -202,8 +202,8 @@ module Phaser {
|
||||
// Alpha
|
||||
if (this.alpha !== 1)
|
||||
{
|
||||
var globalAlpha = this._game.stage.context.globalAlpha;
|
||||
this._game.stage.context.globalAlpha = this.alpha;
|
||||
var globalAlpha = this.context.globalAlpha;
|
||||
this.context.globalAlpha = this.alpha;
|
||||
}
|
||||
|
||||
this._dx = cameraOffsetX + (this.bounds.topLeft.x - camera.worldView.x);
|
||||
@@ -221,12 +221,12 @@ module Phaser {
|
||||
// Rotation - needs to work from origin point really, but for now from center
|
||||
if (this.angle !== 0 || this.flipped == true)
|
||||
{
|
||||
this._game.stage.context.save();
|
||||
this._game.stage.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
||||
this.context.save();
|
||||
this.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
||||
|
||||
if (this.angle !== 0)
|
||||
{
|
||||
this._game.stage.context.rotate(this.angle * (Math.PI / 180));
|
||||
this.context.rotate(this.angle * (Math.PI / 180));
|
||||
}
|
||||
|
||||
this._dx = -(this._dw / 2);
|
||||
@@ -234,7 +234,7 @@ module Phaser {
|
||||
|
||||
if (this.flipped == true)
|
||||
{
|
||||
this._game.stage.context.scale(-1, 1);
|
||||
this.context.scale(-1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,17 +247,17 @@ module Phaser {
|
||||
{
|
||||
if (this._dynamicTexture)
|
||||
{
|
||||
this.regions[i].render(this._game.stage.context, this._dynamicTexture.canvas, this._dx, this._dy, this._dw, this._dh);
|
||||
this.regions[i].render(this.context, this._dynamicTexture.canvas, this._dx, this._dy, this._dw, this._dh);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.regions[i].render(this._game.stage.context, this._texture, this._dx, this._dy, this._dw, this._dh);
|
||||
this.regions[i].render(this.context, this._texture, this._dx, this._dy, this._dw, this._dh);
|
||||
}
|
||||
}
|
||||
|
||||
if (globalAlpha > -1)
|
||||
{
|
||||
this._game.stage.context.globalAlpha = globalAlpha;
|
||||
this.context.globalAlpha = globalAlpha;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -232,8 +232,8 @@ module Phaser {
|
||||
// Alpha
|
||||
if (this.alpha !== 1)
|
||||
{
|
||||
var globalAlpha = this._game.stage.context.globalAlpha;
|
||||
this._game.stage.context.globalAlpha = this.alpha;
|
||||
var globalAlpha = this.context.globalAlpha;
|
||||
this.context.globalAlpha = this.alpha;
|
||||
}
|
||||
|
||||
this._sx = 0;
|
||||
@@ -304,12 +304,12 @@ module Phaser {
|
||||
// Rotation - needs to work from origin point really, but for now from center
|
||||
if (this.angle !== 0 || this.rotationOffset !== 0 || this.flipped == true)
|
||||
{
|
||||
this._game.stage.context.save();
|
||||
this._game.stage.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
||||
this.context.save();
|
||||
this.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
||||
|
||||
if (this.renderRotation == true && (this.angle !== 0 || this.rotationOffset !== 0))
|
||||
{
|
||||
this._game.stage.context.rotate((this.rotationOffset + this.angle) * (Math.PI / 180));
|
||||
this.context.rotate((this.rotationOffset + this.angle) * (Math.PI / 180));
|
||||
}
|
||||
|
||||
this._dx = -(this._dw / 2);
|
||||
@@ -317,7 +317,7 @@ module Phaser {
|
||||
|
||||
if (this.flipped == true)
|
||||
{
|
||||
this._game.stage.context.scale(-1, 1);
|
||||
this.context.scale(-1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ module Phaser {
|
||||
{
|
||||
if (this._dynamicTexture)
|
||||
{
|
||||
this._game.stage.context.drawImage(
|
||||
this.context.drawImage(
|
||||
this._texture.canvas, // Source Image
|
||||
this._sx, // Source X (location within the source image)
|
||||
this._sy, // Source Y
|
||||
@@ -348,7 +348,7 @@ module Phaser {
|
||||
}
|
||||
else
|
||||
{
|
||||
this._game.stage.context.drawImage(
|
||||
this.context.drawImage(
|
||||
this._texture, // Source Image
|
||||
this._sx, // Source X (location within the source image)
|
||||
this._sy, // Source Y
|
||||
@@ -363,14 +363,14 @@ module Phaser {
|
||||
}
|
||||
else
|
||||
{
|
||||
this._game.stage.context.fillStyle = this.fillColor;
|
||||
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
||||
this.context.fillStyle = this.fillColor;
|
||||
this.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
||||
}
|
||||
|
||||
if (this.flipped === true || this.rotation !== 0 || this.rotationOffset !== 0)
|
||||
{
|
||||
//this._game.stage.context.translate(0, 0);
|
||||
this._game.stage.context.restore();
|
||||
//this.context.translate(0, 0);
|
||||
this.context.restore();
|
||||
}
|
||||
|
||||
if (this.renderDebug)
|
||||
@@ -380,7 +380,7 @@ module Phaser {
|
||||
|
||||
if (globalAlpha > -1)
|
||||
{
|
||||
this._game.stage.context.globalAlpha = globalAlpha;
|
||||
this.context.globalAlpha = globalAlpha;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -398,24 +398,24 @@ module Phaser {
|
||||
this._dx = cameraOffsetX + (this.bounds.topLeft.x - camera.worldView.x);
|
||||
this._dy = cameraOffsetY + (this.bounds.topLeft.y - camera.worldView.y);
|
||||
|
||||
this._game.stage.context.fillStyle = this.renderDebugColor;
|
||||
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
||||
this._game.stage.context.fillStyle = this.renderDebugPointColor;
|
||||
this.context.fillStyle = this.renderDebugColor;
|
||||
this.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
||||
this.context.fillStyle = this.renderDebugPointColor;
|
||||
|
||||
var hw = this.bounds.halfWidth * this.scale.x;
|
||||
var hh = this.bounds.halfHeight * this.scale.y;
|
||||
var sw = (this.bounds.width * this.scale.x) - 1;
|
||||
var sh = (this.bounds.height * this.scale.y) - 1;
|
||||
|
||||
this._game.stage.context.fillRect(this._dx, this._dy, 1, 1); // top left
|
||||
this._game.stage.context.fillRect(this._dx + hw, this._dy, 1, 1); // top center
|
||||
this._game.stage.context.fillRect(this._dx + sw, this._dy, 1, 1); // top right
|
||||
this._game.stage.context.fillRect(this._dx, this._dy + hh, 1, 1); // left center
|
||||
this._game.stage.context.fillRect(this._dx + hw, this._dy + hh, 1, 1); // center
|
||||
this._game.stage.context.fillRect(this._dx + sw, this._dy + hh, 1, 1); // right center
|
||||
this._game.stage.context.fillRect(this._dx, this._dy + sh, 1, 1); // bottom left
|
||||
this._game.stage.context.fillRect(this._dx + hw, this._dy + sh, 1, 1); // bottom center
|
||||
this._game.stage.context.fillRect(this._dx + sw, this._dy + sh, 1, 1); // bottom right
|
||||
this.context.fillRect(this._dx, this._dy, 1, 1); // top left
|
||||
this.context.fillRect(this._dx + hw, this._dy, 1, 1); // top center
|
||||
this.context.fillRect(this._dx + sw, this._dy, 1, 1); // top right
|
||||
this.context.fillRect(this._dx, this._dy + hh, 1, 1); // left center
|
||||
this.context.fillRect(this._dx + hw, this._dy + hh, 1, 1); // center
|
||||
this.context.fillRect(this._dx + sw, this._dy + hh, 1, 1); // right center
|
||||
this.context.fillRect(this._dx, this._dy + sh, 1, 1); // bottom left
|
||||
this.context.fillRect(this._dx + hw, this._dy + sh, 1, 1); // bottom center
|
||||
this.context.fillRect(this._dx + sw, this._dy + sh, 1, 1); // bottom right
|
||||
|
||||
}
|
||||
|
||||
@@ -427,11 +427,11 @@ module Phaser {
|
||||
*/
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
|
||||
this._game.stage.context.fillStyle = color;
|
||||
this._game.stage.context.fillText('Sprite: ' + this.name + ' (' + this.bounds.width + ' x ' + this.bounds.height + ')', x, y);
|
||||
this._game.stage.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' rotation: ' + this.angle.toFixed(1), x, y + 14);
|
||||
this._game.stage.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._game.stage.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);
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillText('Sprite: ' + this.name + ' (' + this.bounds.width + ' x ' + this.bounds.height + ')', x, y);
|
||||
this.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,9 @@ module Phaser {
|
||||
this.boundsInTiles = new Rectangle();
|
||||
//this.scrollFactor = new MicroPoint(1, 1);
|
||||
|
||||
this.canvas = game.stage.canvas;
|
||||
this.context = game.stage.context;
|
||||
|
||||
this.mapData = [];
|
||||
this._tempTileBlock = [];
|
||||
this._texture = this._game.cache.getImage(key);
|
||||
@@ -44,11 +47,13 @@ module Phaser {
|
||||
* Local private reference to game.
|
||||
*/
|
||||
private _game: Game;
|
||||
|
||||
/**
|
||||
* The tilemap that contains this layer.
|
||||
* @type {Tilemap}
|
||||
*/
|
||||
private _parent: Tilemap;
|
||||
|
||||
/**
|
||||
* Tileset of this layer.
|
||||
*/
|
||||
@@ -78,26 +83,43 @@ module Phaser {
|
||||
* @type {string}
|
||||
*/
|
||||
public name: string;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Opacity of this layer.
|
||||
* @type {number}
|
||||
*/
|
||||
public alpha: number = 1;
|
||||
|
||||
/**
|
||||
* Controls whether update() and draw() are automatically called.
|
||||
* @type {boolean}
|
||||
*/
|
||||
public exists: bool = true;
|
||||
|
||||
/**
|
||||
* Controls whether draw() are automatically called.
|
||||
* @type {boolean}
|
||||
*/
|
||||
public visible: bool = true;
|
||||
|
||||
//public scrollFactor: MicroPoint;
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
public orientation: string;
|
||||
|
||||
/**
|
||||
* Properties of this map layer. (normally set by map editors)
|
||||
*/
|
||||
@@ -108,10 +130,12 @@ module Phaser {
|
||||
* @type {number[][]}
|
||||
*/
|
||||
public mapData;
|
||||
|
||||
/**
|
||||
* Format of this map data, available: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON.
|
||||
*/
|
||||
public mapFormat: number;
|
||||
|
||||
/**
|
||||
* It's width and height are in tiles instead of pixels.
|
||||
* @type {Rectangle}
|
||||
@@ -123,6 +147,7 @@ module Phaser {
|
||||
* @type {number}
|
||||
*/
|
||||
public tileWidth: number;
|
||||
|
||||
/**
|
||||
* Height of a single tile.
|
||||
* @type {number}
|
||||
@@ -135,6 +160,7 @@ module Phaser {
|
||||
* @type {number}
|
||||
*/
|
||||
public widthInTiles: number = 0;
|
||||
|
||||
/**
|
||||
* How many tiles in each column.
|
||||
* Read-only variable, do NOT recommend changing after the map is loaded!
|
||||
@@ -147,6 +173,7 @@ module Phaser {
|
||||
* @type {number}
|
||||
*/
|
||||
public widthInPixels: number = 0;
|
||||
|
||||
/**
|
||||
* Read-only variable, do NOT recommend changing after the map is loaded!
|
||||
* @type {number}
|
||||
@@ -158,6 +185,7 @@ module Phaser {
|
||||
* @type {number}
|
||||
*/
|
||||
public tileMargin: number = 0;
|
||||
|
||||
/**
|
||||
* Distance between every 2 neighbor tile in the tileset texture.
|
||||
* @type {number}
|
||||
@@ -502,11 +530,11 @@ module Phaser {
|
||||
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
|
||||
this._game.stage.context.fillStyle = color;
|
||||
this._game.stage.context.fillText('TilemapLayer: ' + this.name, x, y);
|
||||
this._game.stage.context.fillText('startX: ' + this._startX + ' endX: ' + this._maxX, x, y + 14);
|
||||
this._game.stage.context.fillText('startY: ' + this._startY + ' endY: ' + this._maxY, x, y + 28);
|
||||
this._game.stage.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42);
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillText('TilemapLayer: ' + this.name, x, y);
|
||||
this.context.fillText('startX: ' + this._startX + ' endX: ' + this._maxX, x, y + 14);
|
||||
this.context.fillText('startY: ' + this._startY + ' endY: ' + this._maxY, x, y + 28);
|
||||
this.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42);
|
||||
|
||||
}
|
||||
|
||||
@@ -585,8 +613,8 @@ module Phaser {
|
||||
// Alpha
|
||||
if (this.alpha !== 1)
|
||||
{
|
||||
var globalAlpha = this._game.stage.context.globalAlpha;
|
||||
this._game.stage.context.globalAlpha = this.alpha;
|
||||
var globalAlpha = this.context.globalAlpha;
|
||||
this.context.globalAlpha = this.alpha;
|
||||
}
|
||||
|
||||
for (var row = this._startY; row < this._startY + this._maxY; row++)
|
||||
@@ -597,7 +625,7 @@ module Phaser {
|
||||
{
|
||||
if (this._tileOffsets[this._columnData[tile]])
|
||||
{
|
||||
this._game.stage.context.drawImage(
|
||||
this.context.drawImage(
|
||||
this._texture, // Source Image
|
||||
this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image)
|
||||
this._tileOffsets[this._columnData[tile]].y, // Source Y
|
||||
@@ -622,13 +650,12 @@ module Phaser {
|
||||
|
||||
if (globalAlpha > -1)
|
||||
{
|
||||
this._game.stage.context.globalAlpha = globalAlpha;
|
||||
this.context.globalAlpha = globalAlpha;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,6 @@ module Phaser {
|
||||
this.onDown = new Phaser.Signal();
|
||||
this.onUp = new Phaser.Signal();
|
||||
this.onTap = new Phaser.Signal();
|
||||
this.onDoubleTap = new Phaser.Signal();
|
||||
this.onHold = new Phaser.Signal();
|
||||
|
||||
this.currentPointers = 0;
|
||||
@@ -164,17 +163,12 @@ module Phaser {
|
||||
public onUp: Phaser.Signal;
|
||||
|
||||
/**
|
||||
* A Signal dispatched when a Pointer object (including the mouse) is tapped: pressed and released quickly
|
||||
* A Signal dispatched when a Pointer object (including the mouse) is tapped: pressed and released quickly.
|
||||
* The signal sends 2 parameters. The Pointer that caused it and a boolean depending if the tap was a single tap or a double tap.
|
||||
* @type {Phaser.Signal}
|
||||
*/
|
||||
public onTap: Phaser.Signal;
|
||||
|
||||
/**
|
||||
* A Signal dispatched when a Pointer object (including the mouse) is double tapped: pressed and released quickly twice in succession
|
||||
* @type {Phaser.Signal}
|
||||
*/
|
||||
public onDoubleTap: Phaser.Signal;
|
||||
|
||||
/**
|
||||
* A Signal dispatched when a Pointer object (including the mouse) is held down
|
||||
* @type {Phaser.Signal}
|
||||
@@ -193,7 +187,7 @@ module Phaser {
|
||||
* @property doubleTapRate
|
||||
* @type {Number}
|
||||
**/
|
||||
public doubleTapRate: number = 250;
|
||||
public doubleTapRate: number = 300;
|
||||
|
||||
/**
|
||||
* The number of milliseconds that the Pointer has to be pressed down for it to fire a onHold event
|
||||
@@ -395,7 +389,6 @@ module Phaser {
|
||||
this.onDown = new Phaser.Signal();
|
||||
this.onUp = new Phaser.Signal();
|
||||
this.onTap = new Phaser.Signal();
|
||||
this.onDoubleTap = new Phaser.Signal();
|
||||
this.onHold = new Phaser.Signal();
|
||||
|
||||
this.currentPointers = 0;
|
||||
|
||||
@@ -401,7 +401,7 @@ module Phaser {
|
||||
*/
|
||||
public stop(event): Pointer {
|
||||
|
||||
console.log('duration', this.duration);
|
||||
this.timeUp = this._game.time.now;
|
||||
|
||||
if (this._game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this._game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this._game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this._game.input.currentPointers == 0))
|
||||
{
|
||||
@@ -410,13 +410,16 @@ module Phaser {
|
||||
// Was it a tap?
|
||||
if (this.duration >= 0 && this.duration <= this._game.input.tapRate)
|
||||
{
|
||||
// Yes, let's dispatch the signal
|
||||
this._game.input.onTap.dispatch(this);
|
||||
|
||||
// Was it a double-tap?
|
||||
if (this.timeUp - this.previousTapTime < this._game.input.doubleTapRate)
|
||||
{
|
||||
this._game.input.onDoubleTap.dispatch(this);
|
||||
// Yes, let's dispatch the signal then with the 2nd parameter set to true
|
||||
this._game.input.onTap.dispatch(this, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Wasn't a double-tap, so dispatch a single tap signal
|
||||
this._game.input.onTap.dispatch(this, false);
|
||||
}
|
||||
|
||||
this.previousTapTime = this.timeUp;
|
||||
@@ -426,10 +429,8 @@ module Phaser {
|
||||
|
||||
this.active = false;
|
||||
this.withinGame = false;
|
||||
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
this.timeUp = this._game.time.now;
|
||||
|
||||
if (this.isMouse == false)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user