DebugUtils converted, re-name spaced the Input classes and started on Camera culling.

This commit is contained in:
Richard Davey 2013-08-31 21:50:34 +01:00
parent 70ee753859
commit 22847f6ade
17 changed files with 1736 additions and 359 deletions

File diff suppressed because it is too large Load diff

View file

@ -20,13 +20,48 @@
function create() {
game.add.sprite(0, 0, 'mushroom');
game.add.sprite(400, 0, 'mushroom');
game.add.sprite(800, 0, 'mushroom');
// Make our game world 2000x2000 pixels in size (the default is to match the game size)
game.world.setSize(2000, 2000);
for (var i = 0; i < 50; i++)
{
var s = game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
s.scrollFactor.setTo(0.5, 0.5);
}
for (var i = 0; i < 50; i++)
{
game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
}
for (var i = 0; i < 50; i++)
{
var s = game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
s.scrollFactor.setTo(2, 2);
}
}
function update() {
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.x -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.x += 4;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.y += 4;
}
}
})();

167
examples/camera2.php Normal file
View file

@ -0,0 +1,167 @@
<!DOCTYPE HTML>
<html>
<head>
<title>phaser.js - a new beginning</title>
<?php
require('js.php');
?>
</head>
<body>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
}
var s;
var c;
var r;
var p;
function create() {
// Make our game world 2000x2000 pixels in size (the default is to match the game size)
game.world.setSize(2000, 2000);
s = game.add.sprite(400, 300, 'mushroom');
// do this on a texture basis!
// this._halfSize.x = this.parent.width / 2;
// this._halfSize.y = this.parent.height / 2;
// this._offset.x = this.origin.x * this.parent.width;
// this._offset.y = this.origin.y * this.parent.height;
// this._angle = Math.atan2(this.halfHeight - this._offset.x, this.halfWidth - this._offset.y);
// this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
// s.scale.setTo(2, 2);
s.anchor.setTo(0.5, 0.5);
s.angle = 45;
r = new Phaser.Rectangle(0, 0, s.width, s.height);
var newWidth = (s.width * Math.cos(s.rotation)) + (s.height * Math.sin(s.rotation));
var newHeight = (s.width * Math.sin(s.rotation)) + (s.height * Math.cos(s.rotation));
r.x = cx(s) - newWidth / 2;
r.y = cy(s);
r.width = newWidth;
r.height = newHeight;
// var max = Math.max(s.width, s.height);
// c = new Phaser.Circle(0,0,max);
// console.log(c);
// p = new Phaser.Point(s.x, s.y);
// s.angle = 90;
// PIXI worldTransform order:
// 0 = scaleX
// 1 = skewY
// 2 = translateX
// 3 = skewX
// 4 = scaleY
// 5 = translateY
console.log(s.worldTransform);
}
function cx(sprite) {
if (sprite.anchor.x == 0)
{
return sprite.x;
}
else
{
return sprite.x - (sprite.width * sprite.anchor.x);
}
}
function cy(sprite) {
if (sprite.anchor.y == 0)
{
return sprite.y;
}
else
{
return sprite.y - (sprite.height * sprite.anchor.y);
}
}
function update() {
s.rotation += 0.01;
var newWidth = (s.width * Math.cos(s.rotation)) + (s.height * Math.sin(s.rotation));
var newHeight = (s.width * Math.sin(s.rotation)) + (s.height * Math.cos(s.rotation));
r.x = cx(s) - newWidth / 2;
r.y = cy(s);
r.width = newWidth;
r.height = newHeight;
}
function render() {
// game.debug.renderCameraInfo(game.camera, 32, 32);
game.debug.renderInputInfo(32, 100);
// game.debug.renderSpriteInfo(s, 32, 32);
// game.debug.renderSpriteBounds(s);
//p.rotate(s.x, s.y, s.angle, asDegrees, distance) {
// game.debug.renderPoint(p);
game.debug.renderRectangle(r);
// var p = getLocalPosition(game.input.x, game.input.y, s);
// game.debug.renderPoint(p, 'rgb(255,0,255)');
// game.debug.renderPixel(game.input.x, game.input.y);
}
function transformBox ( m, t, a ) {
// m = 3x3 matrix (may need to check entries)
// t = translation matrix
// a = rect
}
function getLocalPosition (x, y, displayObject)
{
// Maps the point over the DO to local un-rotated, un-scaled space
// So you can then compare this point against a hitArea that was defined for the sprite to get detection
var worldTransform = displayObject.worldTransform;
var global = { x: x, y: y };
// do a cheeky transform to get the mouse coords;
var a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2],
a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5],
id = 1 / (a00 * a11 + a01 * -a10);
// set the mouse coords...
return new PIXI.Point(a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id,
a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id)
}
})();
</script>
</body>
</html>

View file

@ -91,3 +91,7 @@
<script src="../src/loader/Cache.js"></script>
<script src="../src/loader/Loader.js"></script>
<script src="../src/utils/Debug.js"></script>

View file

