mirror of
https://github.com/wassname/phaser.git
synced 2026-08-17 11:23:42 +08:00
Set the default camera to direct itself to the Stage.
This commit is contained in:
+75
-16
@@ -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 = {}));
|
||||
|
||||
Reference in New Issue
Block a user