Set the default camera to direct itself to the Stage.

This commit is contained in:
Richard Davey
2013-08-09 18:44:45 +01:00
parent f9776f30fc
commit 0b1bcaf270
19 changed files with 376 additions and 172 deletions
+2 -1
View File
@@ -175,7 +175,7 @@ var Phaser;
//this.physics = new Phaser.Physics.Manager(this);
this.plugins = new Phaser.PluginManager(this, this);
this.load.onLoadComplete.addOnce(this.loadComplete, this);
this.load.onLoadComplete.add(this.loadComplete, this);
this.setRenderer(Phaser.Types.RENDERER_CANVAS);
@@ -301,6 +301,7 @@ var Phaser;
this._loadComplete = true;
} else {
// Start the loader going as we have something in the queue
this.load.onLoadComplete.add(this.loadComplete, this);
this.load.start();
}
} else {
-4
View File
@@ -387,10 +387,6 @@ module Phaser {
}
private emptyCallback() {
// Called by onUpdateCallback etc
}
/**
* Game loop method will be called when it's running.
*/
+5 -22
View File
@@ -56,25 +56,15 @@ var Phaser;
this.canvas = document.createElement('canvas');
this.canvas.width = width;
this.canvas.height = height;
this.context = this.canvas.getContext('2d');
if ((parent !== '' || parent !== null) && document.getElementById(parent)) {
document.getElementById(parent).appendChild(this.canvas);
document.getElementById(parent).style.overflow = 'hidden';
} else {
document.body.appendChild(this.canvas);
}
Phaser.CanvasUtils.addToDOM(this.canvas, parent, true);
Phaser.CanvasUtils.setTouchAction(this.canvas);
// Consume default actions on the canvas
this.canvas.style.msTouchAction = 'none';
this.canvas.style['ms-touch-action'] = 'none';
this.canvas.style['touch-action'] = 'none';
this.canvas.style.backgroundColor = 'rgb(0,0,0)';
this.canvas.oncontextmenu = function (event) {
event.preventDefault();
};
this.context = this.canvas.getContext('2d');
this.css3 = new Phaser.Display.CSS3Filters(this.canvas);
this.scaleMode = Phaser.StageScaleMode.NO_SCALE;
@@ -125,7 +115,7 @@ var Phaser;
if (this.clear || (this.game.paused && this.disablePauseScreen == false)) {
if (this.game.device.patchAndroidClearRectBug) {
this.context.fillStyle = 'rgb(0,0,0)';
this.context.fillStyle = this._backgroundColor;
this.context.fillRect(0, 0, this.width, this.height);
} else {
this.context.clearRect(0, 0, this.width, this.height);
@@ -185,13 +175,6 @@ var Phaser;
}
};
Stage.prototype.setImageRenderingCrisp = function () {
this.canvas.style['image-rendering'] = 'crisp-edges';
this.canvas.style['image-rendering'] = '-moz-crisp-edges';
this.canvas.style['image-rendering'] = '-webkit-optimize-contrast';
this.canvas.style['-ms-interpolation-mode'] = 'nearest-neighbor';
};
Stage.prototype.pauseGame = function () {
this.game.paused = true;
@@ -250,7 +233,7 @@ var Phaser;
this.context.fillStyle = this.fillStyle;
if (this.game.device.patchAndroidClearRectBug) {
this.context.fillStyle = 'rgb(0,0,0)';
this.context.fillStyle = this._backgroundColor;
this.context.fillRect(0, 0, this.width, this.height);
} else {
this.context.clearRect(0, 0, this.width, this.height);
+2 -2
View File
@@ -188,7 +188,7 @@ module Phaser {
{
if (this.game.device.patchAndroidClearRectBug)
{
this.context.fillStyle = 'rgb(0,0,0)';
this.context.fillStyle = this._backgroundColor;
this.context.fillRect(0, 0, this.width, this.height);
}
else
@@ -357,7 +357,7 @@ module Phaser {
if (this.game.device.patchAndroidClearRectBug)
{
this.context.fillStyle = 'rgb(0,0,0)';
this.context.fillStyle = this._backgroundColor;
this.context.fillRect(0, 0, this.width, this.height);
}
else
+24 -3
View File
@@ -65,10 +65,13 @@ var Phaser;
this.texture = new Phaser.Display.Texture(this);
// We create a hidden canvas for our camera the size of the game (we use the screenView to clip the render to the camera size)
this.texture.canvas = document.createElement('canvas');
this.texture.canvas.width = width;
this.texture.canvas.height = height;
this._canvas = document.createElement('canvas');
this._canvas.width = width;
this._canvas.height = height;
this._renderLocal = true;
this.texture.canvas = this._canvas;
this.texture.context = this.texture.canvas.getContext('2d');
this.texture.backgroundColor = this.game.stage.backgroundColor;
// Handy proxies
this.scale = this.transform.scale;
@@ -94,6 +97,24 @@ var Phaser;
configurable: true
});
Object.defineProperty(Camera.prototype, "directToStage", {
set: function (value) {
if (value) {
this._renderLocal = false;
this.texture.canvas = this.game.stage.canvas;
Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.game.stage.backgroundColor);
} else {
this._renderLocal = true;
this.texture.canvas = this._canvas;
Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.texture.backgroundColor);
}
this.texture.context = this.texture.canvas.getContext('2d');
},
enumerable: true,
configurable: true
});
/**
* Hides an object from this Camera. Hidden objects are not rendered.
* The object must implement a public cameraBlacklist property.
+27 -3
View File
@@ -45,10 +45,13 @@ module Phaser {
this.texture = new Phaser.Display.Texture(this);
// We create a hidden canvas for our camera the size of the game (we use the screenView to clip the render to the camera size)
this.texture.canvas = <HTMLCanvasElement> document.createElement('canvas');
this.texture.canvas.width = width;
this.texture.canvas.height = height;
this._canvas = <HTMLCanvasElement> document.createElement('canvas');
this._canvas.width = width;
this._canvas.height = height;
this._renderLocal = true;
this.texture.canvas = this._canvas;
this.texture.context = this.texture.canvas.getContext('2d');
this.texture.backgroundColor = this.game.stage.backgroundColor;
// Handy proxies
this.scale = this.transform.scale;
@@ -58,6 +61,8 @@ module Phaser {
}
private _renderLocal: boolean;
private _canvas: HTMLCanvasElement;
private _target: Sprite = null;
/**
@@ -160,6 +165,25 @@ module Phaser {
*/
public z: number = -1;
public set directToStage(value: boolean) {
if (value)
{
this._renderLocal = false;
this.texture.canvas = this.game.stage.canvas;
Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.game.stage.backgroundColor);
}
else
{
this._renderLocal = true;
this.texture.canvas = this._canvas;
Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.texture.backgroundColor);
}
this.texture.context = this.texture.canvas.getContext('2d');
}
/**
* Hides an object from this Camera. Hidden objects are not rendered.
* The object must implement a public cameraBlacklist property.
+2
View File
@@ -29,6 +29,8 @@ var Phaser;
this.defaultCamera = this.addCamera(x, y, width, height);
this.defaultCamera.directToStage = true;
this.current = this.defaultCamera;
}
/**
+2
View File
@@ -29,6 +29,8 @@ module Phaser {
this.defaultCamera = this.addCamera(x, y, width, height);
this.defaultCamera.directToStage = true;
this.current = this.defaultCamera;
}
+1 -1
View File
@@ -114,7 +114,7 @@ var Phaser;
*/
Sprite.prototype.bringToTop = function () {
if (this.group) {
//this.group.bringToTop(this);
this.group.bringToTop(this);
}
};
+10 -6
View File
@@ -19,6 +19,10 @@ var Phaser;
* @type {string}
*/
this.crossOrigin = '';
// If you want to append a URL before the path of any asset you can set this here.
// Useful if you need to allow an asset url to be configured outside of the game code.
// MUST have / on the end of it!
this.baseURL = '';
this.game = game;
this._keys = [];
@@ -225,7 +229,7 @@ var Phaser;
return _this.fileError(file.key);
};
file.data.crossOrigin = this.crossOrigin;
file.data.src = file.url;
file.data.src = this.baseURL + file.url;
break;
case 'audio':
@@ -233,7 +237,7 @@ var Phaser;
if (file.url !== null) {
if (this.game.sound.usingWebAudio) {
this._xhr.open("GET", file.url, true);
this._xhr.open("GET", this.baseURL + file.url, true);
this._xhr.responseType = "arraybuffer";
this._xhr.onload = function () {
return _this.fileComplete(file.key);
@@ -248,7 +252,7 @@ var Phaser;
file.data = new Audio();
file.data.name = file.key;
file.data.preload = 'auto';
file.data.src = file.url;
file.data.src = this.baseURL + file.url;
this.fileComplete(file.key);
} else {
file.data = new Audio();
@@ -257,7 +261,7 @@ var Phaser;
return _this.fileError(file.key);
};
file.data.preload = 'auto';
file.data.src = file.url;
file.data.src = this.baseURL + file.url;
file.data.addEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete(file.key), false);
file.data.load();
}
@@ -267,7 +271,7 @@ var Phaser;
break;
case 'text':
this._xhr.open("GET", file.url, true);
this._xhr.open("GET", this.baseURL + file.url, true);
this._xhr.responseType = "text";
this._xhr.onload = function () {
return _this.fileComplete(file.key);
@@ -341,7 +345,7 @@ var Phaser;
} else {
// Load the JSON or XML before carrying on with the next file
loadNext = false;
this._xhr.open("GET", file.atlasURL, true);
this._xhr.open("GET", this.baseURL + file.atlasURL, true);
this._xhr.responseType = "text";
if (file.format == Loader.TEXTURE_ATLAS_JSON_ARRAY) {
-65
View File
@@ -186,71 +186,6 @@ var Phaser;
enumerable: true,
configurable: true
});
// MOVE THESE TO A UTIL
Body.prototype.render = function (context) {
context.beginPath();
context.strokeStyle = 'rgb(0,255,0)';
context.strokeRect(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight, this.bounds.width, this.bounds.height);
context.stroke();
context.closePath();
// center point
context.fillStyle = 'rgb(0,255,0)';
context.fillRect(this.position.x, this.position.y, 2, 2);
if (this.touching & Phaser.Types.LEFT) {
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.lineTo(this.position.x - this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.stroke();
context.closePath();
}
if (this.touching & Phaser.Types.RIGHT) {
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x + this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.stroke();
context.closePath();
}
if (this.touching & Phaser.Types.UP) {
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.stroke();
context.closePath();
}
if (this.touching & Phaser.Types.DOWN) {
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.stroke();
context.closePath();
}
};
/**
* Render debug infos. (including name, bounds info, position and some other properties)
* @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)
*/
Body.prototype.renderDebugInfo = function (x, y, color) {
if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
this.sprite.texture.context.fillStyle = color;
this.sprite.texture.context.fillText('Sprite: (' + this.sprite.width + ' x ' + this.sprite.height + ')', x, y);
//this.sprite.texture.context.fillText('x: ' + this._sprite.frameBounds.x.toFixed(1) + ' y: ' + this._sprite.frameBounds.y.toFixed(1) + ' rotation: ' + this._sprite.rotation.toFixed(1), x, y + 14);
this.sprite.texture.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' rotation: ' + this.sprite.transform.rotation.toFixed(0), x, y + 14);
this.sprite.texture.context.fillText('vx: ' + this.velocity.x.toFixed(1) + ' vy: ' + this.velocity.y.toFixed(1), x, y + 28);
this.sprite.texture.context.fillText('acx: ' + this.acceleration.x.toFixed(1) + ' acy: ' + this.acceleration.y.toFixed(1), x, y + 42);
this.sprite.texture.context.fillText('angVx: ' + this.angularVelocity.toFixed(1) + ' angAc: ' + this.angularAcceleration.toFixed(1), x, y + 56);
};
return Body;
})();
Physics.Body = Body;
+75 -16
View File
@@ -1,19 +1,78 @@
var Shapes;
(function (Shapes) {
var Point = Shapes.Point = (function () {
function Point(x, y) {
this.x = x;
this.y = y;
/// <reference path="../_definitions.ts" />
/**
* Phaser - CanvasUtils
*
* A collection of methods useful for manipulating canvas objects.
*/
var Phaser;
(function (Phaser) {
var CanvasUtils = (function () {
function CanvasUtils() {
}
Point.prototype.getDist = function () {
return Math.sqrt((this.x * this.x) + (this.y * this.y));
CanvasUtils.getAspectRatio = function (canvas) {
return canvas.width / canvas.height;
};
Point.origin = new Point(0, 0);
return Point;
CanvasUtils.setBackgroundColor = function (canvas, color) {
if (typeof color === "undefined") { color = 'rgb(0,0,0)'; }
canvas.style.backgroundColor = color;
return canvas;
};
CanvasUtils.setTouchAction = function (canvas, value) {
if (typeof value === "undefined") { value = 'none'; }
canvas.style.msTouchAction = value;
canvas.style['ms-touch-action'] = value;
canvas.style['touch-action'] = value;
return canvas;
};
CanvasUtils.addToDOM = function (canvas, parent, overflowHidden) {
if (typeof parent === "undefined") { parent = ''; }
if (typeof overflowHidden === "undefined") { overflowHidden = true; }
if ((parent !== '' || parent !== null) && document.getElementById(parent)) {
document.getElementById(parent).appendChild(canvas);
if (overflowHidden) {
document.getElementById(parent).style.overflow = 'hidden';
}
} else {
document.body.appendChild(canvas);
}
return canvas;
};
CanvasUtils.setTransform = function (context, translateX, translateY, scaleX, scaleY, skewX, skewY) {
context.setTransform(scaleX, skewX, skewY, scaleY, translateX, translateY);
return context;
};
CanvasUtils.setSmoothingEnabled = function (context, value) {
context['imageSmoothingEnabled'] = value;
context['mozImageSmoothingEnabled'] = value;
context['oImageSmoothingEnabled'] = value;
context['webkitImageSmoothingEnabled'] = value;
context['msImageSmoothingEnabled'] = value;
return context;
};
CanvasUtils.setImageRenderingCrisp = function (canvas) {
canvas.style['image-rendering'] = 'crisp-edges';
canvas.style['image-rendering'] = '-moz-crisp-edges';
canvas.style['image-rendering'] = '-webkit-optimize-contrast';
canvas.style.msInterpolationMode = 'nearest-neighbor';
return canvas;
};
CanvasUtils.setImageRenderingBicubic = function (canvas) {
canvas.style['image-rendering'] = 'auto';
canvas.style.msInterpolationMode = 'bicubic';
return canvas;
};
return CanvasUtils;
})();
})(Shapes || (Shapes = {}));
var p = new Shapes.Point(3, 4);
var dist = p.getDist();
Phaser.CanvasUtils = CanvasUtils;
})(Phaser || (Phaser = {}));
+1 -2
View File
@@ -33,8 +33,6 @@ Future Plans
* Joypad support.
* Gestures input class.
* Integrate the Advanced Physics system that is 90% ready but needs updating for TypeScript 0.9.1.
* We can streamline the code for a lot of the CanvasRenderer calls re: global ops, alpha, etc.
* Move getOffset inside Phaser.Display.Canvas
ToDo before release
@@ -169,6 +167,7 @@ V1.0.0
* Added Input.pollRate - this lets you limit how often Pointer events are handled (0 = every frame, 1 = every other frame, etc)
* Renamed the 'init' function to 'preload'. It now calls load.start automatically.
* Entire framework updated for TypeScript 0.9.1 - what a mammoth amount of work that was! Sorry but not backward compatible.
* Added CanvasUtils class, including ability to set image rendering, add a canvas to the dom and other handy things.
V0.9.6
+4
View File
@@ -126,6 +126,10 @@
<DependentUpon>world sprite.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="groups\bring to top 1.ts" />
<TypeScriptCompile Include="display\render crisp.ts" />
<Content Include="display\render crisp.js">
<DependentUpon>render crisp.ts</DependentUpon>
</Content>
<Content Include="groups\add to group 1.ts" />
<Content Include="groups\add to group 2.ts" />
<Content Include="groups\bring to top 1.js">
+2
View File
@@ -31,8 +31,10 @@
function clickedIt() {
if (this.image.visible == true) {
game.stage.backgroundColor = '';
this.image.visible = false;
} else {
game.stage.backgroundColor = 'rgb(0,0,0)';
this.image.visible = true;
}
}
+28
View File
@@ -0,0 +1,28 @@
/// <reference path="../../Phaser/_definitions.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
function preload() {
game.load.image('boss', 'assets/misc/boss1.png');
game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71);
}
var boss;
var button;
function create() {
// For browsers that support it, this keeps our pixel art looking crisp
Phaser.CanvasUtils.setSmoothingEnabled(game.stage.context, false);
boss = game.add.sprite(game.stage.centerX, game.stage.centerY, 'boss');
boss.origin.setTo(0.5, 0.5);
// Zoom in each time we press it
button = game.add.button(32, 32, 'button', clickedIt, this, 2, 1, 0);
}
function clickedIt() {
boss.scale.x += 0.5;
boss.scale.y += 0.5;
}
})();
+37
View File
@@ -0,0 +1,37 @@
/// <reference path="../../Phaser/_definitions.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
function preload() {
game.load.image('boss', 'assets/misc/boss1.png');
game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71);
}
var boss: Phaser.Sprite;
var button: Phaser.UI.Button;
function create() {
// For browsers that support it, this keeps our pixel art looking crisp
Phaser.CanvasUtils.setSmoothingEnabled(game.stage.context, false);
boss = game.add.sprite(game.stage.centerX, game.stage.centerY, 'boss');
boss.origin.setTo(0.5, 0.5);
// Zoom in each time we press it
button = game.add.button(32, 32, 'button', clickedIt, this, 2, 1, 0);
}
function clickedIt() {
boss.scale.x += 0.5;
boss.scale.y += 0.5;
}
})();
+126 -42
View File
@@ -1,5 +1,29 @@
/// <reference path="_definitions.ts" />
/**
* Phaser - http://www.phaser.io
*
* v1.0.0 - August 12th 2013
*
* A feature-packed 2D canvas game framework born from the firey pits of Flixel and
* constructed via plenty of blood, sweat, tears and coffee by Richard Davey (@photonstorm).
*
* Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from both which Phaser
* and my love of game development originate.
*
* Follow Phaser progress at http://www.photonstorm.com
*
* "If you want your children to be intelligent, read them fairy tales."
* "If you want them to be more intelligent, read them more fairy tales."
* -- Albert Einstein
*/
var Phaser;
(function (Phaser) {
Phaser.VERSION = 'Phaser version 1.0.0';
Phaser.GAMES = [];
})(Phaser || (Phaser = {}));
/// <reference path="_definitions.ts" />
/**
* Types
*
* This file contains all constants used through-out Phaser.
@@ -5320,10 +5344,13 @@ var Phaser;
this.texture = new Phaser.Display.Texture(this);
// We create a hidden canvas for our camera the size of the game (we use the screenView to clip the render to the camera size)
this.texture.canvas = document.createElement('canvas');
this.texture.canvas.width = width;
this.texture.canvas.height = height;
this._canvas = document.createElement('canvas');
this._canvas.width = width;
this._canvas.height = height;
this._renderLocal = true;
this.texture.canvas = this._canvas;
this.texture.context = this.texture.canvas.getContext('2d');
this.texture.backgroundColor = this.game.stage.backgroundColor;
// Handy proxies
this.scale = this.transform.scale;
@@ -5349,6 +5376,24 @@ var Phaser;
configurable: true
});
Object.defineProperty(Camera.prototype, "directToStage", {
set: function (value) {
if (value) {
this._renderLocal = false;
this.texture.canvas = this.game.stage.canvas;
Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.game.stage.backgroundColor);
} else {
this._renderLocal = true;
this.texture.canvas = this._canvas;
Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.texture.backgroundColor);
}
this.texture.context = this.texture.canvas.getContext('2d');
},
enumerable: true,
configurable: true
});
/**
* Hides an object from this Camera. Hidden objects are not rendered.
* The object must implement a public cameraBlacklist property.
@@ -5697,6 +5742,8 @@ var Phaser;
this.defaultCamera = this.addCamera(x, y, width, height);
this.defaultCamera.directToStage = true;
this.current = this.defaultCamera;
}
/**
@@ -19162,25 +19209,15 @@ var Phaser;
this.canvas = document.createElement('canvas');
this.canvas.width = width;
this.canvas.height = height;
this.context = this.canvas.getContext('2d');
if ((parent !== '' || parent !== null) && document.getElementById(parent)) {
document.getElementById(parent).appendChild(this.canvas);
document.getElementById(parent).style.overflow = 'hidden';
} else {
document.body.appendChild(this.canvas);
}
Phaser.CanvasUtils.addToDOM(this.canvas, parent, true);
Phaser.CanvasUtils.setTouchAction(this.canvas);
// Consume default actions on the canvas
this.canvas.style.msTouchAction = 'none';
this.canvas.style['ms-touch-action'] = 'none';
this.canvas.style['touch-action'] = 'none';
this.canvas.style.backgroundColor = 'rgb(0,0,0)';
this.canvas.oncontextmenu = function (event) {
event.preventDefault();
};
this.context = this.canvas.getContext('2d');
this.css3 = new Phaser.Display.CSS3Filters(this.canvas);
this.scaleMode = Phaser.StageScaleMode.NO_SCALE;
@@ -19231,7 +19268,7 @@ var Phaser;
if (this.clear || (this.game.paused && this.disablePauseScreen == false)) {
if (this.game.device.patchAndroidClearRectBug) {
this.context.fillStyle = 'rgb(0,0,0)';
this.context.fillStyle = this._backgroundColor;
this.context.fillRect(0, 0, this.width, this.height);
} else {
this.context.clearRect(0, 0, this.width, this.height);
@@ -19291,13 +19328,6 @@ var Phaser;
}
};
Stage.prototype.setImageRenderingCrisp = function () {
this.canvas.style['image-rendering'] = 'crisp-edges';
this.canvas.style['image-rendering'] = '-moz-crisp-edges';
this.canvas.style['image-rendering'] = '-webkit-optimize-contrast';
this.canvas.style['-ms-interpolation-mode'] = 'nearest-neighbor';
};
Stage.prototype.pauseGame = function () {
this.game.paused = true;
@@ -19356,7 +19386,7 @@ var Phaser;
this.context.fillStyle = this.fillStyle;
if (this.game.device.patchAndroidClearRectBug) {
this.context.fillStyle = 'rgb(0,0,0)';
this.context.fillStyle = this._backgroundColor;
this.context.fillRect(0, 0, this.width, this.height);
} else {
this.context.clearRect(0, 0, this.width, this.height);
@@ -20019,27 +20049,81 @@ var Phaser;
})();
Phaser.Game = Game;
})(Phaser || (Phaser = {}));
/// <reference path="_definitions.ts" />
/// <reference path="../_definitions.ts" />
/**
* Phaser - http://www.phaser.io
* Phaser - CanvasUtils
*
* v1.0.0 - August 12th 2013
*
* A feature-packed 2D canvas game framework born from the firey pits of Flixel and
* constructed via plenty of blood, sweat, tears and coffee by Richard Davey (@photonstorm).
*
* Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from both which Phaser
* and my love of game development originate.
*
* Follow Phaser progress at http://www.photonstorm.com
*
* "If you want your children to be intelligent, read them fairy tales."
* "If you want them to be more intelligent, read them more fairy tales."
* -- Albert Einstein
* A collection of methods useful for manipulating canvas objects.
*/
var Phaser;
(function (Phaser) {
Phaser.VERSION = 'Phaser version 1.0.0';
var CanvasUtils = (function () {
function CanvasUtils() {
}
CanvasUtils.getAspectRatio = function (canvas) {
return canvas.width / canvas.height;
};
Phaser.GAMES = [];
CanvasUtils.setBackgroundColor = function (canvas, color) {
if (typeof color === "undefined") { color = 'rgb(0,0,0)'; }
canvas.style.backgroundColor = color;
return canvas;
};
CanvasUtils.setTouchAction = function (canvas, value) {
if (typeof value === "undefined") { value = 'none'; }
canvas.style.msTouchAction = value;
canvas.style['ms-touch-action'] = value;
canvas.style['touch-action'] = value;
return canvas;
};
CanvasUtils.addToDOM = function (canvas, parent, overflowHidden) {
if (typeof parent === "undefined") { parent = ''; }
if (typeof overflowHidden === "undefined") { overflowHidden = true; }
if ((parent !== '' || parent !== null) && document.getElementById(parent)) {
document.getElementById(parent).appendChild(canvas);
if (overflowHidden) {
document.getElementById(parent).style.overflow = 'hidden';
}
} else {
document.body.appendChild(canvas);
}
return canvas;
};
CanvasUtils.setTransform = function (context, translateX, translateY, scaleX, scaleY, skewX, skewY) {
context.setTransform(scaleX, skewX, skewY, scaleY, translateX, translateY);
return context;
};
CanvasUtils.setSmoothingEnabled = function (context, value) {
context['imageSmoothingEnabled'] = value;
context['mozImageSmoothingEnabled'] = value;
context['oImageSmoothingEnabled'] = value;
context['webkitImageSmoothingEnabled'] = value;
context['msImageSmoothingEnabled'] = value;
return context;
};
CanvasUtils.setImageRenderingCrisp = function (canvas) {
canvas.style['image-rendering'] = 'crisp-edges';
canvas.style['image-rendering'] = '-moz-crisp-edges';
canvas.style['image-rendering'] = '-webkit-optimize-contrast';
canvas.style.msInterpolationMode = 'nearest-neighbor';
return canvas;
};
CanvasUtils.setImageRenderingBicubic = function (canvas) {
canvas.style['image-rendering'] = 'auto';
canvas.style.msInterpolationMode = 'bicubic';
return canvas;
};
return CanvasUtils;
})();
Phaser.CanvasUtils = CanvasUtils;
})(Phaser || (Phaser = {}));
+28 -5
View File
@@ -5344,10 +5344,13 @@ var Phaser;
this.texture = new Phaser.Display.Texture(this);
// We create a hidden canvas for our camera the size of the game (we use the screenView to clip the render to the camera size)
this.texture.canvas = document.createElement('canvas');
this.texture.canvas.width = width;
this.texture.canvas.height = height;
this._canvas = document.createElement('canvas');
this._canvas.width = width;
this._canvas.height = height;
this._renderLocal = true;
this.texture.canvas = this._canvas;
this.texture.context = this.texture.canvas.getContext('2d');
this.texture.backgroundColor = this.game.stage.backgroundColor;
// Handy proxies
this.scale = this.transform.scale;
@@ -5373,6 +5376,24 @@ var Phaser;
configurable: true
});
Object.defineProperty(Camera.prototype, "directToStage", {
set: function (value) {
if (value) {
this._renderLocal = false;
this.texture.canvas = this.game.stage.canvas;
Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.game.stage.backgroundColor);
} else {
this._renderLocal = true;
this.texture.canvas = this._canvas;
Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.texture.backgroundColor);
}
this.texture.context = this.texture.canvas.getContext('2d');
},
enumerable: true,
configurable: true
});
/**
* Hides an object from this Camera. Hidden objects are not rendered.
* The object must implement a public cameraBlacklist property.
@@ -5721,6 +5742,8 @@ var Phaser;
this.defaultCamera = this.addCamera(x, y, width, height);
this.defaultCamera.directToStage = true;
this.current = this.defaultCamera;
}
/**
@@ -19245,7 +19268,7 @@ var Phaser;
if (this.clear || (this.game.paused && this.disablePauseScreen == false)) {
if (this.game.device.patchAndroidClearRectBug) {
this.context.fillStyle = 'rgb(0,0,0)';
this.context.fillStyle = this._backgroundColor;
this.context.fillRect(0, 0, this.width, this.height);
} else {
this.context.clearRect(0, 0, this.width, this.height);
@@ -19363,7 +19386,7 @@ var Phaser;
this.context.fillStyle = this.fillStyle;
if (this.game.device.patchAndroidClearRectBug) {
this.context.fillStyle = 'rgb(0,0,0)';
this.context.fillStyle = this._backgroundColor;
this.context.fillRect(0, 0, this.width, this.height);
} else {
this.context.clearRect(0, 0, this.width, this.height);