@ -231,6 +231,30 @@ Phaser.Game.prototype = {
*/
device: null,
/**
* A handy reference to world.camera
* @type {Phaser.Camera}
*/
camera: null,
/**
* A handy reference to renderer.view
* @type {HTMLCanvasElement}
*/
canvas: null,
/**
* A handy reference to renderer.context (only set for CANVAS games)
* @type {Context}
*/
context: null,
/**
* A set of useful debug utilities
* @type {Phaser.Utils.Debug}
*/
debug: null,
/**
* Initialize engine sub modules and start the game.
* @param parent {string} ID of parent Dom element.
@ -275,12 +299,12 @@ Phaser.Game.prototype = {
// this.physics = new Phaser.Physics.PhysicsManager(this);
this.plugins = new Phaser.PluginManager(this, this);
this.net = new Phaser.Net(this);
this.debug = new Phaser.Utils.Debug(this);
this.load.onLoadComplete.add(this.loadComplete, this);
this.world.boot();
this.state.boot();
// this.stage.boot();
this.input.boot();
if (this.renderType == Phaser.CANVAS)
@ -311,6 +335,8 @@ Phaser.Game.prototype = {
this.renderType = Phaser.CANVAS;
this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, this.transparent);
Phaser.Canvas.setSmoothingEnabled(this.renderer.context, this.antialias);
this.canvas = this.renderer.view;
this.context = this.renderer.context;
}
else
{
@ -321,6 +347,8 @@ Phaser.Game.prototype = {
{
// They must have requested WebGL and their browser supports it
this.renderer = new PIXI.WebGLRenderer(this.width, this.height, null, this.transparent, this.antialias);
this.canvas = this.renderer.view;
this.context = null;
}
Phaser.Canvas.addToDOM(this.renderer.view, this.parent, true);
@ -358,6 +386,7 @@ Phaser.Game.prototype = {
this.plugins.update();
this.renderer.render(this.world._stage);
this.state.render();
this.plugins.postRender();

View file

@ -365,15 +365,6 @@ Phaser.StateManager.prototype = {
},
loadRender: function () {
if (this.onLoadRenderCallback)
{
this.onLoadRenderCallback.call(this.callbackContext);
}
},
update: function () {
if (this._created && this.onUpdateCallback)
@ -401,9 +392,16 @@ Phaser.StateManager.prototype = {
render: function () {
if (this.onRenderCallback)
{
this.onRenderCallback.call(this.callbackContext);
if (this._created && this.onRenderCallback)
{
this.onRenderCallback.call(this.callbackContext);
}
else
{
if (this.onLoadRenderCallback)
{
this.onLoadRenderCallback.call(this.callbackContext);
}
}
},

View file

@ -24,6 +24,7 @@ Phaser.World.prototype = {
boot: function () {
this.camera = new Phaser.Camera(this.game, 0, 0, 0, this.game.width, this.game.height);
this.game.camera = this.camera;
},

View file

@ -1,11 +1,10 @@
Phaser.Sprite = function (game, x, y, key, frame) {
if (typeof x === "undefined") { x = 0; }
if (typeof y === "undefined") { y = 0; }
// if null we ought to set to the phaser logo or something :)
if (typeof key === "undefined") { key = null; }
if (typeof frame === "undefined") { frame = null; }
x = x || 0;
y = y || 0;
// if null we ought to set to the phaser logo or something :)
key = key || null;
frame = frame || null;
this.game = game;
@ -37,7 +36,25 @@ Phaser.Sprite = function (game, x, y, key, frame) {
* @property anchor
* @type Point
*/
this.anchor = new PIXI.Point();
this.anchor = new Phaser.Point();
/**
* The width of the sprite (this is initially set by the texture)
*
* @property _width
* @type Number
* @private
*/
// this._width = 0;
/**
* The height of the sprite (this is initially set by the texture)
*
* @property _height
* @type Number
* @private
*/
// this._height = 0;
/**
* The texture that the sprite is using
@ -73,23 +90,8 @@ Phaser.Sprite = function (game, x, y, key, frame) {
*/
this.blendMode = PIXI.blendModes.NORMAL;
/**
* The width of the sprite (this is initially set by the texture)
*
* @property _width
* @type Number
* @private
*/
this._width = 0;
/**
* The height of the sprite (this is initially set by the texture)
*
* @property _height
* @type Number
* @private
*/
this._height = 0;
this._x = x;
this._y = y;
this.updateFrame = true;
this.renderable = true;
@ -100,6 +102,10 @@ Phaser.Sprite = function (game, x, y, key, frame) {
// Replaces the PIXI.Point with a slightly more flexible one
this.scale = new Phaser.Point(1, 1);
this.scrollFactor = new Phaser.Point(1, 1);
this.worldView = new Phaser.Rectangle(x, y, this.width, this.height);
};
Phaser.Sprite.prototype = Object.create(PIXI.Sprite.prototype);
@ -111,6 +117,12 @@ Phaser.Sprite.prototype.constructor = Phaser.Sprite;
Phaser.Sprite.prototype.update = function() {
this.animations.update();
this.worldView.setTo(this._x, this._y, this.width, this.height);
this.position.x = this._x - (this.game.world.camera.x * this.scrollFactor.x);
this.position.y = this._y - (this.game.world.camera.y * this.scrollFactor.y);
// this.checkBounds();
}
@ -130,11 +142,12 @@ Object.defineProperty(Phaser.Sprite.prototype, 'angle', {
Object.defineProperty(Phaser.Sprite.prototype, 'x', {
get: function() {
return this.position.x;
return this._x;
},
set: function(value) {
this.position.x = value;
this.worldView.x = value;
this._x = value;
}
});
@ -142,11 +155,12 @@ Object.defineProperty(Phaser.Sprite.prototype, 'x', {
Object.defineProperty(Phaser.Sprite.prototype, 'y', {
get: function() {
return this.position.y;
return this._y;
},
set: function(value) {
this.position.y = value;
this.worldView.y = value;
this._y = value;
}
});

View file

@ -347,18 +347,22 @@ Phaser.Point.distance = function (a, b, round) {
*/
Phaser.Point.rotate = function (a, x, y, angle, asDegrees, distance) {
if (typeof asDegrees === "undefined") { asDegrees = false; }
if (typeof distance === "undefined") { distance = null; }
asDegrees = asDegrees || false;
distance = distance || null;
if (asDegrees) {
if (asDegrees)
{
angle = Phaser.Math.radToDeg(angle);
}
// Get distance from origin (cx/cy) to this point
if (distance === null) {
if (distance === null)
{
distance = Math.sqrt(((x - a.x) * (x - a.x)) + ((y - a.y) * (y - a.y)));
}
return a.setTo(x + distance * Math.cos(angle), y + distance * Math.sin(angle));
};

View file

@ -13,9 +13,9 @@ Phaser.Input = function (game) {
};
Phaser.Input.MOUSE_OVERRIDES_TOUCH = 0;
Phaser.Input.TOUCH_OVERRIDES_MOUSE = 1;
Phaser.Input.MOUSE_TOUCH_COMBINE = 2;
Phaser.Mouse_OVERRIDES_TOUCH = 0;
Phaser.Touch_OVERRIDES_MOUSE = 1;
Phaser.Mouse_TOUCH_COMBINE = 2;
Phaser.Input.prototype = {
@ -60,7 +60,7 @@ Phaser.Input.prototype = {
/**
* Controls the expected behaviour when using a mouse and touch together on a multi-input device
*/
multiInputOverride: Phaser.Input.MOUSE_TOUCH_COMBINE,
multiInputOverride: Phaser.Mouse_TOUCH_COMBINE,
/**
* A vector object representing the current position of the Pointer.
@ -259,14 +259,14 @@ Phaser.Input.prototype = {
**/
boot: function () {
this.mousePointer = new Phaser.Input.Pointer(this.game, 0);
this.pointer1 = new Phaser.Input.Pointer(this.game, 1);
this.pointer2 = new Phaser.Input.Pointer(this.game, 2);
this.mousePointer = new Phaser.Pointer(this.game, 0);
this.pointer1 = new Phaser.Pointer(this.game, 1);
this.pointer2 = new Phaser.Pointer(this.game, 2);
this.mouse = new Phaser.Input.Mouse(this.game);
this.keyboard = new Phaser.Input.Keyboard(this.game);
this.touch = new Phaser.Input.Touch(this.game);
this.mspointer = new Phaser.Input.MSPointer(this.game);
this.mouse = new Phaser.Mouse(this.game);
this.keyboard = new Phaser.Keyboard(this.game);
this.touch = new Phaser.Touch(this.game);
this.mspointer = new Phaser.MSPointer(this.game);
this.onDown = new Phaser.Signal();
this.onUp = new Phaser.Signal();
@ -321,7 +321,7 @@ Phaser.Input.prototype = {
}
else
{
this['pointer' + next] = new Phaser.Input.Pointer(this.game, next);
this['pointer' + next] = new Phaser.Pointer(this.game, next);
return this['pointer' + next];
}
@ -700,7 +700,7 @@ Object.defineProperty(Phaser.Input.prototype, "totalActivePointers", {
Object.defineProperty(Phaser.Input.prototype, "worldX", {
get: function () {
return this.camera.worldView.x + this.x;
return this.game.camera.view.x + this.x;
},
enumerable: true,
@ -710,7 +710,7 @@ Object.defineProperty(Phaser.Input.prototype, "worldX", {
Object.defineProperty(Phaser.Input.prototype, "worldY", {
get: function () {
return this.camera.worldView.x + this.x;
return this.game.camera.view.y + this.y;
},
enumerable: true,

View file

@ -1,4 +1,4 @@
Phaser.Input.Keyboard = function (game) {
Phaser.Keyboard = function (game) {
this.game = game;
this._keys = {};
@ -6,7 +6,7 @@ Phaser.Input.Keyboard = function (game) {
};
Phaser.Input.Keyboard.prototype = {
Phaser.Keyboard.prototype = {
game: null,
@ -206,101 +206,101 @@ Phaser.Input.Keyboard.prototype = {
// Statics
Phaser.Input.Keyboard.A = "A".charCodeAt(0);
Phaser.Input.Keyboard.B = "B".charCodeAt(0);
Phaser.Input.Keyboard.C = "C".charCodeAt(0);
Phaser.Input.Keyboard.D = "D".charCodeAt(0);
Phaser.Input.Keyboard.E = "E".charCodeAt(0);
Phaser.Input.Keyboard.F = "F".charCodeAt(0);
Phaser.Input.Keyboard.G = "G".charCodeAt(0);
Phaser.Input.Keyboard.H = "H".charCodeAt(0);
Phaser.Input.Keyboard.I = "I".charCodeAt(0);
Phaser.Input.Keyboard.J = "J".charCodeAt(0);
Phaser.Input.Keyboard.K = "K".charCodeAt(0);
Phaser.Input.Keyboard.L = "L".charCodeAt(0);
Phaser.Input.Keyboard.M = "M".charCodeAt(0);
Phaser.Input.Keyboard.N = "N".charCodeAt(0);
Phaser.Input.Keyboard.O = "O".charCodeAt(0);
Phaser.Input.Keyboard.P = "P".charCodeAt(0);
Phaser.Input.Keyboard.Q = "Q".charCodeAt(0);
Phaser.Input.Keyboard.R = "R".charCodeAt(0);
Phaser.Input.Keyboard.S = "S".charCodeAt(0);
Phaser.Input.Keyboard.T = "T".charCodeAt(0);
Phaser.Input.Keyboard.U = "U".charCodeAt(0);
Phaser.Input.Keyboard.V = "V".charCodeAt(0);
Phaser.Input.Keyboard.W = "W".charCodeAt(0);
Phaser.Input.Keyboard.X = "X".charCodeAt(0);
Phaser.Input.Keyboard.Y = "Y".charCodeAt(0);
Phaser.Input.Keyboard.Z = "Z".charCodeAt(0);
Phaser.Input.Keyboard.ZERO = "0".charCodeAt(0);
Phaser.Input.Keyboard.ONE = "1".charCodeAt(0);
Phaser.Input.Keyboard.TWO = "2".charCodeAt(0);
Phaser.Input.Keyboard.THREE = "3".charCodeAt(0);
Phaser.Input.Keyboard.FOUR = "4".charCodeAt(0);
Phaser.Input.Keyboard.FIVE = "5".charCodeAt(0);
Phaser.Input.Keyboard.SIX = "6".charCodeAt(0);
Phaser.Input.Keyboard.SEVEN = "7".charCodeAt(0);
Phaser.Input.Keyboard.EIGHT = "8".charCodeAt(0);
Phaser.Input.Keyboard.NINE = "9".charCodeAt(0);
Phaser.Input.Keyboard.NUMPAD_0 = 96;
Phaser.Input.Keyboard.NUMPAD_1 = 97;
Phaser.Input.Keyboard.NUMPAD_2 = 98;
Phaser.Input.Keyboard.NUMPAD_3 = 99;
Phaser.Input.Keyboard.NUMPAD_4 = 100;
Phaser.Input.Keyboard.NUMPAD_5 = 101;
Phaser.Input.Keyboard.NUMPAD_6 = 102;
Phaser.Input.Keyboard.NUMPAD_7 = 103;
Phaser.Input.Keyboard.NUMPAD_8 = 104;
Phaser.Input.Keyboard.NUMPAD_9 = 105;
Phaser.Input.Keyboard.NUMPAD_MULTIPLY = 106;
Phaser.Input.Keyboard.NUMPAD_ADD = 107;
Phaser.Input.Keyboard.NUMPAD_ENTER = 108;
Phaser.Input.Keyboard.NUMPAD_SUBTRACT = 109;
Phaser.Input.Keyboard.NUMPAD_DECIMAL = 110;
Phaser.Input.Keyboard.NUMPAD_DIVIDE = 111;
Phaser.Input.Keyboard.F1 = 112;
Phaser.Input.Keyboard.F2 = 113;
Phaser.Input.Keyboard.F3 = 114;
Phaser.Input.Keyboard.F4 = 115;
Phaser.Input.Keyboard.F5 = 116;
Phaser.Input.Keyboard.F6 = 117;
Phaser.Input.Keyboard.F7 = 118;
Phaser.Input.Keyboard.F8 = 119;
Phaser.Input.Keyboard.F9 = 120;
Phaser.Input.Keyboard.F10 = 121;
Phaser.Input.Keyboard.F11 = 122;
Phaser.Input.Keyboard.F12 = 123;
Phaser.Input.Keyboard.F13 = 124;
Phaser.Input.Keyboard.F14 = 125;
Phaser.Input.Keyboard.F15 = 126;
Phaser.Input.Keyboard.COLON = 186;
Phaser.Input.Keyboard.EQUALS = 187;
Phaser.Input.Keyboard.UNDERSCORE = 189;
Phaser.Input.Keyboard.QUESTION_MARK = 191;
Phaser.Input.Keyboard.TILDE = 192;
Phaser.Input.Keyboard.OPEN_BRACKET = 219;
Phaser.Input.Keyboard.BACKWARD_SLASH = 220;
Phaser.Input.Keyboard.CLOSED_BRACKET = 221;
Phaser.Input.Keyboard.QUOTES = 222;
Phaser.Input.Keyboard.BACKSPACE = 8;
Phaser.Input.Keyboard.TAB = 9;
Phaser.Input.Keyboard.CLEAR = 12;
Phaser.Input.Keyboard.ENTER = 13;
Phaser.Input.Keyboard.SHIFT = 16;
Phaser.Input.Keyboard.CONTROL = 17;
Phaser.Input.Keyboard.ALT = 18;
Phaser.Input.Keyboard.CAPS_LOCK = 20;
Phaser.Input.Keyboard.ESC = 27;
Phaser.Input.Keyboard.SPACEBAR = 32;
Phaser.Input.Keyboard.PAGE_UP = 33;
Phaser.Input.Keyboard.PAGE_DOWN = 34;
Phaser.Input.Keyboard.END = 35;
Phaser.Input.Keyboard.HOME = 36;
Phaser.Input.Keyboard.LEFT = 37;
Phaser.Input.Keyboard.UP = 38;
Phaser.Input.Keyboard.RIGHT = 39;
Phaser.Input.Keyboard.DOWN = 40;
Phaser.Input.Keyboard.INSERT = 45;
Phaser.Input.Keyboard.DELETE = 46;
Phaser.Input.Keyboard.HELP = 47;
Phaser.Input.Keyboard.NUM_LOCK = 144;
Phaser.Keyboard.A = "A".charCodeAt(0);
Phaser.Keyboard.B = "B".charCodeAt(0);
Phaser.Keyboard.C = "C".charCodeAt(0);
Phaser.Keyboard.D = "D".charCodeAt(0);
Phaser.Keyboard.E = "E".charCodeAt(0);
Phaser.Keyboard.F = "F".charCodeAt(0);
Phaser.Keyboard.G = "G".charCodeAt(0);
Phaser.Keyboard.H = "H".charCodeAt(0);
Phaser.Keyboard.I = "I".charCodeAt(0);
Phaser.Keyboard.J = "J".charCodeAt(0);
Phaser.Keyboard.K = "K".charCodeAt(0);
Phaser.Keyboard.L = "L".charCodeAt(0);
Phaser.Keyboard.M = "M".charCodeAt(0);
Phaser.Keyboard.N = "N".charCodeAt(0);
Phaser.Keyboard.O = "O".charCodeAt(0);
Phaser.Keyboard.P = "P".charCodeAt(0);
Phaser.Keyboard.Q = "Q".charCodeAt(0);
Phaser.Keyboard.R = "R".charCodeAt(0);
Phaser.Keyboard.S = "S".charCodeAt(0);
Phaser.Keyboard.T = "T".charCodeAt(0);
Phaser.Keyboard.U = "U".charCodeAt(0);
Phaser.Keyboard.V = "V".charCodeAt(0);
Phaser.Keyboard.W = "W".charCodeAt(0);
Phaser.Keyboard.X = "X".charCodeAt(0);
Phaser.Keyboard.Y = "Y".charCodeAt(0);
Phaser.Keyboard.Z = "Z".charCodeAt(0);
Phaser.Keyboard.ZERO = "0".charCodeAt(0);
Phaser.Keyboard.ONE = "1".charCodeAt(0);
Phaser.Keyboard.TWO = "2".charCodeAt(0);
Phaser.Keyboard.THREE = "3".charCodeAt(0);
Phaser.Keyboard.FOUR = "4".charCodeAt(0);
Phaser.Keyboard.FIVE = "5".charCodeAt(0);
Phaser.Keyboard.SIX = "6".charCodeAt(0);
Phaser.Keyboard.SEVEN = "7".charCodeAt(0);
Phaser.Keyboard.EIGHT = "8".charCodeAt(0);
Phaser.Keyboard.NINE = "9".charCodeAt(0);
Phaser.Keyboard.NUMPAD_0 = 96;
Phaser.Keyboard.NUMPAD_1 = 97;
Phaser.Keyboard.NUMPAD_2 = 98;
Phaser.Keyboard.NUMPAD_3 = 99;
Phaser.Keyboard.NUMPAD_4 = 100;
Phaser.Keyboard.NUMPAD_5 = 101;
Phaser.Keyboard.NUMPAD_6 = 102;
Phaser.Keyboard.NUMPAD_7 = 103;
Phaser.Keyboard.NUMPAD_8 = 104;
Phaser.Keyboard.NUMPAD_9 = 105;
Phaser.Keyboard.NUMPAD_MULTIPLY = 106;
Phaser.Keyboard.NUMPAD_ADD = 107;
Phaser.Keyboard.NUMPAD_ENTER = 108;
Phaser.Keyboard.NUMPAD_SUBTRACT = 109;
Phaser.Keyboard.NUMPAD_DECIMAL = 110;
Phaser.Keyboard.NUMPAD_DIVIDE = 111;
Phaser.Keyboard.F1 = 112;
Phaser.Keyboard.F2 = 113;
Phaser.Keyboard.F3 = 114;
Phaser.Keyboard.F4 = 115;
Phaser.Keyboard.F5 = 116;
Phaser.Keyboard.F6 = 117;
Phaser.Keyboard.F7 = 118;
Phaser.Keyboard.F8 = 119;
Phaser.Keyboard.F9 = 120;
Phaser.Keyboard.F10 = 121;
Phaser.Keyboard.F11 = 122;
Phaser.Keyboard.F12 = 123;
Phaser.Keyboard.F13 = 124;
Phaser.Keyboard.F14 = 125;
Phaser.Keyboard.F15 = 126;
Phaser.Keyboard.COLON = 186;
Phaser.Keyboard.EQUALS = 187;
Phaser.Keyboard.UNDERSCORE = 189;
Phaser.Keyboard.QUESTION_MARK = 191;
Phaser.Keyboard.TILDE = 192;
Phaser.Keyboard.OPEN_BRACKET = 219;
Phaser.Keyboard.BACKWARD_SLASH = 220;
Phaser.Keyboard.CLOSED_BRACKET = 221;
Phaser.Keyboard.QUOTES = 222;
Phaser.Keyboard.BACKSPACE = 8;
Phaser.Keyboard.TAB = 9;
Phaser.Keyboard.CLEAR = 12;
Phaser.Keyboard.ENTER = 13;
Phaser.Keyboard.SHIFT = 16;
Phaser.Keyboard.CONTROL = 17;
Phaser.Keyboard.ALT = 18;
Phaser.Keyboard.CAPS_LOCK = 20;
Phaser.Keyboard.ESC = 27;
Phaser.Keyboard.SPACEBAR = 32;
Phaser.Keyboard.PAGE_UP = 33;
Phaser.Keyboard.PAGE_DOWN = 34;
Phaser.Keyboard.END = 35;
Phaser.Keyboard.HOME = 36;
Phaser.Keyboard.LEFT = 37;
Phaser.Keyboard.UP = 38;
Phaser.Keyboard.RIGHT = 39;
Phaser.Keyboard.DOWN = 40;
Phaser.Keyboard.INSERT = 45;
Phaser.Keyboard.DELETE = 46;
Phaser.Keyboard.HELP = 47;
Phaser.Keyboard.NUM_LOCK = 144;

View file

@ -1,11 +1,11 @@
/**
* Phaser.Input.MSPointer
* Phaser.MSPointer
*
* The MSPointer class handles touch interactions with the game and the resulting Pointer objects.
* It will work only in Internet Explorer 10 and Windows Store or Windows Phone 8 apps using JavaScript.
* http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx
*/
Phaser.Input.MSPointer = function (game) {
Phaser.MSPointer = function (game) {
this.game = game;
this.callbackContext = this.game;
@ -16,7 +16,7 @@ Phaser.Input.MSPointer = function (game) {
};
Phaser.Input.MSPointer.prototype = {
Phaser.MSPointer.prototype = {
game: null,
@ -55,6 +55,10 @@ Phaser.Input.MSPointer.prototype = {
this.game.stage.canvas.addEventListener('MSPointerDown', this._onMSPointerDown, false);
this.game.stage.canvas.addEventListener('MSPointerMove', this._onMSPointerMove, false);
this.game.stage.canvas.addEventListener('MSPointerUp', this._onMSPointerUp, false);
this.game.stage.canvas.style['-ms-content-zooming'] = 'none';
this.game.stage.canvas.style['-ms-touch-action'] = 'none';
}
},

View file

@ -1,4 +1,4 @@
Phaser.Input.Mouse = function (game) {
Phaser.Mouse = function (game) {
this.game = game;
this.callbackContext = this.game;
@ -9,11 +9,11 @@ Phaser.Input.Mouse = function (game) {
};
Phaser.Input.Mouse.LEFT_BUTTON = 0;
Phaser.Input.Mouse.MIDDLE_BUTTON = 1;
Phaser.Input.Mouse.RIGHT_BUTTON = 2;
Phaser.Mouse.LEFT_BUTTON = 0;
Phaser.Mouse.MIDDLE_BUTTON = 1;
Phaser.Mouse.RIGHT_BUTTON = 2;
Phaser.Input.Mouse.prototype = {
Phaser.Mouse.prototype = {
game: null,

View file

@ -3,7 +3,7 @@
*
* A Pointer object is used by the Mouse, Touch and MSPoint managers and represents a single finger on the touch screen.
*/
Phaser.Input.Pointer = function (game, id) {
Phaser.Pointer = function (game, id) {
this.game = game;
this.id = id;
@ -22,7 +22,7 @@ Phaser.Input.Pointer = function (game, id) {
};
Phaser.Input.Pointer.prototype = {
Phaser.Pointer.prototype = {
/**
* Local private variable to store the status of dispatching a hold event
@ -238,7 +238,7 @@ Phaser.Input.Pointer.prototype = {
// x and y are the old values here?
this.positionDown.setTo(this.x, this.y);
if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
if (this.game.input.multiInputOverride == Phaser.Mouse_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Mouse_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Touch_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
{
//this.game.input.x = this.x * this.game.input.scale.x;
//this.game.input.y = this.y * this.game.input.scale.y;
@ -272,7 +272,7 @@ Phaser.Input.Pointer.prototype = {
{
if (this._holdSent == false && this.duration >= this.game.input.holdRate)
{
if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
if (this.game.input.multiInputOverride == Phaser.Mouse_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Mouse_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Touch_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
{
this.game.input.onHold.dispatch(this);
}
@ -335,7 +335,7 @@ Phaser.Input.Pointer.prototype = {
this.circle.x = this.x;
this.circle.y = this.y;
if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
if (this.game.input.multiInputOverride == Phaser.Mouse_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Mouse_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Touch_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
{
this.game.input.activePointer = this;
this.game.input.x = this.x;
@ -453,7 +453,7 @@ Phaser.Input.Pointer.prototype = {
this.timeUp = this.game.time.now;
if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
if (this.game.input.multiInputOverride == Phaser.Mouse_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Mouse_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Touch_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
{
this.game.input.onUp.dispatch(this);
@ -576,7 +576,7 @@ Phaser.Input.Pointer.prototype = {
};
Object.defineProperty(Phaser.Input.Pointer.prototype, "duration", {
Object.defineProperty(Phaser.Pointer.prototype, "duration", {
/**
* How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1.
@ -598,7 +598,7 @@ Object.defineProperty(Phaser.Input.Pointer.prototype, "duration", {
configurable: true
});
Object.defineProperty(Phaser.Input.Pointer.prototype, "worldX", {
Object.defineProperty(Phaser.Pointer.prototype, "worldX", {
/**
* Gets the X value of this Pointer in world coordinates based on the given camera.
@ -614,7 +614,7 @@ Object.defineProperty(Phaser.Input.Pointer.prototype, "worldX", {
configurable: true
});
Object.defineProperty(Phaser.Input.Pointer.prototype, "worldY", {
Object.defineProperty(Phaser.Pointer.prototype, "worldY", {
/**
* Gets the Y value of this Pointer in world coordinates based on the given camera.

View file

@ -7,7 +7,7 @@
* http://www.html5rocks.com/en/mobile/touchandmouse/
* Note: Android 2.x only supports 1 touch event at once, no multi-touch
*/
Phaser.Input.Touch = function (game) {
Phaser.Touch = function (game) {
this.game = game;
this.callbackContext = this.game;
@ -21,7 +21,7 @@ Phaser.Input.Touch = function (game) {
};
Phaser.Input.Touch.prototype = {
Phaser.Touch.prototype = {
game: null,

View file

@ -152,7 +152,7 @@ PIXI.Sprite.prototype.setTexture = function(texture)
PIXI.Sprite.prototype.onTextureUpdate = function(event)
{
//this.texture.removeEventListener( 'update', this.onTextureUpdateBind );
console.log('pot');
// so if _width is 0 then width was not set..
if(this._width)this.scale.x = this._width / this.texture.frame.width;
if(this._height)this.scale.y = this._height / this.texture.frame.height;

404
src/utils/Debug.js Normal file
View file

@ -0,0 +1,404 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
* @module Phaser
*/
Phaser.Utils = {
// Until we have a proper entry-point
}
/**
* A collection of methods for displaying debug information about game objects.
*
* @class DebugUtils
*/
Phaser.Utils.Debug = function (game) {
this.game = game;
this.context = game.context;
};
Phaser.Utils.Debug.prototype = {
font: '14px Courier',
lineHeight: 16,
renderShadow: true,
currentX: 0,
currentY: 0,
context: null,
/**
* Internal method that resets the debug output values.
* @method start
* @param {Number} x The X value the debug info will start from.
* @param {Number} y The Y value the debug info will start from.
* @param {String} color The color the debug info will drawn in.
*/
start: function (x, y, color) {
if (this.context == null)
{
return;
}
x = x || null;
y = y || null;
color = color || 'rgb(255,255,255)';
if (x && y)
{
this.currentX = x;
this.currentY = y;
this.currentColor = color;
}
this.context.save();
this.context.setTransform(1, 0, 0, 1, 0, 0);
this.context.fillStyle = color;
this.context.font = this.font;
},
stop: function () {
this.context.restore();
},
/**
* Internal method that outputs a single line of text.
* @method line
* @param {String} text The line of text to draw.
* @param {Number} x The X value the debug info will start from.
* @param {Number} y The Y value the debug info will start from.
*/
line: function (text, x, y) {
if (this.context == null)
{
return;
}
x = x || null;
y = y || null;
if (x !== null) {
this.currentX = x;
}
if (y !== null) {
this.currentY = y;
}
if (this.renderShadow)
{
this.context.fillStyle = 'rgb(0,0,0)';
this.context.fillText(text, this.currentX + 1, this.currentY + 1);
this.context.fillStyle = this.currentColor;
}
this.context.fillText(text, this.currentX, this.currentY);
this.currentY += this.lineHeight;
},
renderSpriteCorners: function (sprite, color) {
if (this.context == null)
{
return;
}
if (typeof color === "undefined") { color = 'rgb(255,0,255)'; }
this.start(0, 0, color);
this.line('x: ' + Math.floor(sprite.transform.upperLeft.x) + ' y: ' + Math.floor(sprite.transform.upperLeft.y), sprite.transform.upperLeft.x, sprite.transform.upperLeft.y);
this.line('x: ' + Math.floor(sprite.transform.upperRight.x) + ' y: ' + Math.floor(sprite.transform.upperRight.y), sprite.transform.upperRight.x, sprite.transform.upperRight.y);
this.line('x: ' + Math.floor(sprite.transform.bottomLeft.x) + ' y: ' + Math.floor(sprite.transform.bottomLeft.y), sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y);
this.line('x: ' + Math.floor(sprite.transform.bottomRight.x) + ' y: ' + Math.floor(sprite.transform.bottomRight.y), sprite.transform.bottomRight.x, sprite.transform.bottomRight.y);
},
/**
* Render debug infos. (including id, position, rotation, scrolling factor, worldBounds 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)
*/
renderSoundInfo: function (sound, x, y, color) {
if (this.context == null)
{
return;
}
color = color || 'rgb(255,255,255)';
this.start(x, y, color);
this.line('Sound: ' + sound.key + ' Locked: ' + sound.game.sound.touchLocked + ' Pending Playback: ' + sound.pendingPlayback);
this.line('Decoded: ' + sound.isDecoded + ' Decoding: ' + sound.isDecoding);
this.line('Total Duration: ' + sound.totalDuration + ' Playing: ' + sound.isPlaying);
this.line('Time: ' + sound.currentTime);
this.line('Volume: ' + sound.volume + ' Muted: ' + sound.mute);
this.line('WebAudio: ' + sound.usingWebAudio + ' Audio: ' + sound.usingAudioTag);
if (sound.currentMarker !== '')
{
this.line('Marker: ' + sound.currentMarker + ' Duration: ' + sound.duration);
this.line('Start: ' + sound.markers[sound.currentMarker].start + ' Stop: ' + sound.markers[sound.currentMarker].stop);
this.line('Position: ' + sound.position);
}
},
/**
* Render debug infos. (including id, position, rotation, scrolling factor, worldBounds 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)
*/
renderCameraInfo: function (camera, x, y, color) {
if (this.context == null)
{
return;
}
color = color || 'rgb(255,255,0)';
this.start(x, y, color);
this.line('Camera (' + camera.width + ' x ' + camera.height + ')');
this.line('X: ' + camera.x + ' Y: ' + camera.y);
this.stop();
},
/**
* Renders the Pointer.circle object onto the stage in green if down or red if up.
* @method renderDebug
*/
renderPointer: function (pointer, hideIfUp, downColor, upColor, color) {
if (this.context == null)
{
return;
}
if (typeof hideIfUp === "undefined") { hideIfUp = false; }
if (typeof downColor === "undefined") { downColor = 'rgba(0,255,0,0.5)'; }
if (typeof upColor === "undefined") { upColor = 'rgba(255,0,0,0.5)'; }
if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
if (hideIfUp == true && pointer.isUp == true)
{
return;
}
this.context.beginPath();
this.context.arc(pointer.x, pointer.y, pointer.circle.radius, 0, Math.PI * 2);
if (pointer.active)
{
this.context.fillStyle = downColor;
}
else
{
this.context.fillStyle = upColor;
}
this.context.fill();
this.context.closePath();
// Render the points
this.context.beginPath();
this.context.moveTo(pointer.positionDown.x, pointer.positionDown.y);
this.context.lineTo(pointer.position.x, pointer.position.y);
this.context.lineWidth = 2;
this.context.stroke();
this.context.closePath();
// Render the text
this.start(pointer.x, pointer.y - 100, color);
this.line('ID: ' + pointer.id + " Active: " + pointer.active);
this.line('World X: ' + pointer.worldX + " World Y: " + pointer.worldY);
this.line('Screen X: ' + pointer.x + " Screen Y: " + pointer.y);
this.line('Duration: ' + pointer.duration + " ms");
},
/**
* Render debug information about the Input object.
* @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)
*/
renderInputInfo: function (x, y, color) {
if (this.context == null)
{
return;
}
color = color || 'rgb(255,255,0)';
this.start(x, y, color);
this.line('Input');
this.line('X: ' + this.game.input.x + ' Y: ' + this.game.input.y);
this.line('World X: ' + this.game.input.worldX + ' World Y: ' + this.game.input.worldY);
this.line('Scale X: ' + this.game.input.scale.x.toFixed(1) + ' Scale Y: ' + this.game.input.scale.x.toFixed(1));
this.line('Screen X: ' + this.game.input.activePointer.screenX + ' Screen Y: ' + this.game.input.activePointer.screenY);
this.stop();
},
/**
* 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)
*/
renderSpriteInfo: function (sprite, x, y, color) {
if (this.context == null)
{
return;
}
color = color || 'rgb(255, 255, 255)';
this.start(x, y, color);
this.line('Sprite: ' + ' (' + sprite.width + ' x ' + sprite.height + ') anchor: ' + sprite.anchor.x + ' x ' + sprite.anchor.y);
// this.line('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1));
// this.line('wx: ' + sprite.worldView.x + ' wy: ' + sprite.worldView.y + ' ww: ' + sprite.worldView.width.toFixed(1) + ' wh: ' + sprite.worldView.height.toFixed(1) + ' wb: ' + sprite.worldView.bottom + ' wr: ' + sprite.worldView.right);
// this.line('sx: ' + sprite.scale.x.toFixed(1) + ' sy: ' + sprite.scale.y.toFixed(1));
// 0 = scaleX
// 1 = skewY
// 2 = translateX
// 3 = skewX
// 4 = scaleY
// 5 = translateY
this.line('scale x: ' + sprite.worldTransform[0]);
this.line('scale y: ' + sprite.worldTransform[4]);
this.line('tx: ' + sprite.worldTransform[2]);
this.line('ty: ' + sprite.worldTransform[5]);
this.line('skew x: ' + sprite.worldTransform[1]);
this.line('skew y: ' + sprite.worldTransform[3]);
// this.line('tx: ' + sprite.texture.width.toFixed(1) + ' ty: ' + sprite.texture.height.toFixed(1));
// this.line('center x: ' + sprite.transform.center.x + ' y: ' + sprite.transform.center.y);
// this.line('cameraView x: ' + sprite.cameraView.x + ' y: ' + sprite.cameraView.y + ' width: ' + sprite.cameraView.width + ' height: ' + sprite.cameraView.height);
// this.line('inCamera: ' + this.game.renderer.spriteRenderer.inCamera(this.game.camera, sprite));
},
renderSpriteBounds: function (sprite, color) {
if (this.context == null)
{
return;
}
color = color || 'rgba(0, 255, 0, 0.2)';
this.start();
this.context.fillStyle = color;
this.context.fillRect(sprite.worldView.x, sprite.worldView.y, sprite.worldView.width, sprite.worldView.height);
this.stop();
},
renderPixel: function (x, y, fillStyle) {
if (this.context == null)
{
return;
}
fillStyle = fillStyle || 'rgba(0,255,0,1)';
this.start();
this.context.fillStyle = fillStyle;
this.context.fillRect(x, y, 2, 2);
this.stop();
},
renderPoint: function (point, fillStyle) {
if (this.context == null)
{
return;
}
fillStyle = fillStyle || 'rgba(0,255,0,1)';
this.start();
this.context.fillStyle = fillStyle;
this.context.fillRect(point.x, point.y, 4, 4);
this.stop();
},
renderRectangle: function (rect, fillStyle) {
if (this.context == null)
{
return;
}
fillStyle = fillStyle || 'rgba(0,255,0,0.3)';
this.start();
this.context.fillStyle = fillStyle;
this.context.fillRect(rect.x, rect.y, rect.width, rect.height);
this.stop();
},
renderCircle: function (circle, fillStyle) {
if (this.context == null)
{
return;
}
fillStyle = fillStyle || 'rgba(0,255,0,0.3)';
this.start();
this.context.fillStyle = fillStyle;
this.context.arc(circle.x, circle.y, circle.radius, 0, Math.PI * 2, false);
this.context.fill();
this.stop();
},
/**
* Render text
* @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)
*/
renderText: function (text, x, y, color, font) {
if (this.context == null)
{
return;
}
if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
if (typeof font === "undefined") { font = '16px Courier'; }
this.context.font = font;
this.context.fillStyle = color;
this.context.fillText(text, x, y);
}
};