mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 04:33:31 +00:00
Moved wip to new repo.
This commit is contained in:
parent
bf65fb6a30
commit
49a23f7b6b
354 changed files with 0 additions and 133623 deletions
|
@ -1,167 +0,0 @@
|
|||
var Color = require('./Color');
|
||||
|
||||
var CSSMap = {
|
||||
aliceblue: [ 240, 248, 245 ],
|
||||
antiquewhite: [ 250, 235, 215 ],
|
||||
aqua: [ 0, 255, 255 ],
|
||||
aquamarine: [ 127, 255, 212 ],
|
||||
azure: [ 240, 255, 255 ],
|
||||
beige: [ 245, 245, 220 ],
|
||||
bisque: [ 255, 228, 196 ],
|
||||
black: [ 0, 0, 0 ],
|
||||
blanchedalmond: [ 255, 235, 205 ],
|
||||
blue: [ 0, 0, 255 ],
|
||||
blueviolet: [ 138, 43, 226 ],
|
||||
brown: [ 165, 42, 42 ],
|
||||
burlywood: [ 222, 184, 35 ],
|
||||
cadetblue: [ 95, 158, 160 ],
|
||||
chartreuse: [ 127, 255, 0 ],
|
||||
chocolate: [ 210, 105, 30 ],
|
||||
coral: [ 255, 127, 80 ],
|
||||
cornflowerblue: [ 100, 149, 237 ],
|
||||
cornsilk: [ 255, 248, 220 ],
|
||||
crimson: [ 220, 20, 60 ],
|
||||
darkblue: [ 0, 0, 139 ],
|
||||
darkcyan: [ 0, 139, 139 ],
|
||||
darkgoldenrod: [ 184, 134, 11 ],
|
||||
darkgray: [ 169, 169, 169 ],
|
||||
darkgreen: [ 0, 100, 0 ],
|
||||
darkgrey: [ 169, 169, 169 ],
|
||||
darkkhaki: [ 189, 183, 107 ],
|
||||
darkmagenta: [ 139, 0, 139 ],
|
||||
darkolivegreen: [ 85, 107, 47 ],
|
||||
darkorange: [ 255, 140, 0 ],
|
||||
darkorchid: [ 153, 50, 204 ],
|
||||
darkred: [ 139, 0, 0 ],
|
||||
darksalmon: [ 233, 150, 122 ],
|
||||
darkseagreen: [ 143, 188, 143 ],
|
||||
darkslateblue: [ 72, 61, 139 ],
|
||||
darkslategray: [ 47, 79, 79 ],
|
||||
darkslategrey: [ 47, 79, 79 ],
|
||||
darkturquoise: [ 0, 206, 209 ],
|
||||
darkviolet: [ 148, 0, 211 ],
|
||||
deeppink: [ 255, 20, 147 ],
|
||||
deepskyblue: [ 0, 191, 255 ],
|
||||
dimgray: [ 105, 105, 105 ],
|
||||
dimgrey: [ 105, 105, 105 ],
|
||||
dodgerblue: [ 30, 144, 255 ],
|
||||
firebrick: [ 178, 34, 34 ],
|
||||
floralwhite: [ 255, 250, 240 ],
|
||||
forestgreen: [ 34, 139, 34 ],
|
||||
fuchsia: [ 255, 0, 255 ],
|
||||
gainsboro: [ 220, 220, 220 ],
|
||||
ghostwhite: [ 248, 248, 255 ],
|
||||
gold: [ 255, 215, 0 ],
|
||||
goldenrod: [ 218, 165, 32 ],
|
||||
gray: [ 128, 128, 128 ],
|
||||
green: [ 0, 128, 0 ],
|
||||
greenyellow: [ 173, 255, 47 ],
|
||||
grey: [ 128, 128, 128 ],
|
||||
honeydew: [ 240, 255, 240 ],
|
||||
hotpink: [ 255, 105, 180 ],
|
||||
indianred: [ 205, 92, 92 ],
|
||||
indigo: [ 75, 0, 130 ],
|
||||
ivory: [ 255, 255, 240 ],
|
||||
khaki: [ 240, 230, 140 ],
|
||||
lavender: [ 230, 230, 250 ],
|
||||
lavenderblush: [ 255, 240, 245 ],
|
||||
lawngreen: [ 124, 252, 0 ],
|
||||
lemonchiffon: [ 255, 250, 205 ],
|
||||
lightblue: [ 173, 216, 230 ],
|
||||
lightcoral: [ 240, 128, 128 ],
|
||||
lightcyan: [ 224, 255, 255 ],
|
||||
lightgoldenrodyellow: [ 250, 250, 210 ],
|
||||
lightgray: [ 211, 211, 211 ],
|
||||
lightgreen: [ 144, 238, 144 ],
|
||||
lightgrey: [ 211, 211, 211 ],
|
||||
lightpink: [ 255, 182, 193 ],
|
||||
lightsalmon: [ 255, 160, 122 ],
|
||||
lightseagreen: [ 32, 178, 170 ],
|
||||
lightskyblue: [ 135, 206, 250 ],
|
||||
lightslategray: [ 119, 136, 153 ],
|
||||
lightslategrey: [ 119, 136, 153 ],
|
||||
lightsteelblue: [ 176, 196, 222 ],
|
||||
lightyellow: [ 255, 255, 224 ],
|
||||
lime: [ 0, 255, 0 ],
|
||||
limegreen: [ 50, 205, 50 ],
|
||||
linen: [ 250, 240, 230 ],
|
||||
maroon: [ 128, 0, 0 ],
|
||||
mediumaquamarine: [ 102, 205, 170 ],
|
||||
mediumblue: [ 0, 0, 205 ],
|
||||
mediumorchid: [ 186, 85, 211 ],
|
||||
mediumpurple: [ 147, 112, 219 ],
|
||||
mediumseagreen: [ 60, 179, 113 ],
|
||||
mediumslateblue: [ 123, 104, 238 ],
|
||||
mediumspringgreen: [ 0, 250, 154 ],
|
||||
mediumturquoise: [ 72, 209, 204 ],
|
||||
mediumvioletred: [ 199, 21, 133 ],
|
||||
midnightblue: [ 25, 25, 112 ],
|
||||
mintcream: [ 245, 255, 250 ],
|
||||
mistyrose: [ 255, 228, 225 ],
|
||||
moccasin: [ 255, 228, 181 ],
|
||||
navajowhite: [ 255, 222, 173 ],
|
||||
navy: [ 0, 0, 128 ],
|
||||
oldlace: [ 253, 245, 230 ],
|
||||
olive: [ 128, 128, 0 ],
|
||||
olivedrab: [ 107, 142, 35 ],
|
||||
orange: [ 255, 165, 0 ],
|
||||
orangered: [ 255, 69, 0 ],
|
||||
orchid: [ 218, 112, 214 ],
|
||||
palegoldenrod: [ 238, 232, 170 ],
|
||||
palegreen: [ 152, 251, 152 ],
|
||||
paleturquoise: [ 175, 238, 238 ],
|
||||
palevioletred: [ 219, 112, 147 ],
|
||||
papayawhip: [ 255, 239, 213 ],
|
||||
peachpuff: [ 255, 218, 185 ],
|
||||
peru: [ 205, 133, 63 ],
|
||||
pink: [ 255, 192, 203 ],
|
||||
plum: [ 221, 160, 221 ],
|
||||
powderblue: [ 176, 224, 230 ],
|
||||
purple: [ 128, 0, 128 ],
|
||||
rebeccapurple: [ 102, 51, 153 ],
|
||||
red: [ 255, 0, 0 ],
|
||||
rosybrown: [ 188, 143, 143 ],
|
||||
royalblue: [ 65, 105, 225 ],
|
||||
saddlebrown: [ 139, 69, 19 ],
|
||||
salmon: [ 250, 128, 114 ],
|
||||
sandybrown: [ 244, 164, 96 ],
|
||||
seagreen: [ 46, 139, 87 ],
|
||||
seashell: [ 255, 245, 238 ],
|
||||
sienna: [ 160, 82, 45 ],
|
||||
silver: [ 192, 192, 129 ],
|
||||
skyblue: [ 135, 206, 235 ],
|
||||
slateblue: [ 106, 90, 205 ],
|
||||
slategray: [ 112, 128, 144 ],
|
||||
slategrey: [ 112, 128, 144 ],
|
||||
snow: [ 255, 250, 250 ],
|
||||
springgreen: [ 0, 255, 127 ],
|
||||
steelblue: [ 70, 130, 180 ],
|
||||
tan: [ 210, 180, 140 ],
|
||||
teal: [ 0, 128, 128 ],
|
||||
thistle: [ 216, 191, 216 ],
|
||||
tomato: [ 255, 99, 71 ],
|
||||
turquoise: [ 64, 224, 208 ],
|
||||
violet: [ 238, 130, 238 ],
|
||||
wheat: [ 245, 222, 179 ],
|
||||
white: [ 255, 255, 255 ],
|
||||
whitesmoke: [ 245, 245, 245 ],
|
||||
yellow: [ 255, 255, 0 ],
|
||||
yellowgreen: [ 154, 205, 50 ]
|
||||
};
|
||||
|
||||
var CSSToColor = function (name)
|
||||
{
|
||||
name = name.toLowerCase();
|
||||
|
||||
var color = new Color();
|
||||
var entry = CSSMap[name];
|
||||
|
||||
if (entry)
|
||||
{
|
||||
color.setTo(entry[0], entry[1], entry[2], 255);
|
||||
}
|
||||
|
||||
return color;
|
||||
};
|
||||
|
||||
module.exports = CSSToColor;
|
194
wip/MinMax2.js
194
wip/MinMax2.js
|
@ -1,194 +0,0 @@
|
|||
var Between = require('./Between');
|
||||
var FloatBetween = require('./FloatBetween');
|
||||
var Class = require('../utils/Class');
|
||||
var Percent = require('./Percent');
|
||||
var Wrap = require('./Wrap');
|
||||
|
||||
// A Helper Class that allows you to specify a range between min and max, and then
|
||||
// keep the value within those bounds, or get random ints or floats from the range.
|
||||
|
||||
var MinMax2 = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
function MinMax2 (min, max, steps)
|
||||
{
|
||||
this.min = 0;
|
||||
this.max = 0;
|
||||
this.steps = 0;
|
||||
|
||||
this._current = 0;
|
||||
|
||||
if (min !== undefined)
|
||||
{
|
||||
this.set(min, max, steps);
|
||||
}
|
||||
},
|
||||
|
||||
set: function (min, max, steps)
|
||||
{
|
||||
if (Array.isArray(min))
|
||||
{
|
||||
steps = min[2];
|
||||
max = min[1];
|
||||
min = min[0];
|
||||
}
|
||||
else if (typeof min === 'object')
|
||||
{
|
||||
var obj = min;
|
||||
|
||||
min = (obj.hasOwnProperty('x')) ? obj.x : obj.min;
|
||||
max = (obj.hasOwnProperty('y')) ? obj.y : obj.max;
|
||||
steps = obj.steps;
|
||||
}
|
||||
|
||||
if (min === undefined) { min = 0; }
|
||||
if (max === undefined) { max = min; }
|
||||
if (steps === undefined) { steps = 0; }
|
||||
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.steps = steps;
|
||||
|
||||
this._current = min;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
clone: function ()
|
||||
{
|
||||
return new MinMax2(this.min, this.max, this.steps);
|
||||
},
|
||||
|
||||
copy: function (dest)
|
||||
{
|
||||
dest.min = this.min;
|
||||
dest.max = this.max;
|
||||
dest.steps = this.steps;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
copyXY: function (dest)
|
||||
{
|
||||
dest.x = this.min;
|
||||
dest.y = this.max;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
copyToMinMax: function (dest)
|
||||
{
|
||||
dest.min = this.min;
|
||||
dest.max = this.max;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
// Given U (a value between 0 and 1) return the value in the range
|
||||
getU: function (u)
|
||||
{
|
||||
// TODO
|
||||
},
|
||||
|
||||
// Returns a value between 0 and 1 based on value
|
||||
getPercent: function (value)
|
||||
{
|
||||
return Percent(value, this.min, this.max);
|
||||
},
|
||||
|
||||
getRandom: function ()
|
||||
{
|
||||
return Between(this.min, this.max);
|
||||
},
|
||||
|
||||
getRandomFloat: function ()
|
||||
{
|
||||
return FloatBetween(this.min, this.max);
|
||||
},
|
||||
|
||||
getNext: function ()
|
||||
{
|
||||
var value;
|
||||
|
||||
if (this.steps > 0)
|
||||
{
|
||||
value = this._current;
|
||||
|
||||
var i = value + ((this.max - this.min) / this.steps);
|
||||
|
||||
this._current = Wrap(i, this.min, this.max);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = this.getRandom();
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
|
||||
getNextFloat: function ()
|
||||
{
|
||||
var value;
|
||||
|
||||
if (this.steps > 0)
|
||||
{
|
||||
value = this._current;
|
||||
|
||||
var i = value + ((this.max - this.min) / this.steps);
|
||||
|
||||
this._current = Wrap(i, this.min, this.max);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = this.getRandomFloat();
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
|
||||
current: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._current;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._current = Wrap(value, this.min, this.max);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
x: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.min;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.min = value;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
y: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.max;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.max = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = MinMax2;
|
220
wip/MinMax4.js
220
wip/MinMax4.js
|
@ -1,220 +0,0 @@
|
|||
var Between = require('./Between');
|
||||
var FloatBetween = require('./FloatBetween');
|
||||
var Class = require('../utils/Class');
|
||||
var Percent = require('./Percent');
|
||||
var Wrap = require('./Wrap');
|
||||
var Vector2 = require('./Vector2');
|
||||
|
||||
// A Helper Class that allows you to specify a range between min and max, and then
|
||||
// keep the value within those bounds, or get random ints or floats from the range.
|
||||
|
||||
var MinMax4 = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
function MinMax4 (xMin, xMax, yMin, yMax)
|
||||
{
|
||||
this.xMin = 0;
|
||||
this.xMax = 0;
|
||||
|
||||
this.yMin = 0;
|
||||
this.yMax = 0;
|
||||
|
||||
this._currentX = 0;
|
||||
this._currentY = 0;
|
||||
|
||||
if (xMin !== undefined)
|
||||
{
|
||||
this.set(xMin, xMax, yMin, yMax);
|
||||
}
|
||||
},
|
||||
|
||||
setX: function (min, max)
|
||||
{
|
||||
if (min === undefined) { min = 0; }
|
||||
if (max === undefined) { max = min; }
|
||||
|
||||
this.xMin = min;
|
||||
this.xMax = max;
|
||||
this._currentX = min;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setY: function (min, max)
|
||||
{
|
||||
if (min === undefined) { min = 0; }
|
||||
if (max === undefined) { max = min; }
|
||||
|
||||
this.yMin = min;
|
||||
this.yMax = max;
|
||||
this._currentY = min;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
set: function (xMin, xMax, yMin, yMax)
|
||||
{
|
||||
if (Array.isArray(xMin))
|
||||
{
|
||||
var arr = xMin;
|
||||
|
||||
xMin = arr[0];
|
||||
xMax = arr[1];
|
||||
yMin = arr[2];
|
||||
yMax = arr[3];
|
||||
}
|
||||
else if (typeof xMin === 'object')
|
||||
{
|
||||
var obj = xMin;
|
||||
|
||||
xMin = obj.xMin || obj.min;
|
||||
xMax = obj.xMax || obj.max;
|
||||
yMin = obj.yMin;
|
||||
yMax = obj.yMax;
|
||||
}
|
||||
|
||||
if (xMin === undefined) { xMin = 0; }
|
||||
if (xMax === undefined) { xMax = xMin; }
|
||||
if (yMin === undefined) { yMin = xMin; }
|
||||
if (yMax === undefined) { yMax = xMax; }
|
||||
|
||||
this.setX(xMin, xMax);
|
||||
this.setY(yMin, yMax);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
clone: function ()
|
||||
{
|
||||
return new MinMax4(this.xMin, this.xMax, this.yMin, this.yMax);
|
||||
},
|
||||
|
||||
copyX: function (dest)
|
||||
{
|
||||
dest.x = this.xMin;
|
||||
dest.y = this.xMax;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
copyY: function (dest)
|
||||
{
|
||||
dest.x = this.yMin;
|
||||
dest.y = this.yMax;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
copy: function (dest)
|
||||
{
|
||||
dest.xMin = this.xMin;
|
||||
dest.xMax = this.xMax;
|
||||
|
||||
dest.yMin = this.yMin;
|
||||
dest.yMax = this.yMax;
|
||||
|
||||
return dest;
|
||||
},
|
||||
|
||||
copyXToMinMax: function (dest)
|
||||
{
|
||||
dest.min = this.xMin;
|
||||
dest.max = this.xMax;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
copyYToMinMax: function (dest)
|
||||
{
|
||||
dest.min = this.yMin;
|
||||
dest.max = this.yMax;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/*
|
||||
// Given U (a value between 0 and 1) return the value in the range
|
||||
getU: function (u)
|
||||
{
|
||||
// TODO
|
||||
},
|
||||
|
||||
// Returns a value between 0 and 1 based on value
|
||||
getPercent: function (value)
|
||||
{
|
||||
return Percent(value, this.min, this.max);
|
||||
},
|
||||
*/
|
||||
|
||||
getRandom: function (vec2)
|
||||
{
|
||||
if (vec2 === undefined) { vec2 = new Vector2(); }
|
||||
|
||||
vec2.x = this.getRandomX();
|
||||
vec2.y = this.getRandomY();
|
||||
|
||||
return vec2;
|
||||
},
|
||||
|
||||
getRandomFloat: function (vec2)
|
||||
{
|
||||
if (vec2 === undefined) { vec2 = new Vector2(); }
|
||||
|
||||
vec2.x = this.getRandomXFloat();
|
||||
vec2.y = this.getRandomYFloat();
|
||||
|
||||
return vec2;
|
||||
},
|
||||
|
||||
getRandomX: function ()
|
||||
{
|
||||
return Between(this.xMin, this.xMax);
|
||||
},
|
||||
|
||||
getRandomY: function ()
|
||||
{
|
||||
return Between(this.yMin, this.yMax);
|
||||
},
|
||||
|
||||
getRandomXFloat: function ()
|
||||
{
|
||||
return FloatBetween(this.xMin, this.xMax);
|
||||
},
|
||||
|
||||
getRandomYFloat: function ()
|
||||
{
|
||||
return FloatBetween(this.yMin, this.yMax);
|
||||
},
|
||||
|
||||
x: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._currentX
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._currentX = Wrap(this._currentX, this.xMin, this.xMax);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
y: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._currentY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._currentY = Wrap(this._currentY, this.yMin, this.yMax);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = MinMax4;
|
172
wip/Ticker.js
172
wip/Ticker.js
|
@ -1,172 +0,0 @@
|
|||
/**
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
// Currently un-used
|
||||
// Currently un-used
|
||||
// Currently un-used
|
||||
// Currently un-used
|
||||
// Currently un-used
|
||||
// Currently un-used
|
||||
// Currently un-used
|
||||
|
||||
var NOOP = require('../utils/NOOP');
|
||||
var RequestAnimationFrame = require('../dom/RequestAnimationFrame');
|
||||
|
||||
var Ticker = function (game, framerate)
|
||||
{
|
||||
this.game = game;
|
||||
|
||||
this.raf = new RequestAnimationFrame();
|
||||
|
||||
this.started = false;
|
||||
this.running = false;
|
||||
|
||||
this.lastUpdate = 0;
|
||||
|
||||
this.gap = 1 / (framerate || 60);
|
||||
this.startTime = 0;
|
||||
this.elapsed = 0;
|
||||
this.time = 0;
|
||||
this.nextTime = 0;
|
||||
this.frame = 0;
|
||||
this.overlap = 0;
|
||||
this.fps = framerate;
|
||||
|
||||
this.callback = NOOP;
|
||||
|
||||
this.lagThreshold = 500;
|
||||
this.adjustedLag = 33;
|
||||
|
||||
this.useRAF = true;
|
||||
};
|
||||
|
||||
Ticker.prototype.constructor = Ticker;
|
||||
|
||||
Ticker.prototype = {
|
||||
|
||||
toString: function ()
|
||||
{
|
||||
return 'time: ' + this.time + ' elapsed: ' + this.elapsed + ' overlap: ' + this.overlap;
|
||||
},
|
||||
|
||||
start: function (useRAF, callback)
|
||||
{
|
||||
if (this.started)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
this.started = true;
|
||||
this.running = true;
|
||||
|
||||
var now = window.performance.now();
|
||||
|
||||
this.startTime = now;
|
||||
this.lastUpdate = now;
|
||||
|
||||
this.useRAF = useRAF;
|
||||
this.callback = callback;
|
||||
|
||||
this.raf.start(this.step.bind(this), useRAF);
|
||||
},
|
||||
|
||||
step: function (time, manual)
|
||||
{
|
||||
var elapsed = time - this.lastUpdate;
|
||||
|
||||
if (elapsed > this.lagThreshold)
|
||||
{
|
||||
this.startTime += elapsed - this.adjustedLag;
|
||||
}
|
||||
|
||||
this.lastUpdate += elapsed;
|
||||
|
||||
var dt = (this.lastUpdate - this.startTime) / 1000;
|
||||
|
||||
this.elapsed = elapsed;
|
||||
|
||||
var overlap = dt - this.nextTime;
|
||||
|
||||
this.overlap = overlap;
|
||||
|
||||
this.time = dt;
|
||||
|
||||
if (overlap > 0 || manual)
|
||||
{
|
||||
this.frame++;
|
||||
this.nextTime += overlap + ((overlap >= this.gap) ? 0.004 : this.gap - overlap);
|
||||
this.callback(elapsed);
|
||||
}
|
||||
},
|
||||
|
||||
tick: function ()
|
||||
{
|
||||
this.step(true);
|
||||
},
|
||||
|
||||
lagSmoothing: function (threshold, adjustedLag)
|
||||
{
|
||||
this.lagThreshold = threshold || (1 / 0.0000000001); //zero should be interpreted as basically unlimited
|
||||
this.adjustedLag = Math.min(adjustedLag, this.lagThreshold, 0);
|
||||
},
|
||||
|
||||
sleep: function ()
|
||||
{
|
||||
if (this.running)
|
||||
{
|
||||
this.raf.stop();
|
||||
|
||||
this.running = false;
|
||||
}
|
||||
},
|
||||
|
||||
wake: function (seamless)
|
||||
{
|
||||
if (this.running)
|
||||
{
|
||||
this.sleep();
|
||||
}
|
||||
else if (seamless)
|
||||
{
|
||||
this.startTime += -this.lastUpdate + (this.lastUpdate = Date.now());
|
||||
}
|
||||
else if (this.frame > 10)
|
||||
{
|
||||
this.lastUpdate = Date.now() - this.lagThreshold + 5;
|
||||
}
|
||||
|
||||
this.raf.start(this.step.bind(this), this.useRAF);
|
||||
|
||||
this.running = true;
|
||||
|
||||
this.step(true);
|
||||
},
|
||||
|
||||
setFps: function (value)
|
||||
{
|
||||
this.fps = value;
|
||||
this.gap = 1 / (value || 60);
|
||||
this.nextTime = this.time + this.gap;
|
||||
|
||||
this.wake();
|
||||
},
|
||||
|
||||
getFps: function ()
|
||||
{
|
||||
return this.fps;
|
||||
},
|
||||
|
||||
stop: function ()
|
||||
{
|
||||
this.running = false;
|
||||
this.started = false;
|
||||
|
||||
this.raf.stop();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = Ticker;
|
|
@ -1,631 +0,0 @@
|
|||
/**
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
var Class = require('../utils/Class');
|
||||
var GetValue = require('../utils/object/GetValue');
|
||||
var NOOP = require('../utils/NOOP');
|
||||
var RequestAnimationFrame = require('../dom/RequestAnimationFrame');
|
||||
|
||||
// Frame Rate config
|
||||
// fps: {
|
||||
// min: 10,
|
||||
// target: 60,
|
||||
// forceSetTimeOut: false,
|
||||
// deltaHistory: 10,
|
||||
// panicMax: 120
|
||||
// }
|
||||
|
||||
// http://www.testufo.com/#test=animation-time-graph
|
||||
|
||||
var TimeStep = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @class TimeStep
|
||||
* @memberOf Phaser.Boot
|
||||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Game} game - [description]
|
||||
* @param {FPSConfig]} config - [description]
|
||||
*/
|
||||
function TimeStep (game, config)
|
||||
{
|
||||
/**
|
||||
* A reference to the Phaser.Game instance.
|
||||
*
|
||||
* @property {Phaser.Game} game
|
||||
* @readOnly
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {Phaser.DOM.RequestAnimationFrame} raf
|
||||
* @readOnly
|
||||
*/
|
||||
this.raf = new RequestAnimationFrame();
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {boolean} started
|
||||
* @readOnly
|
||||
*/
|
||||
this.started = false;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {boolean} running
|
||||
* @readOnly
|
||||
*/
|
||||
this.running = false;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} minFps
|
||||
*/
|
||||
this.minFps = GetValue(config, 'min', 5);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} targetFps
|
||||
*/
|
||||
this.targetFps = GetValue(config, 'target', 60);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {number} _min
|
||||
* @private
|
||||
*/
|
||||
this._min = 1000 / this.minFps; // 200ms between frames (i.e. super slow!)
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {number} _target
|
||||
* @private
|
||||
*/
|
||||
this._target = 1000 / this.targetFps; // 16.666ms between frames (i.e. normal)
|
||||
|
||||
// 200 / 1000 = 0.2 (5fps)
|
||||
// 8.333 / 1000 = 0.008333 (120fps)
|
||||
// 16.666 / 1000 = 0.01666 (60fps)
|
||||
|
||||
/**
|
||||
* An exponential moving average of the frames per second.
|
||||
*
|
||||
* @property {integer} actualFps
|
||||
* @readOnly
|
||||
*/
|
||||
this.actualFps = this.targetFps;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} nextFpsUpdate
|
||||
* @readOnly
|
||||
*/
|
||||
this.nextFpsUpdate = 0;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} framesThisSecond
|
||||
* @readOnly
|
||||
*/
|
||||
this.framesThisSecond = 0;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {function} callback
|
||||
*/
|
||||
this.callback = NOOP;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {boolean} forceSetTimeOut
|
||||
* @readOnly
|
||||
*/
|
||||
this.forceSetTimeOut = GetValue(config, 'forceSetTimeOut', false);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} time
|
||||
*/
|
||||
this.time = 0;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} startTime
|
||||
*/
|
||||
this.startTime = 0;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} lastTime
|
||||
*/
|
||||
this.lastTime = 0;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} frame
|
||||
* @readOnly
|
||||
*/
|
||||
this.frame = 0;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {boolean} inFocus
|
||||
* @readOnly
|
||||
*/
|
||||
this.inFocus = true;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} _pauseTime
|
||||
* @private
|
||||
*/
|
||||
this._pauseTime = 0;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} _coolDown
|
||||
* @private
|
||||
*/
|
||||
this._coolDown = 0;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} delta
|
||||
*/
|
||||
this.delta = 0;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} deltaIndex
|
||||
*/
|
||||
this.deltaIndex = 0;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {array} deltaHistory
|
||||
*/
|
||||
this.deltaHistory = [];
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} deltaSmoothingMax
|
||||
* @default 10
|
||||
*/
|
||||
this.deltaSmoothingMax = GetValue(config, 'deltaHistory', 10);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} panicMax
|
||||
* @default 120
|
||||
*/
|
||||
this.panicMax = GetValue(config, 'panicMax', 120);
|
||||
|
||||
/**
|
||||
* The actual elapsed time in ms between one update and the next.
|
||||
* Unlike with `delta` no smoothing, capping, or averaging is applied to this value.
|
||||
* So please be careful when using this value in calculations.
|
||||
*
|
||||
* @property {number} rawDelta
|
||||
*/
|
||||
this.rawDelta = 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when the DOM window.onBlur event triggers.
|
||||
*
|
||||
* @method Phaser.Boot.TimeStep#blur
|
||||
* @since 3.0.0
|
||||
*/
|
||||
blur: function ()
|
||||
{
|
||||
this.inFocus = false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when the DOM window.onFocus event triggers.
|
||||
*
|
||||
* @method Phaser.Boot.TimeStep#focus
|
||||
* @since 3.0.0
|
||||
*/
|
||||
focus: function ()
|
||||
{
|
||||
this.inFocus = true;
|
||||
|
||||
this.resetDelta();
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when the visibility API says the game is 'hidden' (tab switch, etc)
|
||||
*
|
||||
* @method Phaser.Boot.TimeStep#pause
|
||||
* @since 3.0.0
|
||||
*/
|
||||
pause: function ()
|
||||
{
|
||||
this._pauseTime = window.performance.now();
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when the visibility API says the game is 'visible' again (tab switch, etc)
|
||||
*
|
||||
* @method Phaser.Boot.TimeStep#resume
|
||||
* @since 3.0.0
|
||||
*/
|
||||
resume: function ()
|
||||
{
|
||||
this.resetDelta();
|
||||
|
||||
this.startTime += this.time - this._pauseTime;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Boot.TimeStep#resetDelta
|
||||
* @since 3.0.0
|
||||
*/
|
||||
resetDelta: function ()
|
||||
{
|
||||
var now = window.performance.now();
|
||||
|
||||
this.time = now;
|
||||
this.lastTime = now;
|
||||
this.nextFpsUpdate = now + 1000;
|
||||
this.framesThisSecond = 0;
|
||||
this.frame = 0;
|
||||
|
||||
// Pre-populate smoothing array
|
||||
|
||||
for (var i = 0; i < this.deltaSmoothingMax; i++)
|
||||
{
|
||||
this.deltaHistory[i] = Math.min(this._target, this.deltaHistory[i]);
|
||||
}
|
||||
|
||||
this.delta = 0;
|
||||
this.deltaIndex = 0;
|
||||
|
||||
this._coolDown = this.panicMax;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Boot.TimeStep#start
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {function} callback - [description]
|
||||
*/
|
||||
start: function (callback)
|
||||
{
|
||||
if (this.started)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
this.started = true;
|
||||
this.running = true;
|
||||
|
||||
for (var i = 0; i < this.deltaSmoothingMax; i++)
|
||||
{
|
||||
this.deltaHistory[i] = this._target;
|
||||
}
|
||||
|
||||
this.resetDelta();
|
||||
|
||||
this.startTime = window.performance.now();
|
||||
|
||||
this.callback = callback;
|
||||
|
||||
this.raf.start(this.step.bind(this), this.forceSetTimeOut);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Boot.TimeStep#step
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} time - The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.
|
||||
*/
|
||||
step: function (time)
|
||||
{
|
||||
// Debug only
|
||||
// var debug = 0;
|
||||
// var dump = [];
|
||||
|
||||
this.frame++;
|
||||
|
||||
this.rawDelta = time - this.lastTime;
|
||||
|
||||
var idx = this.deltaIndex;
|
||||
var history = this.deltaHistory;
|
||||
var max = this.deltaSmoothingMax;
|
||||
|
||||
// delta time (time is in ms)
|
||||
var dt = (time - this.lastTime);
|
||||
|
||||
// When a browser switches tab, then comes back again, it takes around 10 frames before
|
||||
// the delta time settles down so we employ a 'cooling down' period before we start
|
||||
// trusting the delta values again, to avoid spikes flooding through our delta average
|
||||
|
||||
if (this._coolDown > 0 || !this.inFocus)
|
||||
{
|
||||
this._coolDown--;
|
||||
|
||||
dt = Math.min(dt, this._target);
|
||||
|
||||
// debug = (time - this.lastTime);
|
||||
}
|
||||
|
||||
if (dt > this._min)
|
||||
{
|
||||
// Probably super bad start time or browser tab context loss,
|
||||
// so use the last 'sane' dt value
|
||||
|
||||
// debug = dt;
|
||||
|
||||
dt = history[idx];
|
||||
|
||||
// Clamp delta to min (in case history has become corrupted somehow)
|
||||
dt = Math.min(dt, this._min);
|
||||
}
|
||||
|
||||
// Smooth out the delta over the previous X frames
|
||||
|
||||
// add the delta to the smoothing array
|
||||
history[idx] = dt;
|
||||
|
||||
// adjusts the delta history array index based on the smoothing count
|
||||
// this stops the array growing beyond the size of deltaSmoothingMax
|
||||
this.deltaIndex++;
|
||||
|
||||
if (this.deltaIndex > max)
|
||||
{
|
||||
this.deltaIndex = 0;
|
||||
}
|
||||
|
||||
// Delta Average
|
||||
var avg = 0;
|
||||
|
||||
// Loop the history array, adding the delta values together
|
||||
|
||||
for (var i = 0; i < max; i++)
|
||||
{
|
||||
// Debug
|
||||
// if (history[i] < 16 || history[i] > 17)
|
||||
// {
|
||||
// dump.push({ i: i, dt: history[i] });
|
||||
// }
|
||||
|
||||
avg += history[i];
|
||||
}
|
||||
|
||||
// Then divide by the array length to get the average delta
|
||||
avg /= max;
|
||||
|
||||
// Set as the world delta value
|
||||
this.delta = avg;
|
||||
|
||||
// Real-world timer advance
|
||||
// this.time += avg;
|
||||
this.time += this.rawDelta;
|
||||
|
||||
// Update the estimate of the frame rate, `fps`. Every second, the number
|
||||
// of frames that occurred in that second are included in an exponential
|
||||
// moving average of all frames per second, with an alpha of 0.25. This
|
||||
// means that more recent seconds affect the estimated frame rate more than
|
||||
// older seconds.
|
||||
//
|
||||
// When a browser window is NOT minimized, but is covered up (i.e. you're using
|
||||
// another app which has spawned a window over the top of the browser), then it
|
||||
// will start to throttle the raf callback time. It waits for a while, and then
|
||||
// starts to drop the frame rate at 1 frame per second until it's down to just over 1fps.
|
||||
// So if the game was running at 60fps, and the player opens a new window, then
|
||||
// after 60 seconds (+ the 'buffer time') it'll be down to 1fps, so rafin'g at 1Hz.
|
||||
//
|
||||
// When they make the game visible again, the frame rate is increased at a rate of
|
||||
// approx. 8fps, back up to 60fps (or the max it can obtain)
|
||||
//
|
||||
// There is no easy way to determine if this drop in frame rate is because the
|
||||
// browser is throttling raf, or because the game is struggling with performance
|
||||
// because you're asking it to do too much on the device.
|
||||
|
||||
if (time > this.nextFpsUpdate)
|
||||
{
|
||||
// Compute the new exponential moving average with an alpha of 0.25.
|
||||
this.actualFps = 0.25 * this.framesThisSecond + 0.75 * this.actualFps;
|
||||
this.nextFpsUpdate = time + 1000;
|
||||
this.framesThisSecond = 0;
|
||||
|
||||
// if (this.actualFps < 56)
|
||||
// {
|
||||
// console.log(this.actualFps);
|
||||
// console.log('F', this.frame, 'Avg', avg, 'Dt', debug, 'Panic', this._coolDown);
|
||||
// }
|
||||
}
|
||||
|
||||
this.framesThisSecond++;
|
||||
|
||||
// Interpolation - how far between what is expected and where we are?
|
||||
var interpolation = avg / this._target;
|
||||
|
||||
this.callback(time, avg, interpolation);
|
||||
|
||||
// Shift time value over
|
||||
this.lastTime = time;
|
||||
|
||||
// if (debug !== 0)
|
||||
// {
|
||||
// console.log('F', this.frame, 'Avg', avg, 'Dt', debug, 'Panic', this._coolDown);
|
||||
// }
|
||||
|
||||
/*
|
||||
if (debug !== 0 || dump.length)
|
||||
{
|
||||
console.group('Frame ' + this.frame);
|
||||
console.log('Interpolation', interpolation, '%');
|
||||
|
||||
if (debug)
|
||||
{
|
||||
console.log('Elapsed', debug, 'ms');
|
||||
}
|
||||
|
||||
// console.log('Frame', this.frame, 'Delta', avg, '(average)', debug, '(now)');
|
||||
|
||||
console.log('Delta', avg, '(average)');
|
||||
|
||||
if (dump.length)
|
||||
{
|
||||
console.table(dump);
|
||||
}
|
||||
|
||||
console.groupEnd();
|
||||
}
|
||||
*/
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Boot.TimeStep#tick
|
||||
* @since 3.0.0
|
||||
*/
|
||||
tick: function ()
|
||||
{
|
||||
this.step(window.performance.now());
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Boot.TimeStep#sleep
|
||||
* @since 3.0.0
|
||||
*/
|
||||
sleep: function ()
|
||||
{
|
||||
if (this.running)
|
||||
{
|
||||
this.raf.stop();
|
||||
|
||||
this.running = false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Boot.TimeStep#wake
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {boolean} [seamless=false] - [description]
|
||||
*/
|
||||
wake: function (seamless)
|
||||
{
|
||||
if (this.running)
|
||||
{
|
||||
this.sleep();
|
||||
}
|
||||
else if (seamless)
|
||||
{
|
||||
this.startTime += -this.lastTime + (this.lastTime = window.performance.now());
|
||||
}
|
||||
|
||||
this.raf.start(this.step.bind(this), this.useRAF);
|
||||
|
||||
this.running = true;
|
||||
|
||||
this.step(window.performance.now());
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Boot.TimeStep#setFps
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} value - [description]
|
||||
*/
|
||||
setFps: function (value)
|
||||
{
|
||||
this.sleep();
|
||||
|
||||
this.fps = value;
|
||||
|
||||
this.wake();
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Boot.TimeStep#getFps
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {integer} [description]
|
||||
*/
|
||||
getFps: function ()
|
||||
{
|
||||
return this.fps;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Boot.TimeStep#stop
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
stop: function ()
|
||||
{
|
||||
this.running = false;
|
||||
this.started = false;
|
||||
|
||||
this.raf.stop();
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Boot.TimeStep#destroy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.stop();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = TimeStep;
|
296
wip/Transform.js
296
wip/Transform.js
|
@ -1,296 +0,0 @@
|
|||
var MATH_CONST = require('../../math/const');
|
||||
var WrapAngle = require('../../math/angle/Wrap');
|
||||
var WrapAngleDegrees = require('../../math/angle/WrapDegrees');
|
||||
|
||||
// global bitmask flag for GameObject.renderMask (used by Scale)
|
||||
var _FLAG = 4; // 0100
|
||||
|
||||
// Transform Component
|
||||
|
||||
var Transform = {
|
||||
|
||||
// "private" properties
|
||||
_scaleX: 1,
|
||||
_scaleY: 1,
|
||||
_rotation: 0,
|
||||
_depth: 0,
|
||||
_dirty: false,
|
||||
_world: { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0, sr: 0, cr: 0 },
|
||||
|
||||
// public properties / methods
|
||||
|
||||
// These are world coordinate values.
|
||||
|
||||
// If Game Object is a child of a Container, then you can modify its local position (relative to the Container)
|
||||
// by setting `localX`, `localY`, etc (or changing x/y directly, but remember the values given here are world based).
|
||||
// Changes to the parent Container are instantly reflected in the world coords here (x,y, etc)
|
||||
|
||||
_x: 0,
|
||||
_y: 0,
|
||||
_z: 0,
|
||||
_w: 0,
|
||||
|
||||
x: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._x;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._x = value;
|
||||
this._dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
y: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._y;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._y = value;
|
||||
this._dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
z: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._z;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._z = value;
|
||||
this._dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
w: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._w;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._w = value;
|
||||
this._dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
scaleX: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._scaleX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._scaleX = value;
|
||||
this._dirty = true;
|
||||
|
||||
if (this._scaleX === 0)
|
||||
{
|
||||
this.renderFlags &= ~_FLAG;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.renderFlags |= _FLAG;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
scaleY: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._scaleY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._scaleY = value;
|
||||
this._dirty = true;
|
||||
|
||||
if (this._scaleY === 0)
|
||||
{
|
||||
this.renderFlags &= ~_FLAG;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.renderFlags |= _FLAG;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
angle: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return WrapAngleDegrees(this._rotation * MATH_CONST.RAD_TO_DEG);
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
// value is in degrees
|
||||
this.rotation = WrapAngleDegrees(value) * MATH_CONST.DEG_TO_RAD;
|
||||
}
|
||||
},
|
||||
|
||||
rotation: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._rotation;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
// value is in radians
|
||||
this._rotation = WrapAngle(value);
|
||||
|
||||
this._world.sr = Math.sin(this._rotation);
|
||||
this._world.cr = Math.cos(this._rotation);
|
||||
|
||||
this._dirty = true;
|
||||
}
|
||||
},
|
||||
|
||||
depth: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._depth;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.scene.sys.queueDepthSort();
|
||||
this._depth = value;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
setPosition: function (x, y, z, w)
|
||||
{
|
||||
if (x === undefined) { x = 0; }
|
||||
if (y === undefined) { y = x; }
|
||||
if (z === undefined) { z = 0; }
|
||||
if (w === undefined) { w = 0; }
|
||||
|
||||
this._x = x;
|
||||
this._y = y;
|
||||
this._z = z;
|
||||
this._w = w;
|
||||
|
||||
this._dirty = true;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setRotation: function (radians)
|
||||
{
|
||||
if (radians === undefined) { radians = 0; }
|
||||
|
||||
this.rotation = radians;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setAngle: function (degrees)
|
||||
{
|
||||
if (degrees === undefined) { degrees = 0; }
|
||||
|
||||
this.angle = degrees;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setScale: function (x, y)
|
||||
{
|
||||
if (x === undefined) { x = 1; }
|
||||
if (y === undefined) { y = x; }
|
||||
|
||||
this.scaleX = x;
|
||||
this.scaleY = y;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setZ: function (value)
|
||||
{
|
||||
if (value === undefined) { value = 0; }
|
||||
|
||||
this.z = value;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setW: function (value)
|
||||
{
|
||||
if (value === undefined) { value = 0; }
|
||||
|
||||
this.w = value;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setDepth: function (value)
|
||||
{
|
||||
if (value === undefined) { value = 0; }
|
||||
|
||||
this.depth = value;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
updateTransform: function ()
|
||||
{
|
||||
if (!this.parent || !this._dirty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var tx = this._x;
|
||||
var ty = this._y;
|
||||
var world = this._world;
|
||||
|
||||
var parent = this.parent.world;
|
||||
|
||||
var a = world.cr * this._scaleX;
|
||||
var b = world.sr * this._scaleX;
|
||||
var c = -world.sr * this._scaleY;
|
||||
var d = world.cr * this._scaleY;
|
||||
|
||||
world.a = (a * parent.a) + (b * parent.c);
|
||||
world.b = (a * parent.b) + (b * parent.d);
|
||||
world.c = (c * parent.a) + (d * parent.c);
|
||||
world.d = (c * parent.b) + (d * parent.d);
|
||||
|
||||
// this._worldRotation = Math.atan2(-this.world.c, this.world.d);
|
||||
|
||||
world.tx = (tx * parent.a) + (ty * parent.c) + parent.tx;
|
||||
world.ty = (tx * parent.b) + (ty * parent.d) + parent.ty;
|
||||
|
||||
// this._worldScaleX = this._scaleX * Math.sqrt((world.a * world.a) + (world.c * world.c));
|
||||
// this._worldScaleY = this._scaleY * Math.sqrt((world.b * world.b) + (world.d * world.d));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = Transform;
|
|
@ -1,9 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
(function(){
|
||||
|
||||
var root = this;
|
|
@ -1,23 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
if (typeof exports !== 'undefined') {
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
exports = module.exports = Phaser;
|
||||
}
|
||||
exports.Phaser = Phaser;
|
||||
} else if (typeof define !== 'undefined' && define.amd) {
|
||||
define('Phaser', (function() { return root.Phaser = Phaser; })() );
|
||||
} else {
|
||||
root.Phaser = Phaser;
|
||||
}
|
||||
|
||||
return Phaser;
|
||||
}).call(this);
|
||||
|
||||
/*
|
||||
* "What matters in this life is not what we do but what we do for others, the legacy we leave and the imprint we make." - Eric Meyer
|
||||
*/
|
|
@ -1,567 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
// "First do it, then do it right, then do it better" - Addy Osmani
|
||||
|
||||
/**
|
||||
* @namespace Phaser
|
||||
*/
|
||||
var Phaser = Phaser || { // jshint ignore:line
|
||||
|
||||
/**
|
||||
* The Phaser version number.
|
||||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
VERSION: '3.0.0.r6',
|
||||
|
||||
/**
|
||||
* An array of Phaser game instances.
|
||||
* @constant
|
||||
* @type {array}
|
||||
*/
|
||||
GAMES: [],
|
||||
|
||||
/**
|
||||
* AUTO renderer - picks between WebGL or Canvas based on device.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
AUTO: 0,
|
||||
|
||||
/**
|
||||
* Canvas Renderer.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
CANVAS: 1,
|
||||
|
||||
/**
|
||||
* WebGL Renderer.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
WEBGL: 2,
|
||||
|
||||
/**
|
||||
* Headless renderer (not visual output)
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
HEADLESS: 3,
|
||||
|
||||
/**
|
||||
* WebGL Renderer with MultiTexture support enabled.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
WEBGL_MULTI: 4,
|
||||
|
||||
/**
|
||||
* Direction constant.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
NONE: 0,
|
||||
|
||||
/**
|
||||
* Direction constant.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
LEFT: 1,
|
||||
|
||||
/**
|
||||
* Direction constant.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
RIGHT: 2,
|
||||
|
||||
/**
|
||||
* Direction constant.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
UP: 3,
|
||||
|
||||
/**
|
||||
* Direction constant.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
DOWN: 4,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
SPRITE: 0,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
BUTTON: 1,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
IMAGE: 2,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
GRAPHICS: 3,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
TEXT: 4,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
TILESPRITE: 5,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
BITMAPTEXT: 6,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
GROUP: 7,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
RENDERTEXTURE: 8,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
TILEMAP: 9,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
TILEMAPLAYER: 10,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
EMITTER: 11,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
POLYGON: 12,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
BITMAPDATA: 13,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
CANVAS_FILTER: 14,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
WEBGL_FILTER: 15,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
ELLIPSE: 16,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
SPRITEBATCH: 17,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
RETROFONT: 18,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
POINTER: 19,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
ROPE: 20,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
CIRCLE: 21,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
RECTANGLE: 22,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
LINE: 23,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
MATRIX: 24,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
POINT: 25,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
ROUNDEDRECTANGLE: 26,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
CREATURE: 27,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
VIDEO: 28,
|
||||
|
||||
/**
|
||||
* Game Object type.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
PENDING_ATLAS: -1,
|
||||
|
||||
/**
|
||||
* A horizontal orientation
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
HORIZONTAL: 0,
|
||||
|
||||
/**
|
||||
* A vertical orientation
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
VERTICAL: 1,
|
||||
|
||||
/**
|
||||
* A landscape orientation
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
LANDSCAPE: 0,
|
||||
|
||||
/**
|
||||
* A portrait orientation
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
PORTRAIT: 1,
|
||||
|
||||
/**
|
||||
* The Angle (in degrees) a Game Object needs to be set to in order to face up.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
ANGLE_UP: 270,
|
||||
|
||||
/**
|
||||
* The Angle (in degrees) a Game Object needs to be set to in order to face down.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
ANGLE_DOWN: 90,
|
||||
|
||||
/**
|
||||
* The Angle (in degrees) a Game Object needs to be set to in order to face left.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
ANGLE_LEFT: 180,
|
||||
|
||||
/**
|
||||
* The Angle (in degrees) a Game Object needs to be set to in order to face right.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
ANGLE_RIGHT: 0,
|
||||
|
||||
/**
|
||||
* The Angle (in degrees) a Game Object needs to be set to in order to face north east.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
ANGLE_NORTH_EAST: 315,
|
||||
|
||||
/**
|
||||
* The Angle (in degrees) a Game Object needs to be set to in order to face north west.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
ANGLE_NORTH_WEST: 225,
|
||||
|
||||
/**
|
||||
* The Angle (in degrees) a Game Object needs to be set to in order to face south east.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
ANGLE_SOUTH_EAST: 45,
|
||||
|
||||
/**
|
||||
* The Angle (in degrees) a Game Object needs to be set to in order to face south west.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
ANGLE_SOUTH_WEST: 135,
|
||||
|
||||
/**
|
||||
* A constant representing a top-left alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
TOP_LEFT: 0,
|
||||
|
||||
/**
|
||||
* A constant representing a top-center alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
TOP_CENTER: 1,
|
||||
|
||||
/**
|
||||
* A constant representing a top-right alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
TOP_RIGHT: 2,
|
||||
|
||||
/**
|
||||
* A constant representing a left-top alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
LEFT_TOP: 3,
|
||||
|
||||
/**
|
||||
* A constant representing a left-center alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
LEFT_CENTER: 4,
|
||||
|
||||
/**
|
||||
* A constant representing a left-bottom alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
LEFT_BOTTOM: 5,
|
||||
|
||||
/**
|
||||
* A constant representing a center alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
CENTER: 6,
|
||||
|
||||
/**
|
||||
* A constant representing a right-top alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
RIGHT_TOP: 7,
|
||||
|
||||
/**
|
||||
* A constant representing a right-center alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
RIGHT_CENTER: 8,
|
||||
|
||||
/**
|
||||
* A constant representing a right-bottom alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
RIGHT_BOTTOM: 9,
|
||||
|
||||
/**
|
||||
* A constant representing a bottom-left alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
BOTTOM_LEFT: 10,
|
||||
|
||||
/**
|
||||
* A constant representing a bottom-center alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
BOTTOM_CENTER: 11,
|
||||
|
||||
/**
|
||||
* A constant representing a bottom-right alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
BOTTOM_RIGHT: 12,
|
||||
|
||||
/**
|
||||
* A constant representing a no-operation function
|
||||
* @constant
|
||||
* @type {function}
|
||||
*/
|
||||
NOOP: function () {},
|
||||
|
||||
/**
|
||||
* Various blend modes supported by Pixi.
|
||||
*
|
||||
* IMPORTANT: The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes.
|
||||
*
|
||||
* @constant
|
||||
* @property {Number} blendModes.NORMAL
|
||||
* @property {Number} blendModes.ADD
|
||||
* @property {Number} blendModes.MULTIPLY
|
||||
* @property {Number} blendModes.SCREEN
|
||||
* @property {Number} blendModes.OVERLAY
|
||||
* @property {Number} blendModes.DARKEN
|
||||
* @property {Number} blendModes.LIGHTEN
|
||||
* @property {Number} blendModes.COLOR_DODGE
|
||||
* @property {Number} blendModes.COLOR_BURN
|
||||
* @property {Number} blendModes.HARD_LIGHT
|
||||
* @property {Number} blendModes.SOFT_LIGHT
|
||||
* @property {Number} blendModes.DIFFERENCE
|
||||
* @property {Number} blendModes.EXCLUSION
|
||||
* @property {Number} blendModes.HUE
|
||||
* @property {Number} blendModes.SATURATION
|
||||
* @property {Number} blendModes.COLOR
|
||||
* @property {Number} blendModes.LUMINOSITY
|
||||
* @static
|
||||
*/
|
||||
blendModes: {
|
||||
NORMAL: 0,
|
||||
ADD: 1,
|
||||
MULTIPLY: 2,
|
||||
SCREEN: 3,
|
||||
OVERLAY: 4,
|
||||
DARKEN: 5,
|
||||
LIGHTEN: 6,
|
||||
COLOR_DODGE: 7,
|
||||
COLOR_BURN: 8,
|
||||
HARD_LIGHT: 9,
|
||||
SOFT_LIGHT: 10,
|
||||
DIFFERENCE: 11,
|
||||
EXCLUSION: 12,
|
||||
HUE: 13,
|
||||
SATURATION: 14,
|
||||
COLOR: 15,
|
||||
LUMINOSITY: 16
|
||||
},
|
||||
|
||||
/**
|
||||
* The scale modes that are supported by Pixi.
|
||||
*
|
||||
* The DEFAULT scale mode affects the default scaling mode of future operations.
|
||||
* It can be re-assigned to either LINEAR or NEAREST, depending upon suitability.
|
||||
*
|
||||
* @constant
|
||||
* @property {Object} Phaser.scaleModes
|
||||
* @property {Number} scaleModes.DEFAULT=LINEAR
|
||||
* @property {Number} scaleModes.LINEAR Smooth scaling
|
||||
* @property {Number} scaleModes.NEAREST Pixelating scaling
|
||||
* @static
|
||||
*/
|
||||
scaleModes: {
|
||||
DEFAULT: 0,
|
||||
LINEAR: 0,
|
||||
NEAREST: 1
|
||||
},
|
||||
|
||||
Component: {},
|
||||
GameObject: {},
|
||||
Renderer: {},
|
||||
|
||||
tempMatrix: null
|
||||
|
||||
};
|
||||
|
||||
// "Anybody who doesn’t change their mind a lot is
|
||||
// dramatically underestimating the complexity of
|
||||
// the world we live in.” - Jeff Bezos
|
||||
|
||||
// Remove when ready
|
||||
var PIXI = PIXI || {};
|
File diff suppressed because it is too large
Load diff
|
@ -1,890 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* An Animation instance contains a single animation and the controls to play it.
|
||||
*
|
||||
* It is created by the AnimationManager, consists of Animation.Frame objects and belongs to a single Game Object such as a Sprite.
|
||||
*
|
||||
* @class Phaser.Animation
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {Phaser.Sprite} parent - A reference to the owner of this Animation.
|
||||
* @param {string} name - The unique name for this animation, used in playback commands.
|
||||
* @param {Phaser.FrameData} frameData - The FrameData object that contains all frames used by this Animation.
|
||||
* @param {number[]|string[]} frames - An array of numbers or strings indicating which frames to play in which order.
|
||||
* @param {number} [frameRate=60] - The speed at which the animation should play. The speed is given in frames per second.
|
||||
* @param {boolean} [loop=false] - Whether or not the animation is looped or just plays once.
|
||||
*/
|
||||
Phaser.Animation = function (game, parent, name, frameData, frames, frameRate, loop) {
|
||||
|
||||
if (loop === undefined) { loop = false; }
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Sprite} _parent - A reference to the parent Sprite that owns this Animation.
|
||||
* @private
|
||||
*/
|
||||
this._parent = parent;
|
||||
|
||||
/**
|
||||
* @property {Phaser.FrameData} _frameData - The FrameData the Animation uses.
|
||||
* @private
|
||||
*/
|
||||
this._frameData = frameData;
|
||||
|
||||
/**
|
||||
* @property {string} name - The user defined name given to this Animation.
|
||||
*/
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* @property {array} _frames
|
||||
* @private
|
||||
*/
|
||||
this._frames = [];
|
||||
this._frames = this._frames.concat(frames);
|
||||
|
||||
/**
|
||||
* @property {number} delay - The delay in ms between each frame of the Animation, based on the given frameRate.
|
||||
*/
|
||||
this.delay = 1000 / frameRate;
|
||||
|
||||
/**
|
||||
* @property {boolean} loop - The loop state of the Animation.
|
||||
*/
|
||||
this.loop = loop;
|
||||
|
||||
/**
|
||||
* @property {number} loopCount - The number of times the animation has looped since it was last started.
|
||||
*/
|
||||
this.loopCount = 0;
|
||||
|
||||
/**
|
||||
* @property {boolean} killOnComplete - Should the parent of this Animation be killed when the animation completes?
|
||||
* @default
|
||||
*/
|
||||
this.killOnComplete = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} isFinished - The finished state of the Animation. Set to true once playback completes, false during playback.
|
||||
* @default
|
||||
*/
|
||||
this.isFinished = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} isPlaying - The playing state of the Animation. Set to false once playback completes, true during playback.
|
||||
* @default
|
||||
*/
|
||||
this.isPlaying = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} isPaused - The paused state of the Animation.
|
||||
* @default
|
||||
*/
|
||||
this.isPaused = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} _pauseStartTime - The time the animation paused.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._pauseStartTime = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _frameIndex
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._frameIndex = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _frameDiff
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._frameDiff = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _frameSkip
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._frameSkip = 1;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Frame} currentFrame - The currently displayed frame of the Animation.
|
||||
*/
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Signal} onStart - This event is dispatched when this Animation starts playback.
|
||||
*/
|
||||
this.onStart = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* This event is dispatched when the Animation changes frame.
|
||||
* By default this event is disabled due to its intensive nature. Enable it with: `Animation.enableUpdate = true`.
|
||||
* Note that the event is only dispatched with the current frame. In a low-FPS environment Animations
|
||||
* will automatically frame-skip to try and claw back time, so do not base your code on expecting to
|
||||
* receive a perfectly sequential set of frames from this event.
|
||||
* @property {Phaser.Signal|null} onUpdate
|
||||
* @default
|
||||
*/
|
||||
this.onUpdate = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Signal} onComplete - This event is dispatched when this Animation completes playback. If the animation is set to loop this is never fired, listen for onLoop instead.
|
||||
*/
|
||||
this.onComplete = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Signal} onLoop - This event is dispatched when this Animation loops.
|
||||
*/
|
||||
this.onLoop = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* @property {boolean} isReversed - Indicates if the animation will play backwards.
|
||||
* @default
|
||||
*/
|
||||
this.isReversed = false;
|
||||
|
||||
// Set-up some event listeners
|
||||
this.game.onPause.add(this.onPause, this);
|
||||
this.game.onResume.add(this.onResume, this);
|
||||
|
||||
};
|
||||
|
||||
Phaser.Animation.prototype = {
|
||||
|
||||
/**
|
||||
* Plays this animation.
|
||||
*
|
||||
* @method Phaser.Animation#play
|
||||
* @param {number} [frameRate=null] - The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
|
||||
* @param {boolean} [loop=false] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
|
||||
* @param {boolean} [killOnComplete=false] - If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
|
||||
* @return {Phaser.Animation} - A reference to this Animation instance.
|
||||
*/
|
||||
play: function (frameRate, loop, killOnComplete) {
|
||||
|
||||
if (typeof frameRate === 'number')
|
||||
{
|
||||
// If they set a new frame rate then use it, otherwise use the one set on creation
|
||||
this.delay = 1000 / frameRate;
|
||||
}
|
||||
|
||||
if (typeof loop === 'boolean')
|
||||
{
|
||||
// If they set a new loop value then use it, otherwise use the one set on creation
|
||||
this.loop = loop;
|
||||
}
|
||||
|
||||
if (typeof killOnComplete !== 'undefined')
|
||||
{
|
||||
// Remove the parent sprite once the animation has finished?
|
||||
this.killOnComplete = killOnComplete;
|
||||
}
|
||||
|
||||
this.isPlaying = true;
|
||||
this.isFinished = false;
|
||||
this.paused = false;
|
||||
this.loopCount = 0;
|
||||
|
||||
this._timeLastFrame = this.game.time.time;
|
||||
this._timeNextFrame = this.game.time.time + this.delay;
|
||||
|
||||
this._frameIndex = this.isReversed ? this._frames.length - 1 : 0;
|
||||
this.updateCurrentFrame(false, true);
|
||||
|
||||
this._parent.events.onAnimationStart$dispatch(this._parent, this);
|
||||
|
||||
this.onStart.dispatch(this._parent, this);
|
||||
|
||||
this._parent.animations.currentAnim = this;
|
||||
this._parent.animations.currentFrame = this.currentFrame;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets this animation back to the first frame and restarts the animation.
|
||||
*
|
||||
* @method Phaser.Animation#restart
|
||||
*/
|
||||
restart: function () {
|
||||
|
||||
this.isPlaying = true;
|
||||
this.isFinished = false;
|
||||
this.paused = false;
|
||||
this.loopCount = 0;
|
||||
|
||||
this._timeLastFrame = this.game.time.time;
|
||||
this._timeNextFrame = this.game.time.time + this.delay;
|
||||
|
||||
this._frameIndex = 0;
|
||||
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
|
||||
this._parent.setFrame(this.currentFrame);
|
||||
|
||||
this._parent.animations.currentAnim = this;
|
||||
this._parent.animations.currentFrame = this.currentFrame;
|
||||
|
||||
this.onStart.dispatch(this._parent, this);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Reverses the animation direction.
|
||||
*
|
||||
* @method Phaser.Animation#reverse
|
||||
* @return {Phaser.Animation} The animation instance.
|
||||
*/
|
||||
reverse: function () {
|
||||
|
||||
this.reversed = !this.reversed;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Reverses the animation direction for the current/next animation only
|
||||
* Once the onComplete event is called this method will be called again and revert
|
||||
* the reversed state.
|
||||
*
|
||||
* @method Phaser.Animation#reverseOnce
|
||||
* @return {Phaser.Animation} The animation instance.
|
||||
*/
|
||||
reverseOnce: function () {
|
||||
|
||||
this.onComplete.addOnce(this.reverse, this);
|
||||
|
||||
return this.reverse();
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets this animations playback to a given frame with the given ID.
|
||||
*
|
||||
* @method Phaser.Animation#setFrame
|
||||
* @param {string|number} [frameId] - The identifier of the frame to set. Can be the name of the frame, the sprite index of the frame, or the animation-local frame index.
|
||||
* @param {boolean} [useLocalFrameIndex=false] - If you provide a number for frameId, should it use the numeric indexes of the frameData, or the 0-indexed frame index local to the animation.
|
||||
*/
|
||||
setFrame: function(frameId, useLocalFrameIndex) {
|
||||
|
||||
var frameIndex;
|
||||
|
||||
if (useLocalFrameIndex === undefined)
|
||||
{
|
||||
useLocalFrameIndex = false;
|
||||
}
|
||||
|
||||
// Find the index to the desired frame.
|
||||
if (typeof frameId === "string")
|
||||
{
|
||||
for (var i = 0; i < this._frames.length; i++)
|
||||
{
|
||||
if (this._frameData.getFrame(this._frames[i]).name === frameId)
|
||||
{
|
||||
frameIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof frameId === "number")
|
||||
{
|
||||
if (useLocalFrameIndex)
|
||||
{
|
||||
frameIndex = frameId;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var i = 0; i < this._frames.length; i++)
|
||||
{
|
||||
if (this._frames[i] === frameId)
|
||||
{
|
||||
frameIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (frameIndex)
|
||||
{
|
||||
// Set the current frame index to the found index. Subtract 1 so that it animates to the desired frame on update.
|
||||
this._frameIndex = frameIndex - 1;
|
||||
|
||||
// Make the animation update at next update
|
||||
this._timeNextFrame = this.game.time.time;
|
||||
|
||||
this.update();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Stops playback of this animation and set it to a finished state. If a resetFrame is provided it will stop playback and set frame to the first in the animation.
|
||||
* If `dispatchComplete` is true it will dispatch the complete events, otherwise they'll be ignored.
|
||||
*
|
||||
* @method Phaser.Animation#stop
|
||||
* @param {boolean} [resetFrame=false] - If true after the animation stops the currentFrame value will be set to the first frame in this animation.
|
||||
* @param {boolean} [dispatchComplete=false] - Dispatch the Animation.onComplete and parent.onAnimationComplete events?
|
||||
*/
|
||||
stop: function (resetFrame, dispatchComplete) {
|
||||
|
||||
if (resetFrame === undefined) { resetFrame = false; }
|
||||
if (dispatchComplete === undefined) { dispatchComplete = false; }
|
||||
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
this.paused = false;
|
||||
|
||||
if (resetFrame)
|
||||
{
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[0]);
|
||||
this._parent.setFrame(this.currentFrame);
|
||||
}
|
||||
|
||||
if (dispatchComplete)
|
||||
{
|
||||
this._parent.events.onAnimationComplete$dispatch(this._parent, this);
|
||||
this.onComplete.dispatch(this._parent, this);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when the Game enters a paused state.
|
||||
*
|
||||
* @method Phaser.Animation#onPause
|
||||
*/
|
||||
onPause: function () {
|
||||
|
||||
if (this.isPlaying)
|
||||
{
|
||||
this._frameDiff = this._timeNextFrame - this.game.time.time;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when the Game resumes from a paused state.
|
||||
*
|
||||
* @method Phaser.Animation#onResume
|
||||
*/
|
||||
onResume: function () {
|
||||
|
||||
if (this.isPlaying)
|
||||
{
|
||||
this._timeNextFrame = this.game.time.time + this._frameDiff;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates this animation. Called automatically by the AnimationManager.
|
||||
*
|
||||
* @method Phaser.Animation#update
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
if (this.isPaused)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isPlaying && this.game.time.time >= this._timeNextFrame)
|
||||
{
|
||||
this._frameSkip = 1;
|
||||
|
||||
// Lagging?
|
||||
this._frameDiff = this.game.time.time - this._timeNextFrame;
|
||||
|
||||
this._timeLastFrame = this.game.time.time;
|
||||
|
||||
if (this._frameDiff > this.delay)
|
||||
{
|
||||
// We need to skip a frame, work out how many
|
||||
this._frameSkip = Math.floor(this._frameDiff / this.delay);
|
||||
this._frameDiff -= (this._frameSkip * this.delay);
|
||||
}
|
||||
|
||||
// And what's left now?
|
||||
this._timeNextFrame = this.game.time.time + (this.delay - this._frameDiff);
|
||||
|
||||
if (this.isReversed)
|
||||
{
|
||||
this._frameIndex -= this._frameSkip;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._frameIndex += this._frameSkip;
|
||||
}
|
||||
|
||||
if (!this.isReversed && this._frameIndex >= this._frames.length || this.isReversed && this._frameIndex <= -1)
|
||||
{
|
||||
if (this.loop)
|
||||
{
|
||||
// Update current state before event callback
|
||||
this._frameIndex = Math.abs(this._frameIndex) % this._frames.length;
|
||||
|
||||
if (this.isReversed)
|
||||
{
|
||||
this._frameIndex = this._frames.length - 1 - this._frameIndex;
|
||||
}
|
||||
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
|
||||
// Instead of calling updateCurrentFrame we do it here instead
|
||||
if (this.currentFrame)
|
||||
{
|
||||
this._parent.setFrame(this.currentFrame);
|
||||
}
|
||||
|
||||
this.loopCount++;
|
||||
this._parent.events.onAnimationLoop$dispatch(this._parent, this);
|
||||
this.onLoop.dispatch(this._parent, this);
|
||||
|
||||
if (this.onUpdate)
|
||||
{
|
||||
this.onUpdate.dispatch(this, this.currentFrame);
|
||||
|
||||
// False if the animation was destroyed from within a callback
|
||||
return !!this._frameData;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.complete();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.updateCurrentFrame(true);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Changes the currentFrame per the _frameIndex, updates the display state,
|
||||
* and triggers the update signal.
|
||||
*
|
||||
* Returns true if the current frame update was 'successful', false otherwise.
|
||||
*
|
||||
* @method Phaser.Animation#updateCurrentFrame
|
||||
* @private
|
||||
* @param {boolean} signalUpdate - If true the `Animation.onUpdate` signal will be dispatched.
|
||||
* @param {boolean} fromPlay - Was this call made from the playing of a new animation?
|
||||
* @return {boolean} True if the current frame was updated, otherwise false.
|
||||
*/
|
||||
updateCurrentFrame: function (signalUpdate, fromPlay) {
|
||||
|
||||
if (fromPlay === undefined) { fromPlay = false; }
|
||||
|
||||
if (!this._frameData)
|
||||
{
|
||||
// The animation is already destroyed, probably from a callback
|
||||
return false;
|
||||
}
|
||||
|
||||
// Previous index
|
||||
var idx = this.currentFrame.index;
|
||||
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
|
||||
if (this.currentFrame && (fromPlay || (!fromPlay && idx !== this.currentFrame.index)))
|
||||
{
|
||||
this._parent.setFrame(this.currentFrame);
|
||||
}
|
||||
|
||||
if (this.onUpdate && signalUpdate)
|
||||
{
|
||||
this.onUpdate.dispatch(this, this.currentFrame);
|
||||
|
||||
// False if the animation was destroyed from within a callback
|
||||
return !!this._frameData;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Advances by the given number of frames in the Animation, taking the loop value into consideration.
|
||||
*
|
||||
* @method Phaser.Animation#next
|
||||
* @param {number} [quantity=1] - The number of frames to advance.
|
||||
*/
|
||||
next: function (quantity) {
|
||||
|
||||
if (quantity === undefined) { quantity = 1; }
|
||||
|
||||
var frame = this._frameIndex + quantity;
|
||||
|
||||
if (frame >= this._frames.length)
|
||||
{
|
||||
if (this.loop)
|
||||
{
|
||||
frame %= this._frames.length;
|
||||
}
|
||||
else
|
||||
{
|
||||
frame = this._frames.length - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (frame !== this._frameIndex)
|
||||
{
|
||||
this._frameIndex = frame;
|
||||
this.updateCurrentFrame(true);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Moves backwards the given number of frames in the Animation, taking the loop value into consideration.
|
||||
*
|
||||
* @method Phaser.Animation#previous
|
||||
* @param {number} [quantity=1] - The number of frames to move back.
|
||||
*/
|
||||
previous: function (quantity) {
|
||||
|
||||
if (quantity === undefined) { quantity = 1; }
|
||||
|
||||
var frame = this._frameIndex - quantity;
|
||||
|
||||
if (frame < 0)
|
||||
{
|
||||
if (this.loop)
|
||||
{
|
||||
frame = this._frames.length + frame;
|
||||
}
|
||||
else
|
||||
{
|
||||
frame++;
|
||||
}
|
||||
}
|
||||
|
||||
if (frame !== this._frameIndex)
|
||||
{
|
||||
this._frameIndex = frame;
|
||||
this.updateCurrentFrame(true);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Changes the FrameData object this Animation is using.
|
||||
*
|
||||
* @method Phaser.Animation#updateFrameData
|
||||
* @param {Phaser.FrameData} frameData - The FrameData object that contains all frames used by this Animation.
|
||||
*/
|
||||
updateFrameData: function (frameData) {
|
||||
|
||||
this._frameData = frameData;
|
||||
this.currentFrame = this._frameData ? this._frameData.getFrame(this._frames[this._frameIndex % this._frames.length]) : null;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Cleans up this animation ready for deletion. Nulls all values and references.
|
||||
*
|
||||
* @method Phaser.Animation#destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
|
||||
if (!this._frameData)
|
||||
{
|
||||
// Already destroyed
|
||||
return;
|
||||
}
|
||||
|
||||
this.game.onPause.remove(this.onPause, this);
|
||||
this.game.onResume.remove(this.onResume, this);
|
||||
|
||||
this.game = null;
|
||||
this._parent = null;
|
||||
this._frames = null;
|
||||
this._frameData = null;
|
||||
this.currentFrame = null;
|
||||
this.isPlaying = false;
|
||||
|
||||
this.onStart.dispose();
|
||||
this.onLoop.dispose();
|
||||
this.onComplete.dispose();
|
||||
|
||||
if (this.onUpdate)
|
||||
{
|
||||
this.onUpdate.dispose();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Called internally when the animation finishes playback.
|
||||
* Sets the isPlaying and isFinished states and dispatches the onAnimationComplete event if it exists on the parent and local onComplete event.
|
||||
*
|
||||
* @method Phaser.Animation#complete
|
||||
*/
|
||||
complete: function () {
|
||||
|
||||
this._frameIndex = this._frames.length - 1;
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
this.paused = false;
|
||||
|
||||
this._parent.events.onAnimationComplete$dispatch(this._parent, this);
|
||||
|
||||
this.onComplete.dispatch(this._parent, this);
|
||||
|
||||
if (this.killOnComplete)
|
||||
{
|
||||
this._parent.kill();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.Animation.prototype.constructor = Phaser.Animation;
|
||||
|
||||
/**
|
||||
* @name Phaser.Animation#paused
|
||||
* @property {boolean} paused - Gets and sets the paused state of this Animation.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Animation.prototype, 'paused', {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.isPaused;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.isPaused = value;
|
||||
|
||||
if (value)
|
||||
{
|
||||
// Paused
|
||||
this._pauseStartTime = this.game.time.time;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Un-paused
|
||||
if (this.isPlaying)
|
||||
{
|
||||
this._timeNextFrame = this.game.time.time + this.delay;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.Animation#reversed
|
||||
* @property {boolean} reversed - Gets and sets the isReversed state of this Animation.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Animation.prototype, 'reversed', {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.isReversed;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.isReversed = value;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.Animation#frameTotal
|
||||
* @property {number} frameTotal - The total number of frames in the currently loaded FrameData, or -1 if no FrameData is loaded.
|
||||
* @readonly
|
||||
*/
|
||||
Object.defineProperty(Phaser.Animation.prototype, 'frameTotal', {
|
||||
|
||||
get: function () {
|
||||
return this._frames.length;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.Animation#frame
|
||||
* @property {number} frame - Gets or sets the current frame index and updates the Texture Cache for display.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Animation.prototype, 'frame', {
|
||||
|
||||
get: function () {
|
||||
|
||||
if (this.currentFrame !== null)
|
||||
{
|
||||
return this.currentFrame.index;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this._frameIndex;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[value]);
|
||||
|
||||
if (this.currentFrame !== null)
|
||||
{
|
||||
this._frameIndex = value;
|
||||
this._parent.setFrame(this.currentFrame);
|
||||
|
||||
if (this.onUpdate)
|
||||
{
|
||||
this.onUpdate.dispatch(this, this.currentFrame);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.Animation#speed
|
||||
* @property {number} speed - Gets or sets the current speed of the animation in frames per second. Changing this in a playing animation will take effect from the next frame. Value must be greater than 0.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Animation.prototype, 'speed', {
|
||||
|
||||
get: function () {
|
||||
|
||||
return 1000 / this.delay;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value > 0)
|
||||
{
|
||||
this.delay = 1000 / value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.Animation#enableUpdate
|
||||
* @property {boolean} enableUpdate - Gets or sets if this animation will dispatch the onUpdate events upon changing frame.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Animation.prototype, 'enableUpdate', {
|
||||
|
||||
get: function () {
|
||||
|
||||
return (this.onUpdate !== null);
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value && this.onUpdate === null)
|
||||
{
|
||||
this.onUpdate = new Phaser.Signal();
|
||||
}
|
||||
else if (!value && this.onUpdate !== null)
|
||||
{
|
||||
this.onUpdate.dispose();
|
||||
this.onUpdate = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Really handy function for when you are creating arrays of animation data but it's using frame names and not numbers.
|
||||
* For example imagine you've got 30 frames named: 'explosion_0001-large' to 'explosion_0030-large'
|
||||
* You could use this function to generate those by doing: Phaser.Animation.generateFrameNames('explosion_', 1, 30, '-large', 4);
|
||||
*
|
||||
* @method Phaser.Animation.generateFrameNames
|
||||
* @static
|
||||
* @param {string} prefix - The start of the filename. If the filename was 'explosion_0001-large' the prefix would be 'explosion_'.
|
||||
* @param {number} start - The number to start sequentially counting from. If your frames are named 'explosion_0001' to 'explosion_0034' the start is 1.
|
||||
* @param {number} stop - The number to count to. If your frames are named 'explosion_0001' to 'explosion_0034' the stop value is 34.
|
||||
* @param {string} [suffix=''] - The end of the filename. If the filename was 'explosion_0001-large' the prefix would be '-large'.
|
||||
* @param {number} [zeroPad=0] - The number of zeros to pad the min and max values with. If your frames are named 'explosion_0001' to 'explosion_0034' then the zeroPad is 4.
|
||||
* @return {string[]} An array of framenames.
|
||||
*/
|
||||
Phaser.Animation.generateFrameNames = function (prefix, start, stop, suffix, zeroPad) {
|
||||
|
||||
if (suffix === undefined) { suffix = ''; }
|
||||
|
||||
var output = [];
|
||||
var frame = '';
|
||||
|
||||
if (start < stop)
|
||||
{
|
||||
for (var i = start; i <= stop; i++)
|
||||
{
|
||||
if (typeof zeroPad === 'number')
|
||||
{
|
||||
// str, len, pad, dir
|
||||
frame = Phaser.Utils.pad(i.toString(), zeroPad, '0', 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
frame = i.toString();
|
||||
}
|
||||
|
||||
frame = prefix + frame + suffix;
|
||||
|
||||
output.push(frame);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var i = start; i >= stop; i--)
|
||||
{
|
||||
if (typeof zeroPad === 'number')
|
||||
{
|
||||
// str, len, pad, dir
|
||||
frame = Phaser.Utils.pad(i.toString(), zeroPad, '0', 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
frame = i.toString();
|
||||
}
|
||||
|
||||
frame = prefix + frame + suffix;
|
||||
|
||||
output.push(frame);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
};
|
|
@ -1,565 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Animation Manager is used to add, play and update Phaser Animations.
|
||||
* Any Game Object such as Phaser.Sprite that supports animation contains a single AnimationManager instance.
|
||||
*
|
||||
* @class Phaser.AnimationManager
|
||||
* @constructor
|
||||
* @param {Phaser.Sprite} sprite - A reference to the Game Object that owns this AnimationManager.
|
||||
*/
|
||||
Phaser.AnimationManager = function (sprite) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Sprite} sprite - A reference to the parent Sprite that owns this AnimationManager.
|
||||
*/
|
||||
this.sprite = sprite;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
this.game = sprite.game;
|
||||
|
||||
/**
|
||||
* The currently displayed Frame of animation, if any.
|
||||
* This property is only set once an Animation starts playing. Until that point it remains set as `null`.
|
||||
*
|
||||
* @property {Phaser.Frame} currentFrame
|
||||
* @default
|
||||
*/
|
||||
this.currentFrame = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Animation} currentAnim - The currently displayed animation, if any.
|
||||
* @default
|
||||
*/
|
||||
this.currentAnim = null;
|
||||
|
||||
/**
|
||||
* @property {boolean} updateIfVisible - Should the animation data continue to update even if the Sprite.visible is set to false.
|
||||
* @default
|
||||
*/
|
||||
this.updateIfVisible = true;
|
||||
|
||||
/**
|
||||
* @property {boolean} isLoaded - Set to true once animation data has been loaded.
|
||||
* @default
|
||||
*/
|
||||
this.isLoaded = false;
|
||||
|
||||
/**
|
||||
* @property {Phaser.FrameData} _frameData - A temp. var for holding the currently playing Animations FrameData.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._frameData = null;
|
||||
|
||||
/**
|
||||
* @property {object} _anims - An internal object that stores all of the Animation instances.
|
||||
* @private
|
||||
*/
|
||||
this._anims = {};
|
||||
|
||||
/**
|
||||
* @property {object} _outputFrames - An internal object to help avoid gc.
|
||||
* @private
|
||||
*/
|
||||
this._outputFrames = [];
|
||||
|
||||
};
|
||||
|
||||
Phaser.AnimationManager.prototype = {
|
||||
|
||||
/**
|
||||
* Loads FrameData into the internal temporary vars and resets the frame index to zero.
|
||||
* This is called automatically when a new Sprite is created.
|
||||
*
|
||||
* @method Phaser.AnimationManager#loadFrameData
|
||||
* @private
|
||||
* @param {Phaser.FrameData} frameData - The FrameData set to load.
|
||||
* @param {string|number} frame - The frame to default to.
|
||||
* @return {boolean} Returns `true` if the frame data was loaded successfully, otherwise `false`
|
||||
*/
|
||||
loadFrameData: function (frameData, frame) {
|
||||
|
||||
if (frameData === undefined)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isLoaded)
|
||||
{
|
||||
// We need to update the frameData that the animations are using
|
||||
for (var anim in this._anims)
|
||||
{
|
||||
this._anims[anim].updateFrameData(frameData);
|
||||
}
|
||||
}
|
||||
|
||||
this._frameData = frameData;
|
||||
|
||||
if (frame === undefined || frame === null)
|
||||
{
|
||||
this.frame = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (typeof frame === 'string')
|
||||
{
|
||||
this.frameName = frame;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.frame = frame;
|
||||
}
|
||||
}
|
||||
|
||||
this.isLoaded = true;
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Loads FrameData into the internal temporary vars and resets the frame index to zero.
|
||||
* This is called automatically when a new Sprite is created.
|
||||
*
|
||||
* @method Phaser.AnimationManager#copyFrameData
|
||||
* @private
|
||||
* @param {Phaser.FrameData} frameData - The FrameData set to load.
|
||||
* @param {string|number} frame - The frame to default to.
|
||||
* @return {boolean} Returns `true` if the frame data was loaded successfully, otherwise `false`
|
||||
*/
|
||||
copyFrameData: function (frameData, frame) {
|
||||
|
||||
this._frameData = frameData.clone();
|
||||
|
||||
if (this.isLoaded)
|
||||
{
|
||||
// We need to update the frameData that the animations are using
|
||||
for (var anim in this._anims)
|
||||
{
|
||||
this._anims[anim].updateFrameData(this._frameData);
|
||||
}
|
||||
}
|
||||
|
||||
if (frame === undefined || frame === null)
|
||||
{
|
||||
this.frame = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (typeof frame === 'string')
|
||||
{
|
||||
this.frameName = frame;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.frame = frame;
|
||||
}
|
||||
}
|
||||
|
||||
this.isLoaded = true;
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a new animation under the given key. Optionally set the frames, frame rate and loop.
|
||||
* Animations added in this way are played back with the play function.
|
||||
*
|
||||
* @method Phaser.AnimationManager#add
|
||||
* @param {string} name - The unique (within this Sprite) name for the animation, i.e. "run", "fire", "walk".
|
||||
* @param {Array} [frames=null] - An array of numbers/strings that correspond to the frames to add to this animation and in which order. e.g. [1, 2, 3] or ['run0', 'run1', run2]). If null then all frames will be used.
|
||||
* @param {number} [frameRate=60] - The speed at which the animation should play. The speed is given in frames per second.
|
||||
* @param {boolean} [loop=false] - Whether or not the animation is looped or just plays once.
|
||||
* @param {boolean} [useNumericIndex=true] - Are the given frames using numeric indexes (default) or strings?
|
||||
* @return {Phaser.Animation} The Animation object that was created.
|
||||
*/
|
||||
add: function (name, frames, frameRate, loop, useNumericIndex) {
|
||||
|
||||
frames = frames || [];
|
||||
frameRate = frameRate || 60;
|
||||
|
||||
if (loop === undefined) { loop = false; }
|
||||
|
||||
// If they didn't set the useNumericIndex then let's at least try and guess it
|
||||
if (useNumericIndex === undefined)
|
||||
{
|
||||
if (frames && typeof frames[0] === 'number')
|
||||
{
|
||||
useNumericIndex = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
useNumericIndex = false;
|
||||
}
|
||||
}
|
||||
|
||||
this._outputFrames = [];
|
||||
|
||||
this._frameData.getFrameIndexes(frames, useNumericIndex, this._outputFrames);
|
||||
|
||||
this._anims[name] = new Phaser.Animation(this.game, this.sprite, name, this._frameData, this._outputFrames, frameRate, loop);
|
||||
|
||||
this.currentAnim = this._anims[name];
|
||||
|
||||
if (this.sprite.tilingTexture)
|
||||
{
|
||||
this.sprite.refreshTexture = true;
|
||||
}
|
||||
|
||||
return this._anims[name];
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Check whether the frames in the given array are valid and exist.
|
||||
*
|
||||
* @method Phaser.AnimationManager#validateFrames
|
||||
* @param {Array} frames - An array of frames to be validated.
|
||||
* @param {boolean} [useNumericIndex=true] - Validate the frames based on their numeric index (true) or string index (false)
|
||||
* @return {boolean} True if all given Frames are valid, otherwise false.
|
||||
*/
|
||||
validateFrames: function (frames, useNumericIndex) {
|
||||
|
||||
if (useNumericIndex === undefined) { useNumericIndex = true; }
|
||||
|
||||
for (var i = 0; i < frames.length; i++)
|
||||
{
|
||||
if (useNumericIndex === true)
|
||||
{
|
||||
if (frames[i] > this._frameData.total)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this._frameData.checkFrameName(frames[i]) === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Play an animation based on the given key. The animation should previously have been added via `animations.add`
|
||||
*
|
||||
* If the requested animation is already playing this request will be ignored.
|
||||
* If you need to reset an already running animation do so directly on the Animation object itself.
|
||||
*
|
||||
* @method Phaser.AnimationManager#play
|
||||
* @param {string} name - The name of the animation to be played, e.g. "fire", "walk", "jump".
|
||||
* @param {number} [frameRate=null] - The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
|
||||
* @param {boolean} [loop=false] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
|
||||
* @param {boolean} [killOnComplete=false] - If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
|
||||
* @return {Phaser.Animation} A reference to playing Animation instance.
|
||||
*/
|
||||
play: function (name, frameRate, loop, killOnComplete) {
|
||||
|
||||
if (this._anims[name])
|
||||
{
|
||||
if (this.currentAnim === this._anims[name])
|
||||
{
|
||||
if (this.currentAnim.isPlaying === false)
|
||||
{
|
||||
this.currentAnim.paused = false;
|
||||
return this.currentAnim.play(frameRate, loop, killOnComplete);
|
||||
}
|
||||
|
||||
return this.currentAnim;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.currentAnim && this.currentAnim.isPlaying)
|
||||
{
|
||||
this.currentAnim.stop();
|
||||
}
|
||||
|
||||
this.currentAnim = this._anims[name];
|
||||
this.currentAnim.paused = false;
|
||||
this.currentFrame = this.currentAnim.currentFrame;
|
||||
return this.currentAnim.play(frameRate, loop, killOnComplete);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Stop playback of an animation. If a name is given that specific animation is stopped, otherwise the current animation is stopped.
|
||||
* The currentAnim property of the AnimationManager is automatically set to the animation given.
|
||||
*
|
||||
* @method Phaser.AnimationManager#stop
|
||||
* @param {string} [name=null] - The name of the animation to be stopped, e.g. "fire". If none is given the currently running animation is stopped.
|
||||
* @param {boolean} [resetFrame=false] - When the animation is stopped should the currentFrame be set to the first frame of the animation (true) or paused on the last frame displayed (false)
|
||||
*/
|
||||
stop: function (name, resetFrame) {
|
||||
|
||||
if (resetFrame === undefined) { resetFrame = false; }
|
||||
|
||||
if (this.currentAnim && (typeof name !== 'string' || name === this.currentAnim.name))
|
||||
{
|
||||
this.currentAnim.stop(resetFrame);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The main update function is called by the Sprites update loop. It's responsible for updating animation frames and firing related events.
|
||||
*
|
||||
* @method Phaser.AnimationManager#update
|
||||
* @protected
|
||||
* @return {boolean} True if a new animation frame has been set, otherwise false.
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
if (this.updateIfVisible && !this.sprite.visible)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.currentAnim && this.currentAnim.update())
|
||||
{
|
||||
this.currentFrame = this.currentAnim.currentFrame;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Advances by the given number of frames in the current animation, taking the loop value into consideration.
|
||||
*
|
||||
* @method Phaser.AnimationManager#next
|
||||
* @param {number} [quantity=1] - The number of frames to advance.
|
||||
*/
|
||||
next: function (quantity) {
|
||||
|
||||
if (this.currentAnim)
|
||||
{
|
||||
this.currentAnim.next(quantity);
|
||||
this.currentFrame = this.currentAnim.currentFrame;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Moves backwards the given number of frames in the current animation, taking the loop value into consideration.
|
||||
*
|
||||
* @method Phaser.AnimationManager#previous
|
||||
* @param {number} [quantity=1] - The number of frames to move back.
|
||||
*/
|
||||
previous: function (quantity) {
|
||||
|
||||
if (this.currentAnim)
|
||||
{
|
||||
this.currentAnim.previous(quantity);
|
||||
this.currentFrame = this.currentAnim.currentFrame;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns an animation that was previously added by name.
|
||||
*
|
||||
* @method Phaser.AnimationManager#getAnimation
|
||||
* @param {string} name - The name of the animation to be returned, e.g. "fire".
|
||||
* @return {Phaser.Animation} The Animation instance, if found, otherwise null.
|
||||
*/
|
||||
getAnimation: function (name) {
|
||||
|
||||
if (typeof name === 'string')
|
||||
{
|
||||
if (this._anims[name])
|
||||
{
|
||||
return this._anims[name];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Refreshes the current frame data back to the parent Sprite and also resets the texture data.
|
||||
*
|
||||
* @method Phaser.AnimationManager#refreshFrame
|
||||
*/
|
||||
refreshFrame: function () {
|
||||
|
||||
// TODO
|
||||
// this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Destroys all references this AnimationManager contains.
|
||||
* Iterates through the list of animations stored in this manager and calls destroy on each of them.
|
||||
*
|
||||
* @method Phaser.AnimationManager#destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
|
||||
var anim = null;
|
||||
|
||||
for (var anim in this._anims)
|
||||
{
|
||||
if (this._anims.hasOwnProperty(anim))
|
||||
{
|
||||
this._anims[anim].destroy();
|
||||
}
|
||||
}
|
||||
|
||||
this._anims = {};
|
||||
this._outputFrames = [];
|
||||
this._frameData = null;
|
||||
this.currentAnim = null;
|
||||
this.currentFrame = null;
|
||||
this.sprite = null;
|
||||
this.game = null;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.AnimationManager.prototype.constructor = Phaser.AnimationManager;
|
||||
|
||||
/**
|
||||
* @name Phaser.AnimationManager#frameData
|
||||
* @property {Phaser.FrameData} frameData - The current animations FrameData.
|
||||
* @readonly
|
||||
*/
|
||||
Object.defineProperty(Phaser.AnimationManager.prototype, 'frameData', {
|
||||
|
||||
get: function () {
|
||||
return this._frameData;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.AnimationManager#frameTotal
|
||||
* @property {number} frameTotal - The total number of frames in the currently loaded FrameData, or -1 if no FrameData is loaded.
|
||||
* @readonly
|
||||
*/
|
||||
Object.defineProperty(Phaser.AnimationManager.prototype, 'frameTotal', {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this._frameData.total;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.AnimationManager#paused
|
||||
* @property {boolean} paused - Gets and sets the paused state of the current animation.
|
||||
*/
|
||||
Object.defineProperty(Phaser.AnimationManager.prototype, 'paused', {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.currentAnim.isPaused;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.currentAnim.paused = value;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.AnimationManager#name
|
||||
* @property {string} name - Gets the current animation name, if set.
|
||||
*/
|
||||
Object.defineProperty(Phaser.AnimationManager.prototype, 'name', {
|
||||
|
||||
get: function () {
|
||||
|
||||
if (this.currentAnim)
|
||||
{
|
||||
return this.currentAnim.name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.AnimationManager#frame
|
||||
* @property {number} frame - Gets or sets the current frame index and updates the Texture Cache for display.
|
||||
*/
|
||||
Object.defineProperty(Phaser.AnimationManager.prototype, 'frame', {
|
||||
|
||||
get: function () {
|
||||
|
||||
if (this.currentFrame)
|
||||
{
|
||||
return this.currentFrame.index;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (typeof value === 'number' && this._frameData && this._frameData.getFrame(value) !== null)
|
||||
{
|
||||
this.currentFrame = this._frameData.getFrame(value);
|
||||
|
||||
if (this.currentFrame)
|
||||
{
|
||||
this.sprite.setFrame(this.currentFrame);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.AnimationManager#frameName
|
||||
* @property {string} frameName - Gets or sets the current frame name and updates the Texture Cache for display.
|
||||
*/
|
||||
Object.defineProperty(Phaser.AnimationManager.prototype, 'frameName', {
|
||||
|
||||
get: function () {
|
||||
|
||||
if (this.currentFrame)
|
||||
{
|
||||
return this.currentFrame.name;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (typeof value === 'string' && this._frameData && this._frameData.getFrameByName(value) !== null)
|
||||
{
|
||||
this.currentFrame = this._frameData.getFrameByName(value);
|
||||
|
||||
if (this.currentFrame)
|
||||
{
|
||||
this._frameIndex = this.currentFrame.index;
|
||||
|
||||
this.sprite.setFrame(this.currentFrame);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn('Cannot set frameName: ' + value);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
|
@ -1,354 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Responsible for parsing sprite sheet and JSON data into the internal FrameData format that Phaser uses for animations.
|
||||
*
|
||||
* @class Phaser.AnimationParser
|
||||
* @static
|
||||
*/
|
||||
Phaser.AnimationParser = {
|
||||
|
||||
/**
|
||||
* Parse a Sprite Sheet and extract the animation frame data from it.
|
||||
*
|
||||
* @method Phaser.AnimationParser.spriteSheet
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {string|Image} key - The Game.Cache asset key of the Sprite Sheet image or an actual HTML Image element.
|
||||
* @param {number} frameWidth - The fixed width of each frame of the animation.
|
||||
* @param {number} frameHeight - The fixed height of each frame of the animation.
|
||||
* @param {number} [frameMax=-1] - The total number of animation frames to extract from the Sprite Sheet. The default value of -1 means "extract all frames".
|
||||
* @param {number} [margin=0] - If the frames have been drawn with a margin, specify the amount here.
|
||||
* @param {number} [spacing=0] - If the frames have been drawn with spacing between them, specify the amount here.
|
||||
* @param {number} [skipFrames=0] - Skip a number of frames. Useful when there are multiple sprite sheets in one image.
|
||||
* @return {Phaser.FrameData} A FrameData object containing the parsed frames.
|
||||
*/
|
||||
spriteSheet: function (game, key, frameWidth, frameHeight, frameMax, margin, spacing, skipFrames) {
|
||||
|
||||
var img = key;
|
||||
|
||||
if (typeof key === 'string')
|
||||
{
|
||||
img = game.cache.getImage(key);
|
||||
}
|
||||
|
||||
if (img === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var width = img.width;
|
||||
var height = img.height;
|
||||
|
||||
if (frameWidth <= 0)
|
||||
{
|
||||
frameWidth = Math.floor(-width / Math.min(-1, frameWidth));
|
||||
}
|
||||
|
||||
if (frameHeight <= 0)
|
||||
{
|
||||
frameHeight = Math.floor(-height / Math.min(-1, frameHeight));
|
||||
}
|
||||
|
||||
var row = Math.floor((width - margin) / (frameWidth + spacing));
|
||||
var column = Math.floor((height - margin) / (frameHeight + spacing));
|
||||
var total = row * column;
|
||||
|
||||
if (skipFrames > total || skipFrames < -total)
|
||||
{
|
||||
console.warn(
|
||||
"Phaser.AnimationParser.spriteSheet: skipFrames = " +
|
||||
skipFrames.toString() + " is larger than total sprite number " +
|
||||
total.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
if (skipFrames < 0)
|
||||
{
|
||||
// Allow negative skipframes.
|
||||
skipFrames = total + skipFrames;
|
||||
}
|
||||
|
||||
if (frameMax !== -1)
|
||||
{
|
||||
total = skipFrames + frameMax;
|
||||
}
|
||||
|
||||
// Zero or smaller than frame sizes?
|
||||
if (width === 0 || height === 0 || width < frameWidth || height < frameHeight || total === 0)
|
||||
{
|
||||
console.warn("Phaser.AnimationParser.spriteSheet: '" + key + "'s width/height zero or width/height < given frameWidth/frameHeight");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Let's create some frames then
|
||||
var data = new Phaser.FrameData();
|
||||
var x = margin;
|
||||
var y = margin;
|
||||
|
||||
for (var i = 0; i < total; i++)
|
||||
{
|
||||
data.addFrame(new Phaser.Frame(i, x, y, frameWidth, frameHeight, ''));
|
||||
|
||||
x += frameWidth + spacing;
|
||||
|
||||
if (x + frameWidth > width)
|
||||
{
|
||||
x = margin;
|
||||
y += frameHeight + spacing;
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse the JSON data and extract the animation frame data from it.
|
||||
*
|
||||
* @method Phaser.AnimationParser.JSONData
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {object} json - The JSON data from the Texture Atlas. Must be in Array format.
|
||||
* @return {Phaser.FrameData} A FrameData object containing the parsed frames.
|
||||
*/
|
||||
JSONData: function (game, json) {
|
||||
|
||||
// Malformed?
|
||||
if (!json['frames'])
|
||||
{
|
||||
console.warn("Phaser.AnimationParser.JSONData: Invalid Texture Atlas JSON given, missing 'frames' array");
|
||||
console.log(json);
|
||||
return;
|
||||
}
|
||||
|
||||
// Let's create some frames then
|
||||
var data = new Phaser.FrameData();
|
||||
|
||||
// By this stage frames is a fully parsed array
|
||||
var frames = json['frames'];
|
||||
var newFrame;
|
||||
|
||||
for (var i = 0; i < frames.length; i++)
|
||||
{
|
||||
newFrame = data.addFrame(new Phaser.Frame(
|
||||
i,
|
||||
frames[i].frame.x,
|
||||
frames[i].frame.y,
|
||||
frames[i].frame.w,
|
||||
frames[i].frame.h,
|
||||
frames[i].filename
|
||||
));
|
||||
|
||||
if (frames[i].trimmed)
|
||||
{
|
||||
newFrame.setTrim(
|
||||
frames[i].trimmed,
|
||||
frames[i].sourceSize.w,
|
||||
frames[i].sourceSize.h,
|
||||
frames[i].spriteSourceSize.x,
|
||||
frames[i].spriteSourceSize.y,
|
||||
frames[i].spriteSourceSize.w,
|
||||
frames[i].spriteSourceSize.h
|
||||
);
|
||||
}
|
||||
|
||||
if (frames[i].rotated)
|
||||
{
|
||||
newFrame.rotated = true;
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse the JSON data and extract the animation frame data from it.
|
||||
*
|
||||
* @method Phaser.AnimationParser.JSONDataPyxel
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {object} json - The JSON data from the Texture Atlas. Must be in Pyxel JSON format.
|
||||
* @return {Phaser.FrameData} A FrameData object containing the parsed frames.
|
||||
*/
|
||||
JSONDataPyxel: function (game, json) {
|
||||
|
||||
// Malformed? There are a few keys to check here.
|
||||
var signature = ['layers', 'tilewidth','tileheight','tileswide', 'tileshigh'];
|
||||
|
||||
signature.forEach( function(key) {
|
||||
if (!json[key])
|
||||
{
|
||||
console.warn('Phaser.AnimationParser.JSONDataPyxel: Invalid Pyxel Tilemap JSON given, missing "' + key + '" key.');
|
||||
console.log(json);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
// For this purpose, I only care about parsing tilemaps with a single layer.
|
||||
if (json['layers'].length !== 1)
|
||||
{
|
||||
console.warn('Phaser.AnimationParser.JSONDataPyxel: Too many layers, this parser only supports flat Tilemaps.');
|
||||
console.log(json);
|
||||
return;
|
||||
}
|
||||
|
||||
var data = new Phaser.FrameData();
|
||||
|
||||
var tileheight = json['tileheight'];
|
||||
var tilewidth = json['tilewidth'];
|
||||
|
||||
var frames = json['layers'][0]['tiles'];
|
||||
var newFrame;
|
||||
|
||||
for (var i = 0; i < frames.length; i++)
|
||||
{
|
||||
newFrame = data.addFrame(new Phaser.Frame(
|
||||
i,
|
||||
frames[i].x,
|
||||
frames[i].y,
|
||||
tilewidth,
|
||||
tileheight,
|
||||
"frame_" + i // No names are included in pyxel tilemap data.
|
||||
));
|
||||
|
||||
// No trim data is included.
|
||||
newFrame.setTrim(false);
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse the JSON data and extract the animation frame data from it.
|
||||
*
|
||||
* @method Phaser.AnimationParser.JSONDataHash
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {object} json - The JSON data from the Texture Atlas. Must be in JSON Hash format.
|
||||
* @return {Phaser.FrameData} A FrameData object containing the parsed frames.
|
||||
*/
|
||||
JSONDataHash: function (game, json) {
|
||||
|
||||
// Malformed?
|
||||
if (!json['frames'])
|
||||
{
|
||||
console.warn("Phaser.AnimationParser.JSONDataHash: Invalid Texture Atlas JSON given, missing 'frames' object");
|
||||
console.log(json);
|
||||
return;
|
||||
}
|
||||
|
||||
// Let's create some frames then
|
||||
var data = new Phaser.FrameData();
|
||||
|
||||
// By this stage frames is a fully parsed array
|
||||
var frames = json['frames'];
|
||||
var newFrame;
|
||||
var i = 0;
|
||||
|
||||
for (var key in frames)
|
||||
{
|
||||
newFrame = data.addFrame(new Phaser.Frame(
|
||||
i,
|
||||
frames[key].frame.x,
|
||||
frames[key].frame.y,
|
||||
frames[key].frame.w,
|
||||
frames[key].frame.h,
|
||||
key
|
||||
));
|
||||
|
||||
if (frames[key].trimmed)
|
||||
{
|
||||
newFrame.setTrim(
|
||||
frames[key].trimmed,
|
||||
frames[key].sourceSize.w,
|
||||
frames[key].sourceSize.h,
|
||||
frames[key].spriteSourceSize.x,
|
||||
frames[key].spriteSourceSize.y,
|
||||
frames[key].spriteSourceSize.w,
|
||||
frames[key].spriteSourceSize.h
|
||||
);
|
||||
}
|
||||
|
||||
if (frames[key].rotated)
|
||||
{
|
||||
newFrame.rotated = true;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse the XML data and extract the animation frame data from it.
|
||||
*
|
||||
* @method Phaser.AnimationParser.XMLData
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {object} xml - The XML data from the Texture Atlas. Must be in Starling XML format.
|
||||
* @return {Phaser.FrameData} A FrameData object containing the parsed frames.
|
||||
*/
|
||||
XMLData: function (game, xml) {
|
||||
|
||||
// Malformed?
|
||||
if (!xml.getElementsByTagName('TextureAtlas'))
|
||||
{
|
||||
console.warn("Phaser.AnimationParser.XMLData: Invalid Texture Atlas XML given, missing <TextureAtlas> tag");
|
||||
return;
|
||||
}
|
||||
|
||||
// Let's create some frames then
|
||||
var data = new Phaser.FrameData();
|
||||
var frames = xml.getElementsByTagName('SubTexture');
|
||||
var newFrame;
|
||||
|
||||
var name;
|
||||
var frame;
|
||||
var x;
|
||||
var y;
|
||||
var width;
|
||||
var height;
|
||||
var frameX;
|
||||
var frameY;
|
||||
var frameWidth;
|
||||
var frameHeight;
|
||||
|
||||
for (var i = 0; i < frames.length; i++)
|
||||
{
|
||||
frame = frames[i].attributes;
|
||||
|
||||
name = frame.name.value;
|
||||
x = parseInt(frame.x.value, 10);
|
||||
y = parseInt(frame.y.value, 10);
|
||||
width = parseInt(frame.width.value, 10);
|
||||
height = parseInt(frame.height.value, 10);
|
||||
|
||||
frameX = null;
|
||||
frameY = null;
|
||||
|
||||
if (frame.frameX)
|
||||
{
|
||||
frameX = Math.abs(parseInt(frame.frameX.value, 10));
|
||||
frameY = Math.abs(parseInt(frame.frameY.value, 10));
|
||||
frameWidth = parseInt(frame.frameWidth.value, 10);
|
||||
frameHeight = parseInt(frame.frameHeight.value, 10);
|
||||
}
|
||||
|
||||
newFrame = data.addFrame(new Phaser.Frame(i, x, y, width, height, name));
|
||||
|
||||
// Trimmed?
|
||||
if (frameX !== null || frameY !== null)
|
||||
{
|
||||
newFrame.setTrim(true, width, height, frameX, frameY, frameWidth, frameHeight);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,224 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Frame is a single frame of an animation and is part of a FrameData collection.
|
||||
*
|
||||
* @class Phaser.Frame
|
||||
* @constructor
|
||||
* @param {number} index - The index of this Frame within the FrameData set it is being added to.
|
||||
* @param {number} x - X position of the frame within the texture image.
|
||||
* @param {number} y - Y position of the frame within the texture image.
|
||||
* @param {number} width - Width of the frame within the texture image.
|
||||
* @param {number} height - Height of the frame within the texture image.
|
||||
* @param {string} name - The name of the frame. In Texture Atlas data this is usually set to the filename.
|
||||
*/
|
||||
Phaser.Frame = function (index, x, y, width, height, name) {
|
||||
|
||||
/**
|
||||
* @property {number} index - The index of this Frame within the FrameData set it is being added to.
|
||||
*/
|
||||
this.index = index;
|
||||
|
||||
/**
|
||||
* @property {number} x - X position within the image to cut from.
|
||||
*/
|
||||
this.x = x;
|
||||
|
||||
/**
|
||||
* @property {number} y - Y position within the image to cut from.
|
||||
*/
|
||||
this.y = y;
|
||||
|
||||
/**
|
||||
* @property {number} width - Width of the frame.
|
||||
*/
|
||||
this.width = width;
|
||||
|
||||
/**
|
||||
* @property {number} height - Height of the frame.
|
||||
*/
|
||||
this.height = height;
|
||||
|
||||
/**
|
||||
* @property {string} name - Useful for Texture Atlas files (is set to the filename value).
|
||||
*/
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* @property {number} centerX - Center X position within the image to cut from.
|
||||
*/
|
||||
this.centerX = Math.floor(width / 2);
|
||||
|
||||
/**
|
||||
* @property {number} centerY - Center Y position within the image to cut from.
|
||||
*/
|
||||
this.centerY = Math.floor(height / 2);
|
||||
|
||||
/**
|
||||
* @property {number} distance - The distance from the top left to the bottom-right of this Frame.
|
||||
*/
|
||||
this.distance = Phaser.Math.distance(0, 0, width, height);
|
||||
|
||||
/**
|
||||
* @property {boolean} rotated - Is the frame rotated in the source texture?
|
||||
* @default
|
||||
*/
|
||||
this.rotated = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} trimmed - Was it trimmed when packed?
|
||||
* @default
|
||||
*/
|
||||
this.trimmed = false;
|
||||
|
||||
/**
|
||||
* @property {number} sourceSizeW - Width of the original sprite before it was trimmed.
|
||||
*/
|
||||
this.sourceSizeW = width;
|
||||
|
||||
/**
|
||||
* @property {number} sourceSizeH - Height of the original sprite before it was trimmed.
|
||||
*/
|
||||
this.sourceSizeH = height;
|
||||
|
||||
/**
|
||||
* @property {number} spriteSourceSizeX - X position of the trimmed sprite inside original sprite.
|
||||
* @default
|
||||
*/
|
||||
this.spriteSourceSizeX = 0;
|
||||
|
||||
/**
|
||||
* @property {number} spriteSourceSizeY - Y position of the trimmed sprite inside original sprite.
|
||||
* @default
|
||||
*/
|
||||
this.spriteSourceSizeY = 0;
|
||||
|
||||
/**
|
||||
* @property {number} spriteSourceSizeW - Width of the trimmed sprite.
|
||||
* @default
|
||||
*/
|
||||
this.spriteSourceSizeW = 0;
|
||||
|
||||
/**
|
||||
* @property {number} spriteSourceSizeH - Height of the trimmed sprite.
|
||||
* @default
|
||||
*/
|
||||
this.spriteSourceSizeH = 0;
|
||||
|
||||
/**
|
||||
* @property {number} right - The right of the Frame (x + width).
|
||||
*/
|
||||
this.right = this.x + this.width;
|
||||
|
||||
/**
|
||||
* @property {number} bottom - The bottom of the frame (y + height).
|
||||
*/
|
||||
this.bottom = this.y + this.height;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Frame.prototype = {
|
||||
|
||||
/**
|
||||
* Adjusts of all the Frame properties based on the given width and height values.
|
||||
*
|
||||
* @method Phaser.Frame#resize
|
||||
* @param {integer} width - The new width of the Frame.
|
||||
* @param {integer} height - The new height of the Frame.
|
||||
*/
|
||||
resize: function (width, height) {
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.centerX = Math.floor(width / 2);
|
||||
this.centerY = Math.floor(height / 2);
|
||||
this.distance = Phaser.Math.distance(0, 0, width, height);
|
||||
this.sourceSizeW = width;
|
||||
this.sourceSizeH = height;
|
||||
this.right = this.x + width;
|
||||
this.bottom = this.y + height;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* If the frame was trimmed when added to the Texture Atlas this records the trim and source data.
|
||||
*
|
||||
* @method Phaser.Frame#setTrim
|
||||
* @param {boolean} trimmed - If this frame was trimmed or not.
|
||||
* @param {number} actualWidth - The width of the frame before being trimmed.
|
||||
* @param {number} actualHeight - The height of the frame before being trimmed.
|
||||
* @param {number} destX - The destination X position of the trimmed frame for display.
|
||||
* @param {number} destY - The destination Y position of the trimmed frame for display.
|
||||
* @param {number} destWidth - The destination width of the trimmed frame for display.
|
||||
* @param {number} destHeight - The destination height of the trimmed frame for display.
|
||||
*/
|
||||
setTrim: function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) {
|
||||
|
||||
this.trimmed = trimmed;
|
||||
|
||||
if (trimmed)
|
||||
{
|
||||
this.sourceSizeW = actualWidth;
|
||||
this.sourceSizeH = actualHeight;
|
||||
this.centerX = Math.floor(actualWidth / 2);
|
||||
this.centerY = Math.floor(actualHeight / 2);
|
||||
this.spriteSourceSizeX = destX;
|
||||
this.spriteSourceSizeY = destY;
|
||||
this.spriteSourceSizeW = destWidth;
|
||||
this.spriteSourceSizeH = destHeight;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Clones this Frame into a new Phaser.Frame object and returns it.
|
||||
* Note that all properties are cloned, including the name and index.
|
||||
*
|
||||
* @method Phaser.Frame#clone
|
||||
* @return {Phaser.Frame} An exact copy of this Frame object.
|
||||
*/
|
||||
clone: function () {
|
||||
|
||||
var output = new Phaser.Frame(this.index, this.x, this.y, this.width, this.height, this.name);
|
||||
|
||||
for (var prop in this)
|
||||
{
|
||||
if (this.hasOwnProperty(prop))
|
||||
{
|
||||
output[prop] = this[prop];
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a Rectangle set to the dimensions of this Frame.
|
||||
*
|
||||
* @method Phaser.Frame#getRect
|
||||
* @param {Phaser.Rectangle} [out] - A rectangle to copy the frame dimensions to.
|
||||
* @return {Phaser.Rectangle} A rectangle.
|
||||
*/
|
||||
getRect: function (out) {
|
||||
|
||||
if (out === undefined)
|
||||
{
|
||||
out = new Phaser.Rectangle(this.x, this.y, this.width, this.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
out.setTo(this.x, this.y, this.width, this.height);
|
||||
}
|
||||
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.Frame.prototype.constructor = Phaser.Frame;
|
|
@ -1,278 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* FrameData is a container for Frame objects, which are the internal representation of animation data in Phaser.
|
||||
*
|
||||
* @class Phaser.FrameData
|
||||
* @constructor
|
||||
*/
|
||||
Phaser.FrameData = function () {
|
||||
|
||||
/**
|
||||
* @property {Array} _frames - Local array of frames.
|
||||
* @private
|
||||
*/
|
||||
this._frames = [];
|
||||
|
||||
/**
|
||||
* @property {Array} _frameNames - Local array of frame names for name to index conversions.
|
||||
* @private
|
||||
*/
|
||||
this._frameNames = [];
|
||||
|
||||
};
|
||||
|
||||
Phaser.FrameData.prototype = {
|
||||
|
||||
/**
|
||||
* Adds a new Frame to this FrameData collection. Typically called by the Animation.Parser and not directly.
|
||||
*
|
||||
* @method Phaser.FrameData#addFrame
|
||||
* @param {Phaser.Frame} frame - The frame to add to this FrameData set.
|
||||
* @return {Phaser.Frame} The frame that was just added.
|
||||
*/
|
||||
addFrame: function (frame) {
|
||||
|
||||
frame.index = this._frames.length;
|
||||
|
||||
this._frames.push(frame);
|
||||
|
||||
if (frame.name !== '')
|
||||
{
|
||||
this._frameNames[frame.name] = frame.index;
|
||||
}
|
||||
|
||||
return frame;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a Frame by its numerical index.
|
||||
*
|
||||
* @method Phaser.FrameData#getFrame
|
||||
* @param {number} index - The index of the frame you want to get.
|
||||
* @return {Phaser.Frame} The frame, if found.
|
||||
*/
|
||||
getFrame: function (index) {
|
||||
|
||||
if (index >= this._frames.length)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
|
||||
return this._frames[index];
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a Frame by its frame name.
|
||||
*
|
||||
* @method Phaser.FrameData#getFrameByName
|
||||
* @param {string} name - The name of the frame you want to get.
|
||||
* @return {Phaser.Frame} The frame, if found.
|
||||
*/
|
||||
getFrameByName: function (name) {
|
||||
|
||||
if (typeof this._frameNames[name] === 'number')
|
||||
{
|
||||
return this._frames[this._frameNames[name]];
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if there is a Frame with the given name.
|
||||
*
|
||||
* @method Phaser.FrameData#checkFrameName
|
||||
* @param {string} name - The name of the frame you want to check.
|
||||
* @return {boolean} True if the frame is found, otherwise false.
|
||||
*/
|
||||
checkFrameName: function (name) {
|
||||
|
||||
if (this._frameNames[name] == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Makes a copy of this FrameData including copies (not references) to all of the Frames it contains.
|
||||
*
|
||||
* @method Phaser.FrameData#clone
|
||||
* @return {Phaser.FrameData} A clone of this object, including clones of the Frame objects it contains.
|
||||
*/
|
||||
clone: function () {
|
||||
|
||||
var output = new Phaser.FrameData();
|
||||
|
||||
// No input array, so we loop through all frames
|
||||
for (var i = 0; i < this._frames.length; i++)
|
||||
{
|
||||
output._frames.push(this._frames[i].clone());
|
||||
}
|
||||
|
||||
for (var p in this._frameNames)
|
||||
{
|
||||
if (this._frameNames.hasOwnProperty(p))
|
||||
{
|
||||
output._frameNames.push(this._frameNames[p]);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a range of frames based on the given start and end frame indexes and returns them in an Array.
|
||||
*
|
||||
* @method Phaser.FrameData#getFrameRange
|
||||
* @param {number} start - The starting frame index.
|
||||
* @param {number} end - The ending frame index.
|
||||
* @param {Array} [output] - If given the results will be appended to the end of this array otherwise a new array will be created.
|
||||
* @return {Array} An array of Frames between the start and end index values, or an empty array if none were found.
|
||||
*/
|
||||
getFrameRange: function (start, end, output) {
|
||||
|
||||
if (output === undefined) { output = []; }
|
||||
|
||||
for (var i = start; i <= end; i++)
|
||||
{
|
||||
output.push(this._frames[i]);
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns all of the Frames in this FrameData set where the frame index is found in the input array.
|
||||
* The frames are returned in the output array, or if none is provided in a new Array object.
|
||||
*
|
||||
* @method Phaser.FrameData#getFrames
|
||||
* @param {Array} [frames] - An Array containing the indexes of the frames to retrieve. If the array is empty or undefined then all frames in the FrameData are returned.
|
||||
* @param {boolean} [useNumericIndex=true] - Are the given frames using numeric indexes (default) or strings? (false)
|
||||
* @param {Array} [output] - If given the results will be appended to the end of this array otherwise a new array will be created.
|
||||
* @return {Array} An array of all Frames in this FrameData set matching the given names or IDs.
|
||||
*/
|
||||
getFrames: function (frames, useNumericIndex, output) {
|
||||
|
||||
if (useNumericIndex === undefined) { useNumericIndex = true; }
|
||||
if (output === undefined) { output = []; }
|
||||
|
||||
if (frames === undefined || frames.length === 0)
|
||||
{
|
||||
// No input array, so we loop through all frames
|
||||
for (var i = 0; i < this._frames.length; i++)
|
||||
{
|
||||
// We only need the indexes
|
||||
output.push(this._frames[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Input array given, loop through that instead
|
||||
for (var i = 0; i < frames.length; i++)
|
||||
{
|
||||
// Does the input array contain names or indexes?
|
||||
if (useNumericIndex)
|
||||
{
|
||||
// The actual frame
|
||||
output.push(this.getFrame(frames[i]));
|
||||
}
|
||||
else
|
||||
{
|
||||
// The actual frame
|
||||
output.push(this.getFrameByName(frames[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns all of the Frame indexes in this FrameData set.
|
||||
* The frames indexes are returned in the output array, or if none is provided in a new Array object.
|
||||
*
|
||||
* @method Phaser.FrameData#getFrameIndexes
|
||||
* @param {Array} [frames] - An Array containing the indexes of the frames to retrieve. If undefined or the array is empty then all frames in the FrameData are returned.
|
||||
* @param {boolean} [useNumericIndex=true] - Are the given frames using numeric indexes (default) or strings? (false)
|
||||
* @param {Array} [output] - If given the results will be appended to the end of this array otherwise a new array will be created.
|
||||
* @return {Array} An array of all Frame indexes matching the given names or IDs.
|
||||
*/
|
||||
getFrameIndexes: function (frames, useNumericIndex, output) {
|
||||
|
||||
if (useNumericIndex === undefined) { useNumericIndex = true; }
|
||||
if (output === undefined) { output = []; }
|
||||
|
||||
if (frames === undefined || frames.length === 0)
|
||||
{
|
||||
// No frames array, so we loop through all frames
|
||||
for (var i = 0; i < this._frames.length; i++)
|
||||
{
|
||||
output.push(this._frames[i].index);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Input array given, loop through that instead
|
||||
for (var i = 0; i < frames.length; i++)
|
||||
{
|
||||
// Does the frames array contain names or indexes?
|
||||
if (useNumericIndex && this._frames[frames[i]])
|
||||
{
|
||||
output.push(this._frames[frames[i]].index);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.getFrameByName(frames[i]))
|
||||
{
|
||||
output.push(this.getFrameByName(frames[i]).index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Destroys this FrameData collection by nulling the _frames and _frameNames arrays.
|
||||
*
|
||||
* @method Phaser.FrameData#destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
|
||||
this._frames = null;
|
||||
this._frameNames = null;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.FrameData.prototype.constructor = Phaser.FrameData;
|
||||
|
||||
/**
|
||||
* @name Phaser.FrameData#total
|
||||
* @property {number} total - The total number of frames in this FrameData set.
|
||||
* @readonly
|
||||
*/
|
||||
Object.defineProperty(Phaser.FrameData.prototype, "total", {
|
||||
|
||||
get: function () {
|
||||
return this._frames.length;
|
||||
}
|
||||
|
||||
});
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,337 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Camera is your view into the game world. It has a position and size and renders only those objects within its field of view.
|
||||
* The game automatically creates a single Stage sized camera on boot. Move the camera around the world with Phaser.Camera.x/y
|
||||
*
|
||||
* @class Phaser.Camera
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - Game reference to the currently running game.
|
||||
* @param {number} id - Not being used at the moment, will be when Phaser supports multiple camera
|
||||
* @param {number} x - Position of the camera on the X axis
|
||||
* @param {number} y - Position of the camera on the Y axis
|
||||
* @param {number} width - The width of the view rectangle
|
||||
* @param {number} height - The height of the view rectangle
|
||||
*/
|
||||
Phaser.Camera = function (state, x, y, viewportWidth, viewportHeight)
|
||||
{
|
||||
/**
|
||||
* The State that this Camera belongs to. A Camera can only belong to one State, and a State only
|
||||
* has one Camera.
|
||||
* @property {Phaser.State} state
|
||||
*/
|
||||
this.state = state;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
this.game = state.game;
|
||||
|
||||
this.viewportWidth = viewportWidth;
|
||||
|
||||
this.viewportHeight = viewportHeight;
|
||||
|
||||
this.transform = new Phaser.Component.Transform(this, x, y);
|
||||
|
||||
/**
|
||||
* The Camera is bound to this Rectangle and cannot move outside of it. By default it is enabled and set to the size of the World.
|
||||
* The Rectangle can be located anywhere in the world and updated as often as you like. If you don't wish the Camera to be bound
|
||||
* at all then set this to null. The values can be anything and are in World coordinates, with 0,0 being the top-left of the world.
|
||||
*
|
||||
* @property {Phaser.Rectangle} bounds - The Rectangle in which the Camera is bounded. Set to null to allow for movement anywhere.
|
||||
*/
|
||||
// this.bounds = new Phaser.Rectangle(x, y, width, height);
|
||||
|
||||
// this.bounds = new Phaser.Circle(x, y)
|
||||
|
||||
/**
|
||||
* @property {boolean} atLimit - Whether this camera is flush with the World Bounds or not.
|
||||
*/
|
||||
this.atLimit = { x: false, y: false };
|
||||
};
|
||||
|
||||
Phaser.Camera.prototype.constructor = Phaser.Camera;
|
||||
|
||||
Phaser.Camera.prototype = {
|
||||
|
||||
/**
|
||||
* Method called to ensure the camera doesn't venture outside of the game world.
|
||||
* Called automatically by Camera.update.
|
||||
*
|
||||
* @method Phaser.Camera#checkBounds
|
||||
* @protected
|
||||
*/
|
||||
checkBounds: function ()
|
||||
{
|
||||
this.atLimit.x = false;
|
||||
this.atLimit.y = false;
|
||||
|
||||
// var vx = this.view.x + this._shake.x;
|
||||
// var vw = this.view.right + this._shake.x;
|
||||
// var vy = this.view.y + this._shake.y;
|
||||
// var vh = this.view.bottom + this._shake.y;
|
||||
|
||||
var vx = this.x;
|
||||
var vw = this.x + this.viewportWidth;
|
||||
var vy = this.y;
|
||||
var vh = this.y + this.viewportHeight;
|
||||
|
||||
// Make sure we didn't go outside the cameras bounds
|
||||
if (vx <= this.bounds.x * this.scale.x)
|
||||
{
|
||||
this.atLimit.x = true;
|
||||
this.view.x = this.bounds.x * this.scale.x;
|
||||
|
||||
if (!this._shake.shakeBounds)
|
||||
{
|
||||
// The camera is up against the bounds, so reset the shake
|
||||
this._shake.x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (vw >= this.bounds.right * this.scale.x)
|
||||
{
|
||||
this.atLimit.x = true;
|
||||
this.view.x = (this.bounds.right * this.scale.x) - this.width;
|
||||
|
||||
if (!this._shake.shakeBounds)
|
||||
{
|
||||
// The camera is up against the bounds, so reset the shake
|
||||
this._shake.x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (vy <= this.bounds.top * this.scale.y)
|
||||
{
|
||||
this.atLimit.y = true;
|
||||
this.view.y = this.bounds.top * this.scale.y;
|
||||
|
||||
if (!this._shake.shakeBounds)
|
||||
{
|
||||
// The camera is up against the bounds, so reset the shake
|
||||
this._shake.y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (vh >= this.bounds.bottom * this.scale.y)
|
||||
{
|
||||
this.atLimit.y = true;
|
||||
this.view.y = (this.bounds.bottom * this.scale.y) - this.height;
|
||||
|
||||
if (!this._shake.shakeBounds)
|
||||
{
|
||||
// The camera is up against the bounds, so reset the shake
|
||||
this._shake.y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperties(Phaser.Camera.prototype, {
|
||||
|
||||
// Transform getters / setters
|
||||
|
||||
x: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._posX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._posX = value;
|
||||
this.transform.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
y: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._posY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._posY = value;
|
||||
this.transform.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
right: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._posX + (this.viewportWidth * this.transform._scaleX);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
bottom: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._posY + (this.viewportHeight * this.transform._scaleY);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
scale: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._scaleX = value;
|
||||
this.transform._scaleY = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
scaleX: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._scaleX = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
scaleY: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._scaleY = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
pivotX: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._pivotX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._pivotX = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
pivotY: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._pivotY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._pivotY = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
angle: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return Phaser.Math.wrapAngle(this.rotation * Phaser.Math.RAD_TO_DEG);
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.rotation = Phaser.Math.wrapAngle(value) * Phaser.Math.DEG_TO_RAD;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
rotation: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._rotation;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
if (this.transform._rotation === value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.transform._rotation = value;
|
||||
this.transform.dirty = true;
|
||||
|
||||
if (this.transform._rotation % Phaser.Math.PI2)
|
||||
{
|
||||
this.transform.cache.sr = Math.sin(this.transform._rotation);
|
||||
this.transform.cache.cr = Math.cos(this.transform._rotation);
|
||||
this.transform.updateCache();
|
||||
this.transform.hasLocalRotation = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.transform.hasLocalRotation = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -1,246 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A BaseTransform class that you can use when extending Game Objects.
|
||||
* Hides away the 'private' stuff and exposes only the useful getters and setters
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.BaseTransform = function (x, y)
|
||||
{
|
||||
this.transform = new Phaser.Component.Transform(this, x, y);
|
||||
};
|
||||
|
||||
Phaser.Component.BaseTransform.prototype.constructor = Phaser.Component.BaseTransform;
|
||||
|
||||
Object.defineProperties(Phaser.Component.BaseTransform.prototype, {
|
||||
|
||||
x: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._posX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._posX = value;
|
||||
this.transform.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
y: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._posY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._posY = value;
|
||||
this.transform.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
scale: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._scaleX = value;
|
||||
this.transform._scaleY = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
scaleX: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._scaleX = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
scaleY: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._scaleY = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
anchor: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._anchorX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._anchorX = value;
|
||||
this.transform._anchorY = value;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
anchorX: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._anchorX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._anchorX = value;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
anchorY: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._anchorY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._anchorY = value;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
pivotX: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._pivotX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._pivotX = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
pivotY: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._pivotY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._pivotY = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
angle: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return Phaser.Math.wrapAngle(this.rotation * Phaser.Math.RAD_TO_DEG);
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.rotation = Phaser.Math.wrapAngle(value) * Phaser.Math.DEG_TO_RAD;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
rotation: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._rotation;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
if (this.transform._rotation === value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.transform._rotation = value;
|
||||
this.transform.dirty = true;
|
||||
|
||||
if (this.transform._rotation % Phaser.Math.PI2)
|
||||
{
|
||||
this.transform.cache.sr = Math.sin(this.transform._rotation);
|
||||
this.transform.cache.cr = Math.cos(this.transform._rotation);
|
||||
this.transform.updateCache();
|
||||
this.transform.hasLocalRotation = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.transform.hasLocalRotation = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -1,729 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Children Component features quick access to Group sorting related methods.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.Children = function (gameObject)
|
||||
{
|
||||
this.gameObject = gameObject;
|
||||
|
||||
// The objects that belong to this collection.
|
||||
// The equivalent of the old `Sprite.children` array.
|
||||
this.list = [];
|
||||
|
||||
this.position = 0;
|
||||
};
|
||||
|
||||
Phaser.Component.Children.prototype.constructor = Phaser.Component.Children;
|
||||
|
||||
Phaser.Component.Children.prototype = {
|
||||
|
||||
add: function (child, skipTransform)
|
||||
{
|
||||
if (skipTransform === undefined) { skipTransform = false; }
|
||||
|
||||
// console.log('--->', this.gameObject.name, 'adds new child:', child.name);
|
||||
|
||||
if (child.parent === this)
|
||||
{
|
||||
// console.log('Children.add 1');
|
||||
return child;
|
||||
}
|
||||
else if (child.parent)
|
||||
{
|
||||
// console.log('Children.add 2');
|
||||
child.parent.children.remove(child);
|
||||
}
|
||||
|
||||
child.parent = this.gameObject;
|
||||
|
||||
this.list.push(child);
|
||||
|
||||
if (!skipTransform && this.gameObject.transform && child.transform)
|
||||
{
|
||||
// console.log(this.gameObject.name, 'adds transform from', child.name);
|
||||
this.gameObject.transform.add(child.transform);
|
||||
}
|
||||
|
||||
// console.log('<--- end');
|
||||
|
||||
return child;
|
||||
},
|
||||
|
||||
addAt: function (child, index, skipTransform)
|
||||
{
|
||||
if (index === undefined) { index = 0; }
|
||||
if (skipTransform === undefined) { skipTransform = false; }
|
||||
|
||||
if (this.list.length === 0)
|
||||
{
|
||||
return this.add(child);
|
||||
}
|
||||
|
||||
if (index >= 0 && index <= this.list.length)
|
||||
{
|
||||
if (child.parent)
|
||||
{
|
||||
child.parent.children.remove(child);
|
||||
}
|
||||
|
||||
child.parent = this;
|
||||
|
||||
this.list.splice(index, 0, child);
|
||||
}
|
||||
|
||||
if (!skipTransform && this.gameObject.transform && child.transform)
|
||||
{
|
||||
this.gameObject.transform.add(child.transform);
|
||||
}
|
||||
|
||||
return child;
|
||||
|
||||
},
|
||||
|
||||
addMultiple: function (children, skipTransform)
|
||||
{
|
||||
if (Array.isArray(children))
|
||||
{
|
||||
for (var i = 0; i < children.length; i++)
|
||||
{
|
||||
this.add(children[i], skipTransform);
|
||||
}
|
||||
}
|
||||
|
||||
return children;
|
||||
},
|
||||
|
||||
getAt: function (index)
|
||||
{
|
||||
return this.list[index];
|
||||
},
|
||||
|
||||
getIndex: function (child)
|
||||
{
|
||||
// Return -1 if given child isn't a child of this parent
|
||||
return this.list.indexOf(child);
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the first item from the set based on the property strictly equaling the value given.
|
||||
* Returns null if not found.
|
||||
*
|
||||
* @method Phaser.ArraySet#getByKey
|
||||
* @param {string} property - The property to check against the value.
|
||||
* @param {any} value - The value to check if the property strictly equals.
|
||||
* @return {any} The item that was found, or null if nothing matched.
|
||||
*/
|
||||
getByKey: function (property, value)
|
||||
{
|
||||
for (var i = 0; i < this.list.length; i++)
|
||||
{
|
||||
if (this.list[i][property] === value)
|
||||
{
|
||||
return this.list[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Searches the Group for the first instance of a child with the `name`
|
||||
* property matching the given argument. Should more than one child have
|
||||
* the same name only the first instance is returned.
|
||||
*
|
||||
* @method Phaser.Group#getByName
|
||||
* @param {string} name - The name to search for.
|
||||
* @return {any} The first child with a matching name, or null if none were found.
|
||||
*/
|
||||
getByName: function (name)
|
||||
{
|
||||
return this.getByKey('name', name);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a random child from the group.
|
||||
*
|
||||
* @method Phaser.Group#getRandom
|
||||
* @param {integer} [startIndex=0] - Offset from the front of the group (lowest child).
|
||||
* @param {integer} [length=(to top)] - Restriction on the number of values you want to randomly select from.
|
||||
* @return {any} A random child of this Group.
|
||||
*/
|
||||
getRandom: function (startIndex, length)
|
||||
{
|
||||
if (startIndex === undefined) { startIndex = 0; }
|
||||
if (length === undefined) { length = this.list.length; }
|
||||
|
||||
if (length === 0 || length > this.list.length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var randomIndex = startIndex + Math.floor(Math.random() * length);
|
||||
|
||||
return this.list[randomIndex];
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns all children in this Group.
|
||||
*
|
||||
* You can optionally specify a matching criteria using the `property` and `value` arguments.
|
||||
*
|
||||
* For example: `getAll('exists', true)` would return only children that have their exists property set.
|
||||
*
|
||||
* Optionally you can specify a start and end index. For example if this Group had 100 children,
|
||||
* and you set `startIndex` to 0 and `endIndex` to 50, it would return matches from only
|
||||
* the first 50 children in the Group.
|
||||
*
|
||||
* @method Phaser.Group#getAll
|
||||
* @param {string} [property] - An optional property to test against the value argument.
|
||||
* @param {any} [value] - If property is set then Child.property must strictly equal this value to be included in the results.
|
||||
* @param {integer} [startIndex=0] - The first child index to start the search from.
|
||||
* @param {integer} [endIndex] - The last child index to search up until.
|
||||
* @return {any} A random existing child of this Group.
|
||||
*/
|
||||
getAll: function (property, value, startIndex, endIndex)
|
||||
{
|
||||
if (startIndex === undefined) { startIndex = 0; }
|
||||
if (endIndex === undefined) { endIndex = this.list.length; }
|
||||
|
||||
var output = [];
|
||||
|
||||
for (var i = startIndex; i < endIndex; i++)
|
||||
{
|
||||
var child = this.list[i];
|
||||
|
||||
if (property)
|
||||
{
|
||||
if (child[property] === value)
|
||||
{
|
||||
output.push(child);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
output.push(child);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
},
|
||||
|
||||
swap: function (child1, child2)
|
||||
{
|
||||
if (child1 === child2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var index1 = this.getIndex(child1);
|
||||
var index2 = this.getIndex(child2);
|
||||
|
||||
if (index1 < 0 || index2 < 0)
|
||||
{
|
||||
throw new Error('Children.swap: Supplied objects must be children of the same parent');
|
||||
}
|
||||
|
||||
this.list[index1] = child2;
|
||||
this.list[index2] = child1;
|
||||
},
|
||||
|
||||
// was setIndex
|
||||
moveTo: function (child, index)
|
||||
{
|
||||
var currentIndex = this.getIndex(child);
|
||||
|
||||
if (currentIndex === -1 || index < 0 || index >= this.list.length)
|
||||
{
|
||||
throw new Error('Children.moveTo: The supplied index is out of bounds');
|
||||
}
|
||||
|
||||
// Remove
|
||||
this.list.splice(currentIndex, 1);
|
||||
|
||||
// Add in new location
|
||||
this.list.splice(index, 0, child);
|
||||
|
||||
return child;
|
||||
},
|
||||
|
||||
remove: function (child, skipTransform)
|
||||
{
|
||||
var index = this.list.indexOf(child);
|
||||
|
||||
if (index !== -1)
|
||||
{
|
||||
child.parent = undefined;
|
||||
|
||||
this.list.splice(index, 1);
|
||||
|
||||
if (!skipTransform && this.gameObject.transform && child.transform)
|
||||
{
|
||||
this.gameObject.transform.remove(child.transform);
|
||||
}
|
||||
}
|
||||
|
||||
return child;
|
||||
},
|
||||
|
||||
removeAt: function (index, skipTransform)
|
||||
{
|
||||
var child = this.list[index];
|
||||
|
||||
if (child)
|
||||
{
|
||||
child.parent = undefined;
|
||||
|
||||
this.children.splice(index, 1);
|
||||
|
||||
if (!skipTransform && this.gameObject.transform && child.transform)
|
||||
{
|
||||
this.gameObject.transform.remove(child.transform);
|
||||
}
|
||||
}
|
||||
|
||||
return child;
|
||||
},
|
||||
|
||||
removeBetween: function (beginIndex, endIndex)
|
||||
{
|
||||
if (beginIndex === undefined) { beginIndex = 0; }
|
||||
if (endIndex === undefined) { endIndex = this.list.length; }
|
||||
|
||||
var range = endIndex - beginIndex;
|
||||
|
||||
if (range > 0 && range <= endIndex)
|
||||
{
|
||||
var removed = this.list.splice(beginIndex, range);
|
||||
|
||||
for (var i = 0; i < removed.length; i++)
|
||||
{
|
||||
removed[i].parent = undefined;
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
else if (range === 0 && this.list.length === 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Error('Children.removeBetween: Range Error, numeric values are outside the acceptable range');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes all the items.
|
||||
*
|
||||
* @method Phaser.ArraySet#removeAll
|
||||
*/
|
||||
removeAll: function ()
|
||||
{
|
||||
var i = this.list.length;
|
||||
|
||||
while (i--)
|
||||
{
|
||||
this.remove(this.list[i]);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
// Check to see if the given child is a child of this object, at any depth (recursively scans up the tree)
|
||||
contains: function (child)
|
||||
{
|
||||
if (!child)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (child.parent === this)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.contains(child.parent);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Brings the given child to the top of this group so it renders above all other children.
|
||||
*
|
||||
* @method Phaser.Group#bringToTop
|
||||
* @param {any} child - The child to bring to the top of this group.
|
||||
* @return {any} The child that was moved.
|
||||
*/
|
||||
bringToTop: function (child)
|
||||
{
|
||||
if (child.parent === this && this.getIndex(child) < this.list.length)
|
||||
{
|
||||
this.remove(child);
|
||||
this.add(child);
|
||||
}
|
||||
|
||||
return child;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sends the given child to the bottom of this group so it renders below all other children.
|
||||
*
|
||||
* @method Phaser.Group#sendToBack
|
||||
* @param {any} child - The child to send to the bottom of this group.
|
||||
* @return {any} The child that was moved.
|
||||
*/
|
||||
sendToBack: function (child)
|
||||
{
|
||||
if (child.parent === this && this.getIndex(child) > 0)
|
||||
{
|
||||
this.remove(child);
|
||||
this.addAt(child, 0);
|
||||
}
|
||||
|
||||
return child;
|
||||
},
|
||||
|
||||
/**
|
||||
* Moves the given child up one place in this group unless it's already at the top.
|
||||
*
|
||||
* @method Phaser.Group#moveUp
|
||||
* @param {any} child - The child to move up in the group.
|
||||
* @return {any} The child that was moved.
|
||||
*/
|
||||
moveUp: function (child)
|
||||
{
|
||||
var a = this.getIndex(child);
|
||||
|
||||
if (a !== -1 && a < this.list.length - 1)
|
||||
{
|
||||
var b = this.getAt(a + 1);
|
||||
|
||||
if (b)
|
||||
{
|
||||
this.swap(child, b);
|
||||
}
|
||||
}
|
||||
|
||||
return child;
|
||||
},
|
||||
|
||||
/**
|
||||
* Moves the given child down one place in this group unless it's already at the bottom.
|
||||
*
|
||||
* @method Phaser.Group#moveDown
|
||||
* @param {any} child - The child to move down in the group.
|
||||
* @return {any} The child that was moved.
|
||||
*/
|
||||
moveDown: function (child)
|
||||
{
|
||||
var a = this.getIndex(child);
|
||||
|
||||
if (a > 0)
|
||||
{
|
||||
var b = this.getAt(a - 1);
|
||||
|
||||
if (b)
|
||||
{
|
||||
this.swap(child, b);
|
||||
}
|
||||
}
|
||||
|
||||
return child;
|
||||
},
|
||||
|
||||
/**
|
||||
* Reverses all children in this group.
|
||||
*
|
||||
* This operation applies only to immediate children and does not propagate to subgroups.
|
||||
*
|
||||
* @method Phaser.Group#reverse
|
||||
*/
|
||||
reverse: function ()
|
||||
{
|
||||
this.list.reverse();
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
shuffle: function ()
|
||||
{
|
||||
for (var i = this.list.length - 1; i > 0; i--)
|
||||
{
|
||||
var j = Math.floor(Math.random() * (i + 1));
|
||||
var temp = this.list[i];
|
||||
this.list[i] = this.list[j];
|
||||
this.list[j] = temp;
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Replaces a child of this Group with the given newChild. The newChild cannot be a member of this Group.
|
||||
*
|
||||
* If `Group.enableBody` is set, then a physics body will be created on the object, so long as one does not already exist.
|
||||
*
|
||||
* If `Group.inputEnableChildren` is set, then an Input Handler will be created on the object, so long as one does not already exist.
|
||||
*
|
||||
* @method Phaser.Group#replace
|
||||
* @param {any} oldChild - The child in this group that will be replaced.
|
||||
* @param {any} newChild - The child to be inserted into this group.
|
||||
* @return {any} Returns the oldChild that was replaced within this group.
|
||||
*/
|
||||
replace: function (oldChild, newChild, skipTransform)
|
||||
{
|
||||
var index = this.getIndex(oldChild);
|
||||
|
||||
if (index !== -1)
|
||||
{
|
||||
if (newChild.parent)
|
||||
{
|
||||
newChild.parent.remove(newChild, skipTransform);
|
||||
}
|
||||
|
||||
this.remove(oldChild, skipTransform);
|
||||
|
||||
this.addAt(newChild, index, skipTransform);
|
||||
|
||||
return oldChild;
|
||||
}
|
||||
},
|
||||
|
||||
// Swaps a child from another parent, with one from this parent.
|
||||
// child1 = the child of THIS parent
|
||||
// child2 = the child of the OTHER parent
|
||||
exchange: function (child1, child2, skipTransform)
|
||||
{
|
||||
if (child1 === child2 || child1.parent === child2.parent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var parentChildren = child2.parent.children;
|
||||
|
||||
var index1 = this.getIndex(child1);
|
||||
var index2 = parentChildren.getIndex(child2);
|
||||
|
||||
if (index1 < 0 || index2 < 0)
|
||||
{
|
||||
throw new Error('Children.swap: Supplied objects must be children of parents');
|
||||
}
|
||||
|
||||
this.remove(child1, skipTransform);
|
||||
|
||||
parentChildren.remove(child2, skipTransform);
|
||||
|
||||
this.addAt(child2, index1, skipTransform);
|
||||
|
||||
parentChildren.addAt(child1, index2, skipTransform);
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks for the item within this list.
|
||||
*
|
||||
* @method Phaser.ArraySet#exists
|
||||
* @param {any} item - The element to get the list index for.
|
||||
* @return {boolean} True if the item is found in the list, otherwise false.
|
||||
*/
|
||||
exists: function (child)
|
||||
{
|
||||
return (this.list.indexOf(child) > -1);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the property `key` to the given value on all members of this list.
|
||||
*
|
||||
* @method Phaser.ArraySet#setAll
|
||||
* @param {any} key - The property of the item to set.
|
||||
* @param {any} value - The value to set the property to.
|
||||
*/
|
||||
setAll: function (key, value)
|
||||
{
|
||||
for (var i = 0; i < this.list.length; i++)
|
||||
{
|
||||
if (this.list[i])
|
||||
{
|
||||
this.list[i][key] = value;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Passes all children to the given callback.
|
||||
*
|
||||
* @method each
|
||||
* @param {function} callback - The function to call.
|
||||
* @param {object} [thisArg] - Value to use as `this` when executing callback.
|
||||
* @param {...*} [arguments] - Additional arguments that will be passed to the callback, after the child.
|
||||
*/
|
||||
each: function (callback, thisArg)
|
||||
{
|
||||
var args = [ null ];
|
||||
|
||||
for (var i = 1; i < arguments.length; i++)
|
||||
{
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < this.list.length; i++)
|
||||
{
|
||||
args[0] = this.list[i];
|
||||
callback.apply(thisArg, args);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Moves all children from this Group to the Group given.
|
||||
*
|
||||
* @method Phaser.Group#moveAll
|
||||
* @param {Phaser.Group} group - The new Group to which the children will be moved to.
|
||||
* @param {boolean} [silent=false] - If true the children will not dispatch the `onAddedToGroup` event for the new Group.
|
||||
* @return {Phaser.Group} The Group to which all the children were moved.
|
||||
*/
|
||||
reparent: function (newParent)
|
||||
{
|
||||
if (newParent !== this)
|
||||
{
|
||||
for (var i = 0; i < this.list.length; i++)
|
||||
{
|
||||
var child = this.remove(this.list[i]);
|
||||
|
||||
newParent.add(child);
|
||||
}
|
||||
}
|
||||
|
||||
return newParent;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperties(Phaser.Component.Children.prototype, {
|
||||
|
||||
/**
|
||||
* Returns the first item and resets the cursor to the start.
|
||||
*
|
||||
* @name Phaser.ArraySet#first
|
||||
* @property {any} first
|
||||
*/
|
||||
length: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.list.length;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the first item and resets the cursor to the start.
|
||||
*
|
||||
* @name Phaser.ArraySet#first
|
||||
* @property {any} first
|
||||
*/
|
||||
first: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
this.position = 0;
|
||||
|
||||
if (this.list.length > 0)
|
||||
{
|
||||
return this.list[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the last item and resets the cursor to the end.
|
||||
*
|
||||
* @name Phaser.ArraySet#last
|
||||
* @property {any} last
|
||||
*/
|
||||
last: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
if (this.list.length > 0)
|
||||
{
|
||||
this.position = this.list.length - 1;
|
||||
|
||||
return this.list[this.position];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the the next item (based on the cursor) and advances the cursor.
|
||||
*
|
||||
* @name Phaser.ArraySet#next
|
||||
* @property {any} next
|
||||
*/
|
||||
next: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
if (this.position < this.list.length)
|
||||
{
|
||||
this.position++;
|
||||
|
||||
return this.list[this.position];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the the previous item (based on the cursor) and retreats the cursor.
|
||||
*
|
||||
* @name Phaser.ArraySet#previous
|
||||
* @property {any} previous
|
||||
*/
|
||||
previous: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
if (this.position > 0)
|
||||
{
|
||||
this.position--;
|
||||
|
||||
return this.list[this.position];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -1,390 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Color Component allows you to control the alpha, blend mode, tint and background color
|
||||
* of a Game Object.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.Color = function (gameObject)
|
||||
{
|
||||
this.gameObject = gameObject;
|
||||
|
||||
this.state = gameObject.state;
|
||||
|
||||
this._dirty = false;
|
||||
|
||||
this._alpha = 1;
|
||||
this._worldAlpha = 1;
|
||||
|
||||
this._blendMode = 0;
|
||||
|
||||
this._tint = { topLeft: 0xffffff, topRight: 0xffffff, bottomLeft: 0xffffff, bottomRight: 0xffffff };
|
||||
this._glTint = { topLeft: 16777215, topRight: 16777215, bottomLeft: 16777215, bottomRight: 16777215 };
|
||||
this._hasTint = false;
|
||||
|
||||
// Between 0 and 255
|
||||
this._r = 0;
|
||||
this._g = 0;
|
||||
this._b = 0;
|
||||
|
||||
// Between 0 and 1
|
||||
this._a = 1;
|
||||
|
||||
// String version of RGBA
|
||||
this._rgba = '';
|
||||
|
||||
// 32-bit version of ARGB
|
||||
this._glBg = 0;
|
||||
|
||||
this._hasBackground = false;
|
||||
};
|
||||
|
||||
Phaser.Component.Color.prototype.constructor = Phaser.Component.Color;
|
||||
|
||||
Phaser.Component.Color.prototype = {
|
||||
|
||||
setBackground: function (red, green, blue, alpha)
|
||||
{
|
||||
if (red === undefined)
|
||||
{
|
||||
this._hasBackground = false;
|
||||
this._glBg = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._hasBackground = true;
|
||||
this._r = red;
|
||||
this._g = (green) ? green : 0;
|
||||
this._b = (blue) ? blue : 0;
|
||||
this._a = (alpha) ? alpha : 1;
|
||||
}
|
||||
|
||||
this.dirty = true;
|
||||
},
|
||||
|
||||
clearTint: function ()
|
||||
{
|
||||
this.setTint(0xffffff);
|
||||
|
||||
this._hasTint = false;
|
||||
},
|
||||
|
||||
setTint: function (topLeft, topRight, bottomLeft, bottomRight)
|
||||
{
|
||||
if (topRight === undefined)
|
||||
{
|
||||
topRight = topLeft;
|
||||
bottomLeft = topLeft;
|
||||
bottomRight = topLeft;
|
||||
}
|
||||
|
||||
this.tintTopLeft = topLeft;
|
||||
this.tintTopRight = topRight;
|
||||
this.tintBottomLeft = bottomLeft;
|
||||
this.tintBottomRight = bottomRight;
|
||||
|
||||
this._hasTint = true;
|
||||
|
||||
this.dirty = true;
|
||||
},
|
||||
|
||||
// Called by the Dirty Manager
|
||||
update: function ()
|
||||
{
|
||||
this._dirty = false;
|
||||
|
||||
if (this._hasBackground)
|
||||
{
|
||||
this._rgba = 'rgba(' + this._r + ',' + this._g + ',' + this._b + ',' + this._a + ')';
|
||||
this._glBg = this.getColor32(this._r, this._g, this._b, this._a);
|
||||
}
|
||||
|
||||
// Tint mults?
|
||||
|
||||
},
|
||||
|
||||
getColor: function (value)
|
||||
{
|
||||
return (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16);
|
||||
},
|
||||
|
||||
getColor32: function (r, g, b, a)
|
||||
{
|
||||
a *= 255;
|
||||
|
||||
return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0;
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
this.gameObject = null;
|
||||
this.state = null;
|
||||
this._tint = [];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperties(Phaser.Component.Color.prototype, {
|
||||
|
||||
dirty: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._dirty;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
if (!this._dirty)
|
||||
{
|
||||
this.state.sys.updates.add(this);
|
||||
}
|
||||
|
||||
this._dirty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
tintTopLeft: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._tint.topLeft;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._tint.topLeft = value;
|
||||
this._glTint.topLeft = this.getColor(value);
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
tintTopRight: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._tint.topRight;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._tint.topRight = value;
|
||||
this._glTint.topRight = this.getColor(value);
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
tintBottomLeft: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._tint.bottomLeft;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._tint.bottomLeft = value;
|
||||
this._glTint.bottomLeft = this.getColor(value);
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
tintBottomRight: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._tint.bottomRight;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._tint.bottomRight = value;
|
||||
this._glTint.bottomRight = this.getColor(value);
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
tint: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._tint;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.setTint(value, value, value, value);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
alpha: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._alpha;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
if (value !== this._alpha)
|
||||
{
|
||||
this._alpha = value;
|
||||
this.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
blendMode: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._blendMode;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
if (value !== this._blendMode && value >= 0 && value <= 16)
|
||||
{
|
||||
this._blendMode = value;
|
||||
this.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
worldAlpha: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._worldAlpha;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._worldAlpha = this._alpha * value;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
backgroundAlpha: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._a;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
if (value !== this._a)
|
||||
{
|
||||
this._a = value;
|
||||
this._hasBackground = true;
|
||||
this.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
red: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._r;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
if (value !== this._r)
|
||||
{
|
||||
this._r = value | 0;
|
||||
this._hasBackground = true;
|
||||
this.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
green: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._g;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
if (value !== this._g)
|
||||
{
|
||||
this._g = value | 0;
|
||||
this._hasBackground = true;
|
||||
this.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
blue: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._b;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
if (value !== this._b)
|
||||
{
|
||||
this._b = value | 0;
|
||||
this._hasBackground = true;
|
||||
this.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -1,12 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.Component = function (gameObject)
|
||||
{
|
||||
this.gameObject = gameObject;
|
||||
};
|
||||
|
||||
Phaser.Component.prototype.constructor = Phaser.Component;
|
|
@ -1,281 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Data Component features a means to store pieces of data specific to a Game Object,
|
||||
* search it, query it, and retrieve it.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.Data = function (parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
|
||||
this.list = {};
|
||||
|
||||
this._beforeCallbacks = {};
|
||||
this._afterCallbacks = {};
|
||||
|
||||
this._frozen = false;
|
||||
};
|
||||
|
||||
Phaser.Component.Data.prototype.constructor = Phaser.Component.Data;
|
||||
|
||||
Phaser.Component.Data.prototype = {
|
||||
|
||||
// Retrieves the value for the given key, or undefined if it doesn't exist.
|
||||
get: function (key)
|
||||
{
|
||||
return this.list[key];
|
||||
},
|
||||
|
||||
getAll: function ()
|
||||
{
|
||||
var results = {};
|
||||
|
||||
for (var key in this.list)
|
||||
{
|
||||
results[key] = this.list[key];
|
||||
}
|
||||
|
||||
return results;
|
||||
},
|
||||
|
||||
query: function (search)
|
||||
{
|
||||
var results = {};
|
||||
|
||||
for (var key in this.list)
|
||||
{
|
||||
if (key.match(search))
|
||||
{
|
||||
results[key] = this.list[key];
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
},
|
||||
|
||||
set: function (key, data)
|
||||
{
|
||||
if (this._frozen)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
var listener;
|
||||
var result;
|
||||
|
||||
// If there is a 'before' callback, then check it for a result
|
||||
if (this._beforeCallbacks.hasOwnProperty(key))
|
||||
{
|
||||
listener = this._beforeCallbacks[key];
|
||||
|
||||
result = listener.callback.call(listener.scope, this.parent, key, data);
|
||||
|
||||
if (result !== undefined)
|
||||
{
|
||||
data = result;
|
||||
}
|
||||
}
|
||||
|
||||
this.list[key] = data;
|
||||
|
||||
// If there is a 'after' callback, then check it for a result
|
||||
if (this._afterCallbacks.hasOwnProperty(key))
|
||||
{
|
||||
listener = this._afterCallbacks[key];
|
||||
|
||||
result = listener.callback.call(listener.scope, this.parent, key, data);
|
||||
|
||||
if (result !== undefined)
|
||||
{
|
||||
this.list[key] = result;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
before: function (key, callback, scope)
|
||||
{
|
||||
if (callback === undefined)
|
||||
{
|
||||
// Remove entry
|
||||
delete this._beforeCallbacks[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
this._beforeCallbacks[key] = { callback: callback, scope: scope };
|
||||
}
|
||||
},
|
||||
|
||||
after: function (key, callback, scope)
|
||||
{
|
||||
if (callback === undefined)
|
||||
{
|
||||
// Remove entry
|
||||
delete this._afterCallbacks[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
this._afterCallbacks[key] = { callback: callback, scope: scope };
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Passes all data entries to the given callback. Stores the result of the callback.
|
||||
*
|
||||
* @method each
|
||||
* @param {function} callback - The function to call.
|
||||
* @param {object} [scope] - Value to use as `this` when executing callback.
|
||||
* @param {...*} [arguments] - Additional arguments that will be passed to the callback, after the game object, key, and data.
|
||||
*/
|
||||
each: function (callback, scope)
|
||||
{
|
||||
var args = [ this.parent, null, undefined ];
|
||||
|
||||
for (var i = 1; i < arguments.length; i++)
|
||||
{
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
|
||||
for (var key in this.list)
|
||||
{
|
||||
args[1] = key;
|
||||
args[2] = this.list[key];
|
||||
|
||||
callback.apply(scope, args);
|
||||
}
|
||||
},
|
||||
|
||||
merge: function (data, overwrite)
|
||||
{
|
||||
if (overwrite === undefined) { overwrite = true; }
|
||||
|
||||
// Merge data from another component into this one
|
||||
for (var key in data)
|
||||
{
|
||||
if (overwrite || (!overwrite && !this.has(key)))
|
||||
{
|
||||
this.list[key] = data;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
remove: function (key)
|
||||
{
|
||||
if (!this._frozen && this.has(key))
|
||||
{
|
||||
delete this.list[key];
|
||||
|
||||
this.removeListeners(key);
|
||||
}
|
||||
},
|
||||
|
||||
removeListeners: function (key)
|
||||
{
|
||||
if (this._beforeCallbacks.hasOwnProperty(key))
|
||||
{
|
||||
delete this._beforeCallbacks[key];
|
||||
}
|
||||
|
||||
if (this._afterCallbacks.hasOwnProperty(key))
|
||||
{
|
||||
delete this._afterCallbacks[key];
|
||||
}
|
||||
},
|
||||
|
||||
// Gets the data associated with the given 'key', deletes it from this Data store, then returns it.
|
||||
pop: function (key)
|
||||
{
|
||||
var data = undefined;
|
||||
|
||||
if (!this._frozen && this.has(key))
|
||||
{
|
||||
data = this.list[key];
|
||||
|
||||
delete this.list[key];
|
||||
|
||||
this.removeListeners(key);
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
has: function (key)
|
||||
{
|
||||
return this.list.hasOwnProperty(key);
|
||||
},
|
||||
|
||||
reset: function ()
|
||||
{
|
||||
for (var key in this.list)
|
||||
{
|
||||
delete this.list[key];
|
||||
}
|
||||
|
||||
for (key in this._beforeCallbacks)
|
||||
{
|
||||
delete this._beforeCallbacks[key];
|
||||
}
|
||||
|
||||
for (key in this._afterCallbacks)
|
||||
{
|
||||
delete this._afterCallbacks[key];
|
||||
}
|
||||
|
||||
this._frozen = false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperties(Phaser.Component.Data.prototype, {
|
||||
|
||||
/**
|
||||
* Freeze this Data component, so no changes can be written to it.
|
||||
*
|
||||
* @name freeze
|
||||
* @property {boolean} freeze
|
||||
*/
|
||||
freeze: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._frozen;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._frozen = (value) ? true : false;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
count: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
var i = 0;
|
||||
|
||||
for (var key in this.list)
|
||||
{
|
||||
if (this.list[key] !== undefined)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -1,25 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Timeline Component.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.Timeline = function (gameObject)
|
||||
{
|
||||
this.gameObject = gameObject;
|
||||
|
||||
this.game = gameObject.game;
|
||||
|
||||
this._dirty = false;
|
||||
};
|
||||
|
||||
Phaser.Component.Timeline.prototype.constructor = Phaser.Component.Timeline;
|
||||
|
||||
Phaser.Component.Timeline.prototype = {
|
||||
|
||||
};
|
File diff suppressed because it is too large
Load diff
|
@ -1,79 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Dirty! Manager
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.UpdateManager = function (state)
|
||||
{
|
||||
this.state = state;
|
||||
|
||||
this.game = state.game;
|
||||
|
||||
this.list = [];
|
||||
|
||||
// this.i = 1;
|
||||
|
||||
this.running = false;
|
||||
|
||||
this.processed = 0;
|
||||
};
|
||||
|
||||
Phaser.UpdateManager.prototype.constructor = Phaser.UpdateManager;
|
||||
|
||||
Phaser.UpdateManager.prototype = {
|
||||
|
||||
stop: function ()
|
||||
{
|
||||
if (!this.running)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// console.log(this.i, 'UpdateManager.stop', this.processed);
|
||||
|
||||
this.list.length = 0;
|
||||
|
||||
// this.i++;
|
||||
},
|
||||
|
||||
start: function ()
|
||||
{
|
||||
if (!this.running)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var len = this.list.length;
|
||||
|
||||
if (len === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// console.log(this.i, 'UpdateManager.start', len);
|
||||
|
||||
this.processed = 0;
|
||||
|
||||
for (var i = 0; i < len; i++)
|
||||
{
|
||||
// Because it may have already been processed (as a child of another Transform that was updated)
|
||||
if (this.list[i] && this.list[i]._dirty)
|
||||
{
|
||||
this.processed++;
|
||||
this.list[i].update();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
add: function (transform)
|
||||
{
|
||||
this.list.push(transform);
|
||||
}
|
||||
|
||||
};
|
|
@ -1,10 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
Phaser.Boot = function ()
|
||||
{
|
||||
|
||||
|
||||
};
|
|
@ -1,945 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Camera is your view into the game world. It has a position and size and renders only those objects within its field of view.
|
||||
* The game automatically creates a single Stage sized camera on boot. Move the camera around the world with Phaser.Camera.x/y
|
||||
*
|
||||
* @class Phaser.Camera
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - Game reference to the currently running game.
|
||||
* @param {number} id - Not being used at the moment, will be when Phaser supports multiple camera
|
||||
* @param {number} x - Position of the camera on the X axis
|
||||
* @param {number} y - Position of the camera on the Y axis
|
||||
* @param {number} width - The width of the view rectangle
|
||||
* @param {number} height - The height of the view rectangle
|
||||
*/
|
||||
Phaser.Camera = function (game, id, x, y, width, height) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.World} world - A reference to the game world.
|
||||
*/
|
||||
this.world = game.world;
|
||||
|
||||
/**
|
||||
* @property {number} id - Reserved for future multiple camera set-ups.
|
||||
* @default
|
||||
*/
|
||||
this.id = 0;
|
||||
|
||||
/**
|
||||
* Camera view.
|
||||
* The view into the world we wish to render (by default the game dimensions).
|
||||
* The x/y values are in world coordinates, not screen coordinates, the width/height is how many pixels to render.
|
||||
* Sprites outside of this view are not rendered if Sprite.autoCull is set to `true`. Otherwise they are always rendered.
|
||||
* @property {Phaser.Rectangle} view
|
||||
*/
|
||||
this.view = new Phaser.Rectangle(x, y, width, height);
|
||||
|
||||
/**
|
||||
* The Camera is bound to this Rectangle and cannot move outside of it. By default it is enabled and set to the size of the World.
|
||||
* The Rectangle can be located anywhere in the world and updated as often as you like. If you don't wish the Camera to be bound
|
||||
* at all then set this to null. The values can be anything and are in World coordinates, with 0,0 being the top-left of the world.
|
||||
*
|
||||
* @property {Phaser.Rectangle} bounds - The Rectangle in which the Camera is bounded. Set to null to allow for movement anywhere.
|
||||
*/
|
||||
this.bounds = new Phaser.Rectangle(x, y, width, height);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Rectangle} deadzone - Moving inside this Rectangle will not cause the camera to move.
|
||||
*/
|
||||
this.deadzone = null;
|
||||
|
||||
/**
|
||||
* @property {boolean} visible - Whether this camera is visible or not.
|
||||
* @default
|
||||
*/
|
||||
this.visible = true;
|
||||
|
||||
/**
|
||||
* @property {boolean} roundPx - If a Camera has roundPx set to `true` it will call `view.floor` as part of its update loop, keeping its boundary to integer values. Set this to `false` to disable this from happening.
|
||||
* @default
|
||||
*/
|
||||
this.roundPx = true;
|
||||
|
||||
/**
|
||||
* @property {boolean} atLimit - Whether this camera is flush with the World Bounds or not.
|
||||
*/
|
||||
this.atLimit = { x: false, y: false };
|
||||
|
||||
/**
|
||||
* @property {Phaser.Sprite} target - If the camera is tracking a Sprite, this is a reference to it, otherwise null.
|
||||
* @default
|
||||
*/
|
||||
this.target = null;
|
||||
|
||||
/**
|
||||
* @property {PIXI.DisplayObject} displayObject - The display object to which all game objects are added. Set by World.boot.
|
||||
*/
|
||||
this.displayObject = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} scale - The scale of the display object to which all game objects are added. Set by World.boot.
|
||||
*/
|
||||
this.scale = null;
|
||||
|
||||
/**
|
||||
* @property {number} totalInView - The total number of Sprites with `autoCull` set to `true` that are visible by this Camera.
|
||||
* @readonly
|
||||
*/
|
||||
this.totalInView = 0;
|
||||
|
||||
/**
|
||||
* The linear interpolation value to use when following a target.
|
||||
* The default values of 1 means the camera will instantly snap to the target coordinates.
|
||||
* A lower value, such as 0.1 means the camera will more slowly track the target, giving
|
||||
* a smooth transition. You can set the horizontal and vertical values independently, and also
|
||||
* adjust this value in real-time during your game.
|
||||
* @property {Phaser.Point} lerp
|
||||
* @default
|
||||
*/
|
||||
this.lerp = new Phaser.Point(1, 1);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Signal} onShakeComplete - This signal is dispatched when the camera shake effect completes.
|
||||
*/
|
||||
this.onShakeComplete = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Signal} onFlashComplete - This signal is dispatched when the camera flash effect completes.
|
||||
*/
|
||||
this.onFlashComplete = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* This signal is dispatched when the camera fade effect completes.
|
||||
* When the fade effect completes you will be left with the screen black (or whatever
|
||||
* color you faded to). In order to reset this call `Camera.resetFX`. This is called
|
||||
* automatically when you change State.
|
||||
* @property {Phaser.Signal} onFadeComplete
|
||||
*/
|
||||
this.onFadeComplete = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* The Graphics object used to handle camera fx such as fade and flash.
|
||||
* @property {Phaser.Graphics} fx
|
||||
* @protected
|
||||
*/
|
||||
this.fx = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} _targetPosition - Internal point used to calculate target position.
|
||||
* @private
|
||||
*/
|
||||
this._targetPosition = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {number} edge - Edge property.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._edge = 0;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} position - Current position of the camera in world.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._position = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {Object} _shake - The shake effect container.
|
||||
* @private
|
||||
*/
|
||||
this._shake = {
|
||||
intensity: 0,
|
||||
duration: 0,
|
||||
horizontal: false,
|
||||
vertical: false,
|
||||
shakeBounds: true,
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
|
||||
/**
|
||||
* @property {number} _fxDuration - FX duration timer.
|
||||
* @private
|
||||
*/
|
||||
this._fxDuration = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _fxType - The FX type running.
|
||||
* @private
|
||||
*/
|
||||
this._fxType = 0;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Camera.FOLLOW_LOCKON = 0;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Camera.FOLLOW_PLATFORMER = 1;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Camera.FOLLOW_TOPDOWN = 2;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Camera.FOLLOW_TOPDOWN_TIGHT = 3;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Camera.SHAKE_BOTH = 4;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Camera.SHAKE_HORIZONTAL = 5;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Camera.SHAKE_VERTICAL = 6;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {boolean}
|
||||
*/
|
||||
Phaser.Camera.ENABLE_FX = true;
|
||||
|
||||
Phaser.Camera.prototype = {
|
||||
|
||||
/**
|
||||
* Called automatically by Phaser.World.
|
||||
*
|
||||
* @method Phaser.Camera#boot
|
||||
* @private
|
||||
*/
|
||||
boot: function () {
|
||||
|
||||
this.displayObject = this.game.world;
|
||||
|
||||
this.scale = this.game.world.scale;
|
||||
|
||||
this.game.camera = this;
|
||||
|
||||
if (Phaser.Graphics && Phaser.Camera.ENABLE_FX)
|
||||
{
|
||||
this.fx = new Phaser.Graphics(this.game);
|
||||
|
||||
this.game.stage.addChild(this.fx);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Camera preUpdate. Sets the total view counter to zero.
|
||||
*
|
||||
* @method Phaser.Camera#preUpdate
|
||||
*/
|
||||
preUpdate: function () {
|
||||
|
||||
this.totalInView = 0;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Tell the camera which sprite to follow.
|
||||
*
|
||||
* You can set the follow type and a linear interpolation value.
|
||||
* Use low lerp values (such as 0.1) to automatically smooth the camera motion.
|
||||
*
|
||||
* If you find you're getting a slight "jitter" effect when following a Sprite it's probably to do with sub-pixel rendering of the Sprite position.
|
||||
* This can be disabled by setting `game.renderer.renderSession.roundPixels = true` to force full pixel rendering.
|
||||
*
|
||||
* @method Phaser.Camera#follow
|
||||
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text} target - The object you want the camera to track. Set to null to not follow anything.
|
||||
* @param {number} [style] - Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling follow().
|
||||
* @param {float} [lerpX=1] - A value between 0 and 1. This value specifies the amount of linear interpolation to use when horizontally tracking the target. The closer the value to 1, the faster the camera will track.
|
||||
* @param {float} [lerpY=1] - A value between 0 and 1. This value specifies the amount of linear interpolation to use when vertically tracking the target. The closer the value to 1, the faster the camera will track.
|
||||
*/
|
||||
follow: function (target, style, lerpX, lerpY) {
|
||||
|
||||
if (style === undefined) { style = Phaser.Camera.FOLLOW_LOCKON; }
|
||||
if (lerpX === undefined) { lerpX = 1; }
|
||||
if (lerpY === undefined) { lerpY = 1; }
|
||||
|
||||
this.target = target;
|
||||
this.lerp.set(lerpX, lerpY);
|
||||
|
||||
var helper;
|
||||
|
||||
switch (style) {
|
||||
|
||||
case Phaser.Camera.FOLLOW_PLATFORMER:
|
||||
var w = this.width / 8;
|
||||
var h = this.height / 3;
|
||||
this.deadzone = new Phaser.Rectangle((this.width - w) / 2, (this.height - h) / 2 - h * 0.25, w, h);
|
||||
break;
|
||||
|
||||
case Phaser.Camera.FOLLOW_TOPDOWN:
|
||||
helper = Math.max(this.width, this.height) / 4;
|
||||
this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
|
||||
break;
|
||||
|
||||
case Phaser.Camera.FOLLOW_TOPDOWN_TIGHT:
|
||||
helper = Math.max(this.width, this.height) / 8;
|
||||
this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
|
||||
break;
|
||||
|
||||
case Phaser.Camera.FOLLOW_LOCKON:
|
||||
this.deadzone = null;
|
||||
break;
|
||||
|
||||
default:
|
||||
this.deadzone = null;
|
||||
break;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the Camera follow target to null, stopping it from following an object if it's doing so.
|
||||
*
|
||||
* @method Phaser.Camera#unfollow
|
||||
*/
|
||||
unfollow: function () {
|
||||
|
||||
this.target = null;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Move the camera focus on a display object instantly.
|
||||
* @method Phaser.Camera#focusOn
|
||||
* @param {any} displayObject - The display object to focus the camera on. Must have visible x/y properties.
|
||||
*/
|
||||
focusOn: function (displayObject) {
|
||||
|
||||
this.setPosition(Math.round(displayObject.x - this.view.halfWidth), Math.round(displayObject.y - this.view.halfHeight));
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Move the camera focus on a location instantly.
|
||||
* @method Phaser.Camera#focusOnXY
|
||||
* @param {number} x - X position.
|
||||
* @param {number} y - Y position.
|
||||
*/
|
||||
focusOnXY: function (x, y) {
|
||||
|
||||
this.setPosition(Math.round(x - this.view.halfWidth), Math.round(y - this.view.halfHeight));
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* This creates a camera shake effect. It works by applying a random amount of additional
|
||||
* spacing on the x and y axis each frame. You can control the intensity and duration
|
||||
* of the effect, and if it should effect both axis or just one.
|
||||
*
|
||||
* When the shake effect ends the signal Camera.onShakeComplete is dispatched.
|
||||
*
|
||||
* @method Phaser.Camera#shake
|
||||
* @param {float} [intensity=0.05] - The intensity of the camera shake. Given as a percentage of the camera size representing the maximum distance that the camera can move while shaking.
|
||||
* @param {number} [duration=500] - The duration of the shake effect in milliseconds.
|
||||
* @param {boolean} [force=true] - If a camera shake effect is already running and force is true it will replace the previous effect, resetting the duration.
|
||||
* @param {number} [direction=Phaser.Camera.SHAKE_BOTH] - The directions in which the camera can shake. Either Phaser.Camera.SHAKE_BOTH, Phaser.Camera.SHAKE_HORIZONTAL or Phaser.Camera.SHAKE_VERTICAL.
|
||||
* @param {boolean} [shakeBounds=true] - Is the effect allowed to shake the camera beyond its bounds (if set?).
|
||||
* @return {boolean} True if the shake effect was started, otherwise false.
|
||||
*/
|
||||
shake: function (intensity, duration, force, direction, shakeBounds) {
|
||||
|
||||
if (intensity === undefined) { intensity = 0.05; }
|
||||
if (duration === undefined) { duration = 500; }
|
||||
if (force === undefined) { force = true; }
|
||||
if (direction === undefined) { direction = Phaser.Camera.SHAKE_BOTH; }
|
||||
if (shakeBounds === undefined) { shakeBounds = true; }
|
||||
|
||||
if (!force && this._shake.duration > 0)
|
||||
{
|
||||
// Can't reset an already running shake
|
||||
return false;
|
||||
}
|
||||
|
||||
this._shake.intensity = intensity;
|
||||
this._shake.duration = duration;
|
||||
this._shake.shakeBounds = shakeBounds;
|
||||
|
||||
this._shake.x = 0;
|
||||
this._shake.y = 0;
|
||||
|
||||
this._shake.horizontal = (direction === Phaser.Camera.SHAKE_BOTH || direction === Phaser.Camera.SHAKE_HORIZONTAL);
|
||||
this._shake.vertical = (direction === Phaser.Camera.SHAKE_BOTH || direction === Phaser.Camera.SHAKE_VERTICAL);
|
||||
|
||||
return true;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* This creates a camera flash effect. It works by filling the game with the solid fill
|
||||
* color specified, and then fading it away to alpha 0 over the duration given.
|
||||
*
|
||||
* You can use this for things such as hit feedback effects.
|
||||
*
|
||||
* When the effect ends the signal Camera.onFlashComplete is dispatched.
|
||||
*
|
||||
* @method Phaser.Camera#flash
|
||||
* @param {numer} [color=0xffffff] - The color of the flash effect. I.e. 0xffffff for white, 0xff0000 for red, etc.
|
||||
* @param {number} [duration=500] - The duration of the flash effect in milliseconds.
|
||||
* @param {boolean} [force=false] - If a camera flash or fade effect is already running and force is true it will replace the previous effect, resetting the duration.
|
||||
* @param {numer} [alpha=1] - The alpha value of the color applied to the flash effect.
|
||||
* @return {boolean} True if the effect was started, otherwise false.
|
||||
*/
|
||||
flash: function (color, duration, force, alpha) {
|
||||
|
||||
if (color === undefined) { color = 0xffffff; }
|
||||
if (duration === undefined) { duration = 500; }
|
||||
if (force === undefined) { force = false; }
|
||||
if (alpha === undefined) { alpha = 1; }
|
||||
|
||||
if (!this.fx || (!force && this._fxDuration > 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.fx.clear();
|
||||
|
||||
this.fx.beginFill(color, alpha);
|
||||
this.fx.drawRect(0, 0, this.width, this.height);
|
||||
this.fx.endFill();
|
||||
|
||||
this.fx.alpha = 1;
|
||||
|
||||
this._fxDuration = duration;
|
||||
this._fxType = 0;
|
||||
|
||||
return true;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* This creates a camera fade effect. It works by filling the game with the
|
||||
* color specified, over the duration given, ending with a solid fill.
|
||||
*
|
||||
* You can use this for things such as transitioning to a new scene.
|
||||
*
|
||||
* The game will be left 'filled' at the end of this effect, likely obscuring
|
||||
* everything. In order to reset it you can call `Camera.resetFX` and it will clear the
|
||||
* fade. Or you can call `Camera.flash` with the same color as the fade, and it will
|
||||
* reverse the process, bringing the game back into view again.
|
||||
*
|
||||
* When the effect ends the signal Camera.onFadeComplete is dispatched.
|
||||
*
|
||||
* @method Phaser.Camera#fade
|
||||
* @param {numer} [color=0x000000] - The color the game will fade to. I.e. 0x000000 for black, 0xff0000 for red, etc.
|
||||
* @param {number} [duration=500] - The duration of the fade in milliseconds.
|
||||
* @param {boolean} [force=false] - If a camera flash or fade effect is already running and force is true it will replace the previous effect, resetting the duration.
|
||||
* @param {numer} [alpha=1] - The alpha value of the color applied to the fade effect.
|
||||
* @return {boolean} True if the effect was started, otherwise false.
|
||||
*/
|
||||
fade: function (color, duration, force, alpha) {
|
||||
|
||||
if (color === undefined) { color = 0x000000; }
|
||||
if (duration === undefined) { duration = 500; }
|
||||
if (force === undefined) { force = false; }
|
||||
if (alpha === undefined) { alpha = 1; }
|
||||
|
||||
if (!this.fx || (!force && this._fxDuration > 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.fx.clear();
|
||||
|
||||
this.fx.beginFill(color, alpha);
|
||||
this.fx.drawRect(0, 0, this.width, this.height);
|
||||
this.fx.endFill();
|
||||
|
||||
this.fx.alpha = 0;
|
||||
|
||||
this._fxDuration = duration;
|
||||
this._fxType = 1;
|
||||
|
||||
return true;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The camera update loop. This is called automatically by the core game loop.
|
||||
*
|
||||
* @method Phaser.Camera#update
|
||||
* @protected
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
if (this._fxDuration > 0)
|
||||
{
|
||||
this.updateFX();
|
||||
}
|
||||
|
||||
if (this._shake.duration > 0)
|
||||
{
|
||||
this.updateShake();
|
||||
}
|
||||
|
||||
if (this.bounds)
|
||||
{
|
||||
this.checkBounds();
|
||||
}
|
||||
|
||||
if (this.roundPx)
|
||||
{
|
||||
this.view.floor();
|
||||
this._shake.x = Math.floor(this._shake.x);
|
||||
this._shake.y = Math.floor(this._shake.y);
|
||||
}
|
||||
|
||||
this.displayObject.position.x = -this.view.x;
|
||||
this.displayObject.position.y = -this.view.y;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the camera flash and fade effects.
|
||||
*
|
||||
* @method Phaser.Camera#updateFX
|
||||
* @private
|
||||
*/
|
||||
updateFX: function () {
|
||||
|
||||
if (this._fxType === 0)
|
||||
{
|
||||
// flash
|
||||
this.fx.alpha -= this.game.time.elapsedMS / this._fxDuration;
|
||||
|
||||
if (this.fx.alpha <= 0)
|
||||
{
|
||||
this._fxDuration = 0;
|
||||
this.fx.alpha = 0;
|
||||
this.onFlashComplete.dispatch();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// fade
|
||||
this.fx.alpha += this.game.time.elapsedMS / this._fxDuration;
|
||||
|
||||
if (this.fx.alpha >= 1)
|
||||
{
|
||||
this._fxDuration = 0;
|
||||
this.fx.alpha = 1;
|
||||
this.onFadeComplete.dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the camera shake effect.
|
||||
*
|
||||
* @method Phaser.Camera#updateShake
|
||||
* @private
|
||||
*/
|
||||
updateShake: function () {
|
||||
|
||||
this._shake.duration -= this.game.time.elapsedMS;
|
||||
|
||||
if (this._shake.duration <= 0)
|
||||
{
|
||||
this.onShakeComplete.dispatch();
|
||||
this._shake.x = 0;
|
||||
this._shake.y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this._shake.horizontal)
|
||||
{
|
||||
this._shake.x = this.game.rnd.frac() * this._shake.intensity * this.view.width * 2 - this._shake.intensity * this.view.width;
|
||||
}
|
||||
|
||||
if (this._shake.vertical)
|
||||
{
|
||||
this._shake.y = this.game.rnd.frac() * this._shake.intensity * this.view.height * 2 - this._shake.intensity * this.view.height;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal method that handles tracking a sprite.
|
||||
*
|
||||
* @method Phaser.Camera#updateTarget
|
||||
* @private
|
||||
*/
|
||||
updateTarget: function () {
|
||||
|
||||
this._targetPosition.x = this.view.x + this.target.worldPosition.x;
|
||||
this._targetPosition.y = this.view.y + this.target.worldPosition.y;
|
||||
|
||||
if (this.deadzone)
|
||||
{
|
||||
this._edge = this._targetPosition.x - this.view.x;
|
||||
|
||||
if (this._edge < this.deadzone.left)
|
||||
{
|
||||
this.view.x = this.game.math.linear(this.view.x, this._targetPosition.x - this.deadzone.left, this.lerp.x);
|
||||
}
|
||||
else if (this._edge > this.deadzone.right)
|
||||
{
|
||||
this.view.x = this.game.math.linear(this.view.x, this._targetPosition.x - this.deadzone.right, this.lerp.x);
|
||||
}
|
||||
|
||||
this._edge = this._targetPosition.y - this.view.y;
|
||||
|
||||
if (this._edge < this.deadzone.top)
|
||||
{
|
||||
this.view.y = this.game.math.linear(this.view.y, this._targetPosition.y - this.deadzone.top, this.lerp.y);
|
||||
}
|
||||
else if (this._edge > this.deadzone.bottom)
|
||||
{
|
||||
this.view.y = this.game.math.linear(this.view.y, this._targetPosition.y - this.deadzone.bottom, this.lerp.y);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.view.x = this.game.math.linear(this.view.x, this._targetPosition.x - this.view.halfWidth, this.lerp.x);
|
||||
this.view.y = this.game.math.linear(this.view.y, this._targetPosition.y - this.view.halfHeight, this.lerp.y);
|
||||
}
|
||||
|
||||
if (this.bounds)
|
||||
{
|
||||
this.checkBounds();
|
||||
}
|
||||
|
||||
if (this.roundPx)
|
||||
{
|
||||
this.view.floor();
|
||||
}
|
||||
|
||||
this.displayObject.position.x = -this.view.x;
|
||||
this.displayObject.position.y = -this.view.y;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the Camera bounds to match the game world.
|
||||
*
|
||||
* @method Phaser.Camera#setBoundsToWorld
|
||||
*/
|
||||
setBoundsToWorld: function () {
|
||||
|
||||
if (this.bounds)
|
||||
{
|
||||
this.bounds.copyFrom(this.game.world.bounds);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Method called to ensure the camera doesn't venture outside of the game world.
|
||||
* Called automatically by Camera.update.
|
||||
*
|
||||
* @method Phaser.Camera#checkBounds
|
||||
* @protected
|
||||
*/
|
||||
checkBounds: function () {
|
||||
|
||||
this.atLimit.x = false;
|
||||
this.atLimit.y = false;
|
||||
|
||||
var vx = this.view.x + this._shake.x;
|
||||
var vw = this.view.right + this._shake.x;
|
||||
var vy = this.view.y + this._shake.y;
|
||||
var vh = this.view.bottom + this._shake.y;
|
||||
|
||||
// Make sure we didn't go outside the cameras bounds
|
||||
if (vx <= this.bounds.x * this.scale.x)
|
||||
{
|
||||
this.atLimit.x = true;
|
||||
this.view.x = this.bounds.x * this.scale.x;
|
||||
|
||||
if (!this._shake.shakeBounds)
|
||||
{
|
||||
// The camera is up against the bounds, so reset the shake
|
||||
this._shake.x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (vw >= this.bounds.right * this.scale.x)
|
||||
{
|
||||
this.atLimit.x = true;
|
||||
this.view.x = (this.bounds.right * this.scale.x) - this.width;
|
||||
|
||||
if (!this._shake.shakeBounds)
|
||||
{
|
||||
// The camera is up against the bounds, so reset the shake
|
||||
this._shake.x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (vy <= this.bounds.top * this.scale.y)
|
||||
{
|
||||
this.atLimit.y = true;
|
||||
this.view.y = this.bounds.top * this.scale.y;
|
||||
|
||||
if (!this._shake.shakeBounds)
|
||||
{
|
||||
// The camera is up against the bounds, so reset the shake
|
||||
this._shake.y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (vh >= this.bounds.bottom * this.scale.y)
|
||||
{
|
||||
this.atLimit.y = true;
|
||||
this.view.y = (this.bounds.bottom * this.scale.y) - this.height;
|
||||
|
||||
if (!this._shake.shakeBounds)
|
||||
{
|
||||
// The camera is up against the bounds, so reset the shake
|
||||
this._shake.y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* A helper function to set both the X and Y properties of the camera at once
|
||||
* without having to use game.camera.x and game.camera.y.
|
||||
*
|
||||
* @method Phaser.Camera#setPosition
|
||||
* @param {number} x - X position.
|
||||
* @param {number} y - Y position.
|
||||
*/
|
||||
setPosition: function (x, y) {
|
||||
|
||||
this.view.x = x;
|
||||
this.view.y = y;
|
||||
|
||||
if (this.bounds)
|
||||
{
|
||||
this.checkBounds();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the size of the view rectangle given the width and height in parameters.
|
||||
*
|
||||
* @method Phaser.Camera#setSize
|
||||
* @param {number} width - The desired width.
|
||||
* @param {number} height - The desired height.
|
||||
*/
|
||||
setSize: function (width, height) {
|
||||
|
||||
this.view.width = width;
|
||||
this.view.height = height;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Resets the camera back to 0,0 and un-follows any object it may have been tracking.
|
||||
* Also immediately resets any camera effects that may have been running such as
|
||||
* shake, flash or fade.
|
||||
*
|
||||
* @method Phaser.Camera#reset
|
||||
*/
|
||||
reset: function () {
|
||||
|
||||
this.target = null;
|
||||
|
||||
this.view.x = 0;
|
||||
this.view.y = 0;
|
||||
|
||||
this._shake.duration = 0;
|
||||
|
||||
this.resetFX();
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Resets any active FX, such as a fade or flash and immediately clears it.
|
||||
* Useful to calling after a fade in order to remove the fade from the Stage.
|
||||
*
|
||||
* @method Phaser.Camera#resetFX
|
||||
*/
|
||||
resetFX: function () {
|
||||
|
||||
if (this.fx)
|
||||
{
|
||||
this.fx.clear();
|
||||
this.fx.alpha = 0;
|
||||
}
|
||||
|
||||
this._fxDuration = 0;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.Camera.prototype.constructor = Phaser.Camera;
|
||||
|
||||
/**
|
||||
* The Cameras x coordinate. This value is automatically clamped if it falls outside of the World bounds.
|
||||
* @name Phaser.Camera#x
|
||||
* @property {number} x - Gets or sets the cameras x position.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Camera.prototype, "x", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.view.x;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.view.x = value;
|
||||
|
||||
if (this.bounds)
|
||||
{
|
||||
this.checkBounds();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The Cameras y coordinate. This value is automatically clamped if it falls outside of the World bounds.
|
||||
* @name Phaser.Camera#y
|
||||
* @property {number} y - Gets or sets the cameras y position.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Camera.prototype, "y", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.view.y;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.view.y = value;
|
||||
|
||||
if (this.bounds)
|
||||
{
|
||||
this.checkBounds();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The Cameras position. This value is automatically clamped if it falls outside of the World bounds.
|
||||
* @name Phaser.Camera#position
|
||||
* @property {Phaser.Point} position - Gets or sets the cameras xy position using Phaser.Point object.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Camera.prototype, "position", {
|
||||
|
||||
get: function () {
|
||||
|
||||
this._position.set(this.view.x, this.view.y);
|
||||
|
||||
return this._position;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (typeof value.x !== "undefined") { this.view.x = value.x; }
|
||||
if (typeof value.y !== "undefined") { this.view.y = value.y; }
|
||||
|
||||
if (this.bounds)
|
||||
{
|
||||
this.checkBounds();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The Cameras width. By default this is the same as the Game size and should not be adjusted for now.
|
||||
* @name Phaser.Camera#width
|
||||
* @property {number} width - Gets or sets the cameras width.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Camera.prototype, "width", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.view.width;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.view.width = value;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The Cameras height. By default this is the same as the Game size and should not be adjusted for now.
|
||||
* @name Phaser.Camera#height
|
||||
* @property {number} height - Gets or sets the cameras height.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Camera.prototype, "height", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.view.height;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.view.height = value;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* The Cameras shake intensity.
|
||||
* @name Phaser.Camera#shakeIntensity
|
||||
* @property {number} shakeIntensity - Gets or sets the cameras shake intensity.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Camera.prototype, "shakeIntensity", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this._shake.intensity;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this._shake.intensity = value;
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -1,204 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Phaser.Create class is a collection of smaller helper methods that allow you to generate game content
|
||||
* quickly and easily, without the need for any external files. You can create textures for sprites and in
|
||||
* coming releases we'll add dynamic sound effect generation support as well (like sfxr).
|
||||
*
|
||||
* Access this via `Game.create` (`this.game.create` from within a State object)
|
||||
*
|
||||
* @class Phaser.Create
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - Game reference to the currently running game.
|
||||
*/
|
||||
Phaser.Create = function (game) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.BitmapData} bmd - The internal BitmapData Create uses to generate textures from.
|
||||
*/
|
||||
this.bmd = null;
|
||||
|
||||
/**
|
||||
* @property {HTMLCanvasElement} canvas - The canvas the BitmapData uses.
|
||||
*/
|
||||
this.canvas = null;
|
||||
|
||||
/**
|
||||
* @property {CanvasRenderingContext2D} context - The 2d context of the canvas.
|
||||
*/
|
||||
this.ctx = null;
|
||||
|
||||
/**
|
||||
* @property {array} palettes - A range of 16 color palettes for use with sprite generation.
|
||||
*/
|
||||
this.palettes = [
|
||||
{ 0: '#000', 1: '#9D9D9D', 2: '#FFF', 3: '#BE2633', 4: '#E06F8B', 5: '#493C2B', 6: '#A46422', 7: '#EB8931', 8: '#F7E26B', 9: '#2F484E', A: '#44891A', B: '#A3CE27', C: '#1B2632', D: '#005784', E: '#31A2F2', F: '#B2DCEF' },
|
||||
{ 0: '#000', 1: '#191028', 2: '#46af45', 3: '#a1d685', 4: '#453e78', 5: '#7664fe', 6: '#833129', 7: '#9ec2e8', 8: '#dc534b', 9: '#e18d79', A: '#d6b97b', B: '#e9d8a1', C: '#216c4b', D: '#d365c8', E: '#afaab9', F: '#f5f4eb' },
|
||||
{ 0: '#000', 1: '#2234d1', 2: '#0c7e45', 3: '#44aacc', 4: '#8a3622', 5: '#5c2e78', 6: '#aa5c3d', 7: '#b5b5b5', 8: '#5e606e', 9: '#4c81fb', A: '#6cd947', B: '#7be2f9', C: '#eb8a60', D: '#e23d69', E: '#ffd93f', F: '#fff' },
|
||||
{ 0: '#000', 1: '#fff', 2: '#8b4131', 3: '#7bbdc5', 4: '#8b41ac', 5: '#6aac41', 6: '#3931a4', 7: '#d5de73', 8: '#945a20', 9: '#5a4100', A: '#bd736a', B: '#525252', C: '#838383', D: '#acee8b', E: '#7b73de', F: '#acacac' },
|
||||
{ 0: '#000', 1: '#191028', 2: '#46af45', 3: '#a1d685', 4: '#453e78', 5: '#7664fe', 6: '#833129', 7: '#9ec2e8', 8: '#dc534b', 9: '#e18d79', A: '#d6b97b', B: '#e9d8a1', C: '#216c4b', D: '#d365c8', E: '#afaab9', F: '#fff' }
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* A 16 color palette by [Arne](http://androidarts.com/palette/16pal.htm)
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Create.PALETTE_ARNE = 0;
|
||||
|
||||
/**
|
||||
* A 16 color JMP inspired palette.
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Create.PALETTE_JMP = 1;
|
||||
|
||||
/**
|
||||
* A 16 color CGA inspired palette.
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Create.PALETTE_CGA = 2;
|
||||
|
||||
/**
|
||||
* A 16 color C64 inspired palette.
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Create.PALETTE_C64 = 3;
|
||||
|
||||
/**
|
||||
* A 16 color palette inspired by Japanese computers like the MSX.
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Create.PALETTE_JAPANESE_MACHINE = 4;
|
||||
|
||||
Phaser.Create.prototype = {
|
||||
|
||||
/**
|
||||
* Generates a new PIXI.Texture from the given data, which can be applied to a Sprite.
|
||||
*
|
||||
* This allows you to create game graphics quickly and easily, with no external files but that use actual proper images
|
||||
* rather than Phaser.Graphics objects, which are expensive to render and limited in scope.
|
||||
*
|
||||
* Each element of the array is a string holding the pixel color values, as mapped to one of the Phaser.Create PALETTE consts.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* `var data = [
|
||||
* ' 333 ',
|
||||
* ' 777 ',
|
||||
* 'E333E',
|
||||
* ' 333 ',
|
||||
* ' 3 3 '
|
||||
* ];`
|
||||
*
|
||||
* `game.create.texture('bob', data);`
|
||||
*
|
||||
* The above will create a new texture called `bob`, which will look like a little man wearing a hat. You can then use it
|
||||
* for sprites the same way you use any other texture: `game.add.sprite(0, 0, 'bob');`
|
||||
*
|
||||
* @method Phaser.Create#texture
|
||||
* @param {string} key - The key used to store this texture in the Phaser Cache.
|
||||
* @param {array} data - An array of pixel data.
|
||||
* @param {integer} [pixelWidth=8] - The width of each pixel.
|
||||
* @param {integer} [pixelHeight=8] - The height of each pixel.
|
||||
* @param {integer} [palette=0] - The palette to use when rendering the texture. One of the Phaser.Create.PALETTE consts.
|
||||
* @return {PIXI.Texture} The newly generated texture.
|
||||
*/
|
||||
texture: function (key, data, pixelWidth, pixelHeight, palette) {
|
||||
|
||||
if (pixelWidth === undefined) { pixelWidth = 8; }
|
||||
if (pixelHeight === undefined) { pixelHeight = pixelWidth; }
|
||||
if (palette === undefined) { palette = 0; }
|
||||
|
||||
var w = data[0].length * pixelWidth;
|
||||
var h = data.length * pixelHeight;
|
||||
|
||||
// No bmd? Let's make one
|
||||
if (this.bmd === null)
|
||||
{
|
||||
this.bmd = this.game.make.bitmapData();
|
||||
this.canvas = this.bmd.canvas;
|
||||
this.ctx = this.bmd.context;
|
||||
}
|
||||
|
||||
this.bmd.resize(w, h);
|
||||
this.bmd.clear();
|
||||
|
||||
// Draw it
|
||||
for (var y = 0; y < data.length; y++)
|
||||
{
|
||||
var row = data[y];
|
||||
|
||||
for (var x = 0; x < row.length; x++)
|
||||
{
|
||||
var d = row[x];
|
||||
|
||||
if (d !== '.' && d !== ' ')
|
||||
{
|
||||
this.ctx.fillStyle = this.palettes[palette][d];
|
||||
this.ctx.fillRect(x * pixelWidth, y * pixelHeight, pixelWidth, pixelHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.bmd.generateTexture(key);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a grid texture based on the given dimensions.
|
||||
*
|
||||
* @method Phaser.Create#grid
|
||||
* @param {string} key - The key used to store this texture in the Phaser Cache.
|
||||
* @param {integer} width - The width of the grid in pixels.
|
||||
* @param {integer} height - The height of the grid in pixels.
|
||||
* @param {integer} cellWidth - The width of the grid cells in pixels.
|
||||
* @param {integer} cellHeight - The height of the grid cells in pixels.
|
||||
* @param {string} color - The color to draw the grid lines in. Should be a Canvas supported color string like `#ff5500` or `rgba(200,50,3,0.5)`.
|
||||
* @return {PIXI.Texture} The newly generated texture.
|
||||
*/
|
||||
grid: function (key, width, height, cellWidth, cellHeight, color) {
|
||||
|
||||
// No bmd? Let's make one
|
||||
if (this.bmd === null)
|
||||
{
|
||||
this.bmd = this.game.make.bitmapData();
|
||||
this.canvas = this.bmd.canvas;
|
||||
this.ctx = this.bmd.context;
|
||||
}
|
||||
|
||||
this.bmd.resize(width, height);
|
||||
|
||||
this.ctx.fillStyle = color;
|
||||
|
||||
for (var y = 0; y < height; y += cellHeight)
|
||||
{
|
||||
this.ctx.fillRect(0, y, width, 1);
|
||||
}
|
||||
|
||||
for (var x = 0; x < width; x += cellWidth)
|
||||
{
|
||||
this.ctx.fillRect(x, 0, 1, height);
|
||||
}
|
||||
|
||||
return this.bmd.generateTexture(key);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.Create.prototype.constructor = Phaser.Create;
|
|
@ -1,300 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @author Mat Groves (@Doormat23)
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a base Filter class to use for any Phaser filter development.
|
||||
* If you want to make a custom filter, this should be your base class.
|
||||
*
|
||||
* The default uniforms, types and values for all Filters are:
|
||||
*
|
||||
* ```
|
||||
* resolution: { type: '2f', value: { x: 256, y: 256 }}
|
||||
* time: { type: '1f', value: 0 }
|
||||
* mouse: { type: '2f', value: { x: 0.0, y: 0.0 } }
|
||||
* date: { type: '4fv', value: [ d.getFullYear(), d.getMonth(), d.getDate(), d.getHours() *60 * 60 + d.getMinutes() * 60 + d.getSeconds() ] }
|
||||
* sampleRate: { type: '1f', value: 44100.0 }
|
||||
* iChannel0: { type: 'sampler2D', value: null, textureData: { repeat: true } }
|
||||
* iChannel1: { type: 'sampler2D', value: null, textureData: { repeat: true } }
|
||||
* iChannel2: { type: 'sampler2D', value: null, textureData: { repeat: true } }
|
||||
* iChannel3: { type: 'sampler2D', value: null, textureData: { repeat: true } }
|
||||
* ```
|
||||
*
|
||||
* The vast majority of filters (including all of those that ship with Phaser) use fragment shaders, and
|
||||
* therefore only work in WebGL and are not supported by Canvas at all.
|
||||
*
|
||||
* @class Phaser.Filter
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {object} [uniforms] - Uniform mappings object. The uniforms are added on the default uniforms, or replace them if the keys are the same.
|
||||
* @param {Array|string} [fragmentSrc] - The fragment shader code. Either an array, one element per line of code, or a string.
|
||||
*/
|
||||
Phaser.Filter = function (game, uniforms, fragmentSrc)
|
||||
{
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {number} type - The const type of this object, either Phaser.WEBGL_FILTER or Phaser.CANVAS_FILTER.
|
||||
* @default
|
||||
*/
|
||||
this.type = Phaser.WEBGL_FILTER;
|
||||
|
||||
/**
|
||||
* An array of passes - some filters contain a few steps this array simply stores the steps in a linear fashion.
|
||||
* For example the blur filter has two passes blurX and blurY.
|
||||
* @property {array} passes - An array of filter objects.
|
||||
* @private
|
||||
*/
|
||||
this.passes = [ this ];
|
||||
|
||||
/**
|
||||
* @property {array} shaders - Array an array of shaders.
|
||||
* @private
|
||||
*/
|
||||
this.shaders = [];
|
||||
|
||||
/**
|
||||
* @property {boolean} dirty - Internal PIXI var.
|
||||
* @default
|
||||
*/
|
||||
this.dirty = true;
|
||||
|
||||
/**
|
||||
* @property {number} padding - Internal PIXI var.
|
||||
* @default
|
||||
*/
|
||||
this.padding = 0;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} prevPoint - The previous position of the pointer (we don't update the uniform if the same)
|
||||
*/
|
||||
this.prevPoint = new Phaser.Point();
|
||||
|
||||
/*
|
||||
* The supported types are: 1f, 1fv, 1i, 2f, 2fv, 2i, 2iv, 3f, 3fv, 3i, 3iv, 4f, 4fv, 4i, 4iv, mat2, mat3, mat4 and sampler2D.
|
||||
*/
|
||||
|
||||
var d = new Date();
|
||||
|
||||
/**
|
||||
* @property {object} uniforms - Default uniform mappings. Compatible with ShaderToy and GLSLSandbox.
|
||||
*/
|
||||
this.uniforms = {
|
||||
|
||||
resolution: { type: '2f', value: { x: 256, y: 256 }},
|
||||
time: { type: '1f', value: 0 },
|
||||
mouse: { type: '2f', value: { x: 0.0, y: 0.0 } },
|
||||
date: { type: '4fv', value: [ d.getFullYear(), d.getMonth(), d.getDate(), d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds() ] },
|
||||
sampleRate: { type: '1f', value: 44100.0 },
|
||||
iChannel0: { type: 'sampler2D', value: null, textureData: { repeat: true } },
|
||||
iChannel1: { type: 'sampler2D', value: null, textureData: { repeat: true } },
|
||||
iChannel2: { type: 'sampler2D', value: null, textureData: { repeat: true } },
|
||||
iChannel3: { type: 'sampler2D', value: null, textureData: { repeat: true } }
|
||||
|
||||
};
|
||||
|
||||
// Copy over / replace any passed in the constructor
|
||||
if (uniforms)
|
||||
{
|
||||
for (var key in uniforms)
|
||||
{
|
||||
this.uniforms[key] = uniforms[key];
|
||||
}
|
||||
}
|
||||
|
||||
// If fragmentSrc is a string, split it based on new-lines into an array
|
||||
if (typeof fragmentSrc === 'string')
|
||||
{
|
||||
fragmentSrc = fragmentSrc.split('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {array|string} fragmentSrc - The fragment shader code.
|
||||
*/
|
||||
this.fragmentSrc = fragmentSrc || [];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.prototype = {
|
||||
|
||||
/**
|
||||
* This should be over-ridden. Will receive a variable number of arguments.
|
||||
*
|
||||
* @method Phaser.Filter#init
|
||||
*/
|
||||
init: function ()
|
||||
{
|
||||
|
||||
// This should be over-ridden. Will receive a variable number of arguments.
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the resolution uniforms on the filter.
|
||||
*
|
||||
* @method Phaser.Filter#setResolution
|
||||
* @param {number} width - The width of the display.
|
||||
* @param {number} height - The height of the display.
|
||||
*/
|
||||
setResolution: function (width, height)
|
||||
{
|
||||
this.uniforms.resolution.value.x = width;
|
||||
this.uniforms.resolution.value.y = height;
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates the filter.
|
||||
*
|
||||
* @method Phaser.Filter#update
|
||||
* @param {Phaser.Pointer} [pointer] - A Pointer object to use for the filter. The coordinates are mapped to the mouse uniform.
|
||||
*/
|
||||
update: function (pointer)
|
||||
{
|
||||
if (pointer)
|
||||
{
|
||||
var x = pointer.x / this.game.width;
|
||||
var y = 1 - pointer.y / this.game.height;
|
||||
|
||||
if (x !== this.prevPoint.x || y !== this.prevPoint.y)
|
||||
{
|
||||
this.uniforms.mouse.value.x = x.toFixed(2);
|
||||
this.uniforms.mouse.value.y = y.toFixed(2);
|
||||
this.prevPoint.set(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
this.uniforms.time.value = this.game.time.totalElapsedSeconds();
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Phaser.Image object using a blank texture and assigns
|
||||
* this Filter to it. The image is then added to the world.
|
||||
*
|
||||
* If you don't provide width and height values then Filter.width and Filter.height are used.
|
||||
*
|
||||
* If you do provide width and height values then this filter will be resized to match those
|
||||
* values.
|
||||
*
|
||||
* @method Phaser.Filter#addToWorld
|
||||
* @param {number} [x=0] - The x coordinate to place the Image at.
|
||||
* @param {number} [y=0] - The y coordinate to place the Image at.
|
||||
* @param {number} [width] - The width of the Image. If not specified (or null) it will use Filter.width. If specified Filter.width will be set to this value.
|
||||
* @param {number} [height] - The height of the Image. If not specified (or null) it will use Filter.height. If specified Filter.height will be set to this value.
|
||||
* @param {number} [anchorX=0] - Set the x anchor point of the Image. A value between 0 and 1, where 0 is the top-left and 1 is bottom-right.
|
||||
* @param {number} [anchorY=0] - Set the y anchor point of the Image. A value between 0 and 1, where 0 is the top-left and 1 is bottom-right.
|
||||
* @return {Phaser.Image} The newly added Image object.
|
||||
*/
|
||||
addToWorld: function (x, y, width, height, anchorX, anchorY)
|
||||
{
|
||||
if (anchorX === undefined) { anchorX = 0; }
|
||||
if (anchorY === undefined) { anchorY = 0; }
|
||||
|
||||
if (width !== undefined && width !== null)
|
||||
{
|
||||
this.width = width;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = this.width;
|
||||
}
|
||||
|
||||
if (height !== undefined && height !== null)
|
||||
{
|
||||
this.height = height;
|
||||
}
|
||||
else
|
||||
{
|
||||
height = this.height;
|
||||
}
|
||||
|
||||
var image = this.game.add.image(x, y, '__default');
|
||||
|
||||
image.width = width;
|
||||
image.height = height;
|
||||
|
||||
image.anchor.set(anchorX, anchorY);
|
||||
|
||||
image.filters = [ this ];
|
||||
|
||||
return image;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Syncs the uniforms between the class object and the shaders.
|
||||
*
|
||||
* @method Phaser.Filter#syncUniforms
|
||||
*/
|
||||
syncUniforms: function ()
|
||||
{
|
||||
for (var i = 0; i < this.shaders.length; i++)
|
||||
{
|
||||
this.shaders[i].dirty = true;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Clear down this Filter and null out references to game.
|
||||
*
|
||||
* @method Phaser.Filter#destroy
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.passes.length = 0;
|
||||
this.shaders.length = 0;
|
||||
this.fragmentSrc.length = 0;
|
||||
|
||||
this.game = null;
|
||||
this.uniforms = null;
|
||||
this.prevPoint = null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.prototype.constructor = Phaser.Filter;
|
||||
|
||||
/**
|
||||
* @name Phaser.Filter#width
|
||||
* @property {number} width - The width (resolution uniform)
|
||||
*/
|
||||
Object.defineProperty(Phaser.Filter.prototype, 'width', {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.uniforms.resolution.value.x;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.uniforms.resolution.value.x = value;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.Filter#height
|
||||
* @property {number} height - The height (resolution uniform)
|
||||
*/
|
||||
Object.defineProperty(Phaser.Filter.prototype, 'height', {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.uniforms.resolution.value.y;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.uniforms.resolution.value.y = value;
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -1,327 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* WARNING: This is an EXPERIMENTAL class. The API will change significantly in the coming versions and is incomplete.
|
||||
* Please try to avoid using in production games with a long time to build.
|
||||
* This is also why the documentation is incomplete.
|
||||
*
|
||||
* FlexGrid is a a responsive grid manager that works in conjunction with the ScaleManager RESIZE scaling mode and FlexLayers
|
||||
* to provide for game object positioning in a responsive manner.
|
||||
*
|
||||
* @class Phaser.FlexGrid
|
||||
* @constructor
|
||||
* @param {Phaser.ScaleManager} manager - The ScaleManager.
|
||||
* @param {number} width - The width of the game.
|
||||
* @param {number} height - The height of the game.
|
||||
*/
|
||||
Phaser.FlexGrid = function (manager, width, height) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
this.game = manager.game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.ScaleManager} manager - A reference to the ScaleManager.
|
||||
*/
|
||||
this.manager = manager;
|
||||
|
||||
// The perfect dimensions on which everything else is based
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
this.boundsCustom = new Phaser.Rectangle(0, 0, width, height);
|
||||
this.boundsFluid = new Phaser.Rectangle(0, 0, width, height);
|
||||
this.boundsFull = new Phaser.Rectangle(0, 0, width, height);
|
||||
this.boundsNone = new Phaser.Rectangle(0, 0, width, height);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} position -
|
||||
* @readonly
|
||||
*/
|
||||
this.positionCustom = new Phaser.Point(0, 0);
|
||||
this.positionFluid = new Phaser.Point(0, 0);
|
||||
this.positionFull = new Phaser.Point(0, 0);
|
||||
this.positionNone = new Phaser.Point(0, 0);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} scaleFactor - The scale factor based on the game dimensions vs. the scaled dimensions.
|
||||
* @readonly
|
||||
*/
|
||||
this.scaleCustom = new Phaser.Point(1, 1);
|
||||
this.scaleFluid = new Phaser.Point(1, 1);
|
||||
this.scaleFluidInversed = new Phaser.Point(1, 1);
|
||||
this.scaleFull = new Phaser.Point(1, 1);
|
||||
this.scaleNone = new Phaser.Point(1, 1);
|
||||
|
||||
this.customWidth = 0;
|
||||
this.customHeight = 0;
|
||||
this.customOffsetX = 0;
|
||||
this.customOffsetY = 0;
|
||||
|
||||
this.ratioH = width / height;
|
||||
this.ratioV = height / width;
|
||||
|
||||
this.multiplier = 0;
|
||||
|
||||
this.layers = [];
|
||||
|
||||
};
|
||||
|
||||
Phaser.FlexGrid.prototype = {
|
||||
|
||||
/**
|
||||
* Sets the core game size. This resets the w/h parameters and bounds.
|
||||
*
|
||||
* @method Phaser.FlexGrid#setSize
|
||||
* @param {number} width - The new dimensions.
|
||||
* @param {number} height - The new dimensions.
|
||||
*/
|
||||
setSize: function (width, height) {
|
||||
|
||||
// These are locked and don't change until setSize is called again
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
this.ratioH = width / height;
|
||||
this.ratioV = height / width;
|
||||
|
||||
this.scaleNone = new Phaser.Point(1, 1);
|
||||
|
||||
this.boundsNone.width = this.width;
|
||||
this.boundsNone.height = this.height;
|
||||
|
||||
this.refresh();
|
||||
|
||||
},
|
||||
|
||||
// Need ability to create your own layers with custom scaling, etc.
|
||||
|
||||
/**
|
||||
* A custom layer is centered on the game and maintains its aspect ratio as it scales up and down.
|
||||
*
|
||||
* @method Phaser.FlexGrid#createCustomLayer
|
||||
* @param {number} width - Width of this layer in pixels.
|
||||
* @param {number} height - Height of this layer in pixels.
|
||||
* @param {PIXI.DisplayObject[]} [children] - An array of children that are used to populate the FlexLayer.
|
||||
* @return {Phaser.FlexLayer} The Layer object.
|
||||
*/
|
||||
createCustomLayer: function (width, height, children, addToWorld) {
|
||||
|
||||
if (addToWorld === undefined) { addToWorld = true; }
|
||||
|
||||
this.customWidth = width;
|
||||
this.customHeight = height;
|
||||
|
||||
this.boundsCustom.width = width;
|
||||
this.boundsCustom.height = height;
|
||||
|
||||
var layer = new Phaser.FlexLayer(this, this.positionCustom, this.boundsCustom, this.scaleCustom);
|
||||
|
||||
if (addToWorld)
|
||||
{
|
||||
this.game.world.add(layer);
|
||||
}
|
||||
|
||||
this.layers.push(layer);
|
||||
|
||||
if (typeof children !== 'undefined' && typeof children !== null)
|
||||
{
|
||||
layer.addMultiple(children);
|
||||
}
|
||||
|
||||
return layer;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* A fluid layer is centered on the game and maintains its aspect ratio as it scales up and down.
|
||||
*
|
||||
* @method Phaser.FlexGrid#createFluidLayer
|
||||
* @param {array} [children] - An array of children that are used to populate the FlexLayer.
|
||||
* @return {Phaser.FlexLayer} The Layer object.
|
||||
*/
|
||||
createFluidLayer: function (children, addToWorld) {
|
||||
|
||||
if (addToWorld === undefined) { addToWorld = true; }
|
||||
|
||||
var layer = new Phaser.FlexLayer(this, this.positionFluid, this.boundsFluid, this.scaleFluid);
|
||||
|
||||
if (addToWorld)
|
||||
{
|
||||
this.game.world.add(layer);
|
||||
}
|
||||
|
||||
this.layers.push(layer);
|
||||
|
||||
if (typeof children !== 'undefined' && typeof children !== null)
|
||||
{
|
||||
layer.addMultiple(children);
|
||||
}
|
||||
|
||||
return layer;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* A full layer is placed at 0,0 and extends to the full size of the game. Children are scaled according to the fluid ratios.
|
||||
*
|
||||
* @method Phaser.FlexGrid#createFullLayer
|
||||
* @param {array} [children] - An array of children that are used to populate the FlexLayer.
|
||||
* @return {Phaser.FlexLayer} The Layer object.
|
||||
*/
|
||||
createFullLayer: function (children) {
|
||||
|
||||
var layer = new Phaser.FlexLayer(this, this.positionFull, this.boundsFull, this.scaleFluid);
|
||||
|
||||
this.game.world.add(layer);
|
||||
|
||||
this.layers.push(layer);
|
||||
|
||||
if (typeof children !== 'undefined')
|
||||
{
|
||||
layer.addMultiple(children);
|
||||
}
|
||||
|
||||
return layer;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* A fixed layer is centered on the game and is the size of the required dimensions and is never scaled.
|
||||
*
|
||||
* @method Phaser.FlexGrid#createFixedLayer
|
||||
* @param {PIXI.DisplayObject[]} [children] - An array of children that are used to populate the FlexLayer.
|
||||
* @return {Phaser.FlexLayer} The Layer object.
|
||||
*/
|
||||
createFixedLayer: function (children) {
|
||||
|
||||
var layer = new Phaser.FlexLayer(this, this.positionNone, this.boundsNone, this.scaleNone);
|
||||
|
||||
this.game.world.add(layer);
|
||||
|
||||
this.layers.push(layer);
|
||||
|
||||
if (typeof children !== 'undefined')
|
||||
{
|
||||
layer.addMultiple(children);
|
||||
}
|
||||
|
||||
return layer;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Resets the layer children references
|
||||
*
|
||||
* @method Phaser.FlexGrid#reset
|
||||
*/
|
||||
reset: function () {
|
||||
|
||||
var i = this.layers.length;
|
||||
|
||||
while (i--)
|
||||
{
|
||||
if (!this.layers[i].persist)
|
||||
{
|
||||
// Remove references to this class
|
||||
this.layers[i].position = null;
|
||||
this.layers[i].scale = null;
|
||||
this.layers.slice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when the game container changes dimensions.
|
||||
*
|
||||
* @method Phaser.FlexGrid#onResize
|
||||
* @param {number} width - The new width of the game container.
|
||||
* @param {number} height - The new height of the game container.
|
||||
*/
|
||||
onResize: function (width, height) {
|
||||
|
||||
this.ratioH = width / height;
|
||||
this.ratioV = height / width;
|
||||
|
||||
this.refresh(width, height);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates all internal vars such as the bounds and scale values.
|
||||
*
|
||||
* @method Phaser.FlexGrid#refresh
|
||||
*/
|
||||
refresh: function () {
|
||||
|
||||
this.multiplier = Math.min((this.manager.height / this.height), (this.manager.width / this.width));
|
||||
|
||||
this.boundsFluid.width = Math.round(this.width * this.multiplier);
|
||||
this.boundsFluid.height = Math.round(this.height * this.multiplier);
|
||||
|
||||
this.scaleFluid.set(this.boundsFluid.width / this.width, this.boundsFluid.height / this.height);
|
||||
this.scaleFluidInversed.set(this.width / this.boundsFluid.width, this.height / this.boundsFluid.height);
|
||||
|
||||
this.scaleFull.set(this.boundsFull.width / this.width, this.boundsFull.height / this.height);
|
||||
|
||||
this.boundsFull.width = Math.round(this.manager.width * this.scaleFluidInversed.x);
|
||||
this.boundsFull.height = Math.round(this.manager.height * this.scaleFluidInversed.y);
|
||||
|
||||
this.boundsFluid.centerOn(this.manager.bounds.centerX, this.manager.bounds.centerY);
|
||||
this.boundsNone.centerOn(this.manager.bounds.centerX, this.manager.bounds.centerY);
|
||||
|
||||
this.positionFluid.set(this.boundsFluid.x, this.boundsFluid.y);
|
||||
this.positionNone.set(this.boundsNone.x, this.boundsNone.y);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Fits a sprites width to the bounds.
|
||||
*
|
||||
* @method Phaser.FlexGrid#fitSprite
|
||||
* @param {Phaser.Sprite} sprite - The Sprite to fit.
|
||||
*/
|
||||
fitSprite: function (sprite) {
|
||||
|
||||
this.manager.scaleSprite(sprite);
|
||||
|
||||
sprite.x = this.manager.bounds.centerX;
|
||||
sprite.y = this.manager.bounds.centerY;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Call in the render function to output the bounds rects.
|
||||
*
|
||||
* @method Phaser.FlexGrid#debug
|
||||
*/
|
||||
debug: function () {
|
||||
|
||||
// for (var i = 0; i < this.layers.length; i++)
|
||||
// {
|
||||
// this.layers[i].debug();
|
||||
// }
|
||||
|
||||
// this.game.debug.text(this.boundsFull.width + ' x ' + this.boundsFull.height, this.boundsFull.x + 4, this.boundsFull.y + 16);
|
||||
// this.game.debug.geom(this.boundsFull, 'rgba(0,0,255,0.9', false);
|
||||
|
||||
this.game.debug.text(this.boundsFluid.width + ' x ' + this.boundsFluid.height, this.boundsFluid.x + 4, this.boundsFluid.y + 16);
|
||||
this.game.debug.geom(this.boundsFluid, 'rgba(255,0,0,0.9', false);
|
||||
|
||||
// this.game.debug.text(this.boundsNone.width + ' x ' + this.boundsNone.height, this.boundsNone.x + 4, this.boundsNone.y + 16);
|
||||
// this.game.debug.geom(this.boundsNone, 'rgba(0,255,0,0.9', false);
|
||||
|
||||
// this.game.debug.text(this.boundsCustom.width + ' x ' + this.boundsCustom.height, this.boundsCustom.x + 4, this.boundsCustom.y + 16);
|
||||
// this.game.debug.geom(this.boundsCustom, 'rgba(255,255,0,0.9', false);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.FlexGrid.prototype.constructor = Phaser.FlexGrid;
|
|
@ -1,115 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* WARNING: This is an EXPERIMENTAL class. The API will change significantly in the coming versions and is incomplete.
|
||||
* Please try to avoid using in production games with a long time to build.
|
||||
* This is also why the documentation is incomplete.
|
||||
*
|
||||
* A responsive grid layer.
|
||||
*
|
||||
* @class Phaser.FlexLayer
|
||||
* @extends Phaser.Group
|
||||
* @constructor
|
||||
* @param {Phaser.FlexGrid} manager - The FlexGrid that owns this FlexLayer.
|
||||
* @param {Phaser.Point} position - A reference to the Point object used for positioning.
|
||||
* @param {Phaser.Rectangle} bounds - A reference to the Rectangle used for the layer bounds.
|
||||
* @param {Phaser.Point} scale - A reference to the Point object used for layer scaling.
|
||||
*/
|
||||
Phaser.FlexLayer = function (manager, position, bounds, scale) {
|
||||
|
||||
Phaser.Group.call(this, manager.game, null, '__flexLayer' + manager.game.rnd.uuid(), false);
|
||||
|
||||
/**
|
||||
* @property {Phaser.ScaleManager} scale - A reference to the ScaleManager.
|
||||
*/
|
||||
this.manager = manager.manager;
|
||||
|
||||
/**
|
||||
* @property {Phaser.FlexGrid} grid - A reference to the FlexGrid that owns this layer.
|
||||
*/
|
||||
this.grid = manager;
|
||||
|
||||
/**
|
||||
* Should the FlexLayer remain through a State swap?
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.persist = false;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} position
|
||||
*/
|
||||
this.position = position;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Rectangle} bounds
|
||||
*/
|
||||
this.bounds = bounds;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} scale
|
||||
*/
|
||||
this.scale = scale;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} topLeft
|
||||
*/
|
||||
this.topLeft = bounds.topLeft;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} topMiddle
|
||||
*/
|
||||
this.topMiddle = new Phaser.Point(bounds.halfWidth, 0);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} topRight
|
||||
*/
|
||||
this.topRight = bounds.topRight;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} bottomLeft
|
||||
*/
|
||||
this.bottomLeft = bounds.bottomLeft;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} bottomMiddle
|
||||
*/
|
||||
this.bottomMiddle = new Phaser.Point(bounds.halfWidth, bounds.bottom);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} bottomRight
|
||||
*/
|
||||
this.bottomRight = bounds.bottomRight;
|
||||
|
||||
};
|
||||
|
||||
Phaser.FlexLayer.prototype = Object.create(Phaser.Group.prototype);
|
||||
Phaser.FlexLayer.prototype.constructor = Phaser.FlexLayer;
|
||||
|
||||
/**
|
||||
* Resize.
|
||||
*
|
||||
* @method Phaser.FlexLayer#resize
|
||||
*/
|
||||
Phaser.FlexLayer.prototype.resize = function () {
|
||||
};
|
||||
|
||||
/**
|
||||
* Debug.
|
||||
*
|
||||
* @method Phaser.FlexLayer#debug
|
||||
*/
|
||||
Phaser.FlexLayer.prototype.debug = function () {
|
||||
|
||||
this.game.debug.text(this.bounds.width + ' x ' + this.bounds.height, this.bounds.x + 4, this.bounds.y + 16);
|
||||
this.game.debug.geom(this.bounds, 'rgba(0,0,255,0.9', false);
|
||||
|
||||
this.game.debug.geom(this.topLeft, 'rgba(255,255,255,0.9');
|
||||
this.game.debug.geom(this.topMiddle, 'rgba(255,255,255,0.9');
|
||||
this.game.debug.geom(this.topRight, 'rgba(255,255,255,0.9');
|
||||
|
||||
};
|
|
@ -1,227 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
|
||||
Phaser.Game = function (width, height, renderType, parent, stateConfig)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.resolution = 1;
|
||||
|
||||
this.renderType = renderType;
|
||||
this.renderer = null;
|
||||
this.canvas = null;
|
||||
this.context = null;
|
||||
|
||||
/**
|
||||
* @property {string|HTMLElement} parent - The Games DOM parent.
|
||||
* @default
|
||||
*/
|
||||
this.parent = parent;
|
||||
|
||||
this.isBooted = false;
|
||||
this.isRunning = false;
|
||||
|
||||
/**
|
||||
* @property {Phaser.RequestAnimationFrame} raf - Automatically handles the core game loop via requestAnimationFrame or setTimeout
|
||||
* @protected
|
||||
*/
|
||||
this.raf = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.TextureManager} textures - Reference to the Phaser Texture Manager.
|
||||
*/
|
||||
this.textures = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.UpdateManager} updates - Reference to the Phaser Update Manager.
|
||||
*/
|
||||
this.updates = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Cache} cache - Reference to the assets cache.
|
||||
*/
|
||||
this.cache = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Input} input - Reference to the input manager
|
||||
*/
|
||||
this.input = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.StateManager} state - The StateManager.
|
||||
*/
|
||||
this.state = new Phaser.StateManager(this, stateConfig);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Device} device - Contains device information and capabilities.
|
||||
*/
|
||||
this.device = Phaser.Device;
|
||||
|
||||
this.rnd = new Phaser.RandomDataGenerator([ (Date.now() * Math.random()).toString() ]);
|
||||
|
||||
this.device.whenReady(this.boot, this);
|
||||
|
||||
};
|
||||
|
||||
Phaser.Game.prototype.constructor = Phaser.Game;
|
||||
|
||||
Phaser.Game.prototype = {
|
||||
|
||||
boot: function ()
|
||||
{
|
||||
if (this.isBooted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Inject any new Factory helpers that exist in the build
|
||||
for (var gameobject in Phaser.GameObject)
|
||||
{
|
||||
if (Phaser.GameObject[gameobject].hasOwnProperty('FACTORY_KEY'))
|
||||
{
|
||||
var key = Phaser.GameObject[gameobject]['FACTORY_KEY'];
|
||||
|
||||
Phaser.GameObject.Factory.prototype[key] = Phaser.GameObject[gameobject]['FACTORY_ADD'];
|
||||
}
|
||||
}
|
||||
|
||||
this.isBooted = true;
|
||||
|
||||
this.setUpRenderer();
|
||||
this.showDebugHeader();
|
||||
|
||||
// Global
|
||||
// this.scale = new Phaser.ScaleManager(this, this.width, this.height);
|
||||
|
||||
this.scale = { offset: { x: 0, y: 0 } };
|
||||
this.time = { time: function () { return Date.now(); } };
|
||||
|
||||
this.textures = new Phaser.TextureManager(this);
|
||||
this.cache = new Phaser.Cache(this);
|
||||
this.input = new Phaser.Input(this);
|
||||
|
||||
this.input.boot();
|
||||
|
||||
this.state.boot();
|
||||
|
||||
this.isRunning = true;
|
||||
|
||||
this.rafHandle = window.requestAnimationFrame(this.step.bind(this));
|
||||
},
|
||||
|
||||
// timestamp = DOMHighResTimeStamp
|
||||
step: function (timestamp)
|
||||
{
|
||||
this.input.update();
|
||||
|
||||
this.state.step(timestamp);
|
||||
|
||||
this.rafHandle = window.requestAnimationFrame(this.step.bind(this));
|
||||
},
|
||||
|
||||
/**
|
||||
* Displays a Phaser version debug header in the console.
|
||||
*
|
||||
* @method Phaser.Game#showDebugHeader
|
||||
* @protected
|
||||
*/
|
||||
showDebugHeader: function ()
|
||||
{
|
||||
if (Phaser.hideBanner)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var c = (this.renderType === Phaser.CANVAS) ? 'Canvas' : 'WebGL';
|
||||
|
||||
if (!this.device.ie)
|
||||
{
|
||||
var args = [
|
||||
'%c %c %c %c %c Phaser v' + Phaser.VERSION + ' / ' + c + ' %c http://phaser.io',
|
||||
'background: #ff0000',
|
||||
'background: #ffff00',
|
||||
'background: #00ff00',
|
||||
'background: #00ffff',
|
||||
'color: #ffffff; background: #000;',
|
||||
'background: #fff'
|
||||
];
|
||||
|
||||
console.log.apply(console, args);
|
||||
}
|
||||
else if (window['console'])
|
||||
{
|
||||
console.log('Phaser v' + Phaser.VERSION + ' / http://phaser.io');
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the device is capable of using the requested renderer and sets it up or an alternative if not.
|
||||
*
|
||||
* @method Phaser.Game#setUpRenderer
|
||||
* @protected
|
||||
*/
|
||||
setUpRenderer: function ()
|
||||
{
|
||||
// if (this.config['canvas'])
|
||||
// {
|
||||
// this.canvas = this.config['canvas'];
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
this.canvas = Phaser.Canvas.create(this, this.width, this.height, '', true);
|
||||
// }
|
||||
|
||||
// if (this.config['canvasStyle'])
|
||||
// {
|
||||
// this.canvas.style = this.config['canvasStyle'];
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.canvas.style['-webkit-full-screen'] = 'width: 100%; height: 100%';
|
||||
// }
|
||||
|
||||
if (this.renderType === Phaser.HEADLESS || this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && !this.device.webGL))
|
||||
{
|
||||
if (this.device.canvas)
|
||||
{
|
||||
// They requested Canvas and their browser supports it
|
||||
this.renderType = Phaser.CANVAS;
|
||||
|
||||
this.renderer = new Phaser.Renderer.Canvas(this);
|
||||
|
||||
this.context = this.renderer.context;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Error('Phaser.Game - Cannot create Canvas or WebGL context, aborting.');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// They requested WebGL and their browser supports it
|
||||
|
||||
this.renderType = Phaser.WEBGL;
|
||||
|
||||
this.renderer = new Phaser.Renderer.WebGL(this);
|
||||
|
||||
this.context = null;
|
||||
|
||||
// Move to renderer class
|
||||
// this.canvas.addEventListener('webglcontextlost', this.contextLost.bind(this), false);
|
||||
// this.canvas.addEventListener('webglcontextrestored', this.contextRestored.bind(this), false);
|
||||
}
|
||||
|
||||
if (this.renderType !== Phaser.HEADLESS)
|
||||
{
|
||||
Phaser.Canvas.addToDOM(this.canvas, this.parent, false);
|
||||
Phaser.Canvas.setTouchAction(this.canvas);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,10 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
Phaser.MainLoop = function ()
|
||||
{
|
||||
|
||||
|
||||
};
|
|
@ -1,122 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a base Plugin template to use for any Phaser plugin development.
|
||||
*
|
||||
* @class Phaser.Plugin
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {any} parent - The object that owns this plugin, usually Phaser.PluginManager.
|
||||
*/
|
||||
Phaser.Plugin = function (game, parent) {
|
||||
|
||||
if (parent === undefined) { parent = null; }
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {any} parent - The parent of this plugin. If added to the PluginManager the parent will be set to that, otherwise it will be null.
|
||||
*/
|
||||
this.parent = parent;
|
||||
|
||||
/**
|
||||
* @property {boolean} active - A Plugin with active=true has its preUpdate and update methods called by the parent, otherwise they are skipped.
|
||||
* @default
|
||||
*/
|
||||
this.active = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} visible - A Plugin with visible=true has its render and postRender methods called by the parent, otherwise they are skipped.
|
||||
* @default
|
||||
*/
|
||||
this.visible = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} hasPreUpdate - A flag to indicate if this plugin has a preUpdate method.
|
||||
* @default
|
||||
*/
|
||||
this.hasPreUpdate = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} hasUpdate - A flag to indicate if this plugin has an update method.
|
||||
* @default
|
||||
*/
|
||||
this.hasUpdate = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} hasPostUpdate - A flag to indicate if this plugin has a postUpdate method.
|
||||
* @default
|
||||
*/
|
||||
this.hasPostUpdate = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} hasRender - A flag to indicate if this plugin has a render method.
|
||||
* @default
|
||||
*/
|
||||
this.hasRender = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} hasPostRender - A flag to indicate if this plugin has a postRender method.
|
||||
* @default
|
||||
*/
|
||||
this.hasPostRender = false;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Plugin.prototype = {
|
||||
|
||||
/**
|
||||
* Pre-update is called at the very start of the update cycle, before any other subsystems have been updated (including Physics).
|
||||
* It is only called if active is set to true.
|
||||
* @method Phaser.Plugin#preUpdate
|
||||
*/
|
||||
preUpdate: function () {
|
||||
},
|
||||
|
||||
/**
|
||||
* Update is called after all the core subsystems (Input, Tweens, Sound, etc) and the State have updated, but before the render.
|
||||
* It is only called if active is set to true.
|
||||
* @method Phaser.Plugin#update
|
||||
*/
|
||||
update: function () {
|
||||
},
|
||||
|
||||
/**
|
||||
* Render is called right after the Game Renderer completes, but before the State.render.
|
||||
* It is only called if visible is set to true.
|
||||
* @method Phaser.Plugin#render
|
||||
*/
|
||||
render: function () {
|
||||
},
|
||||
|
||||
/**
|
||||
* Post-render is called after the Game Renderer and State.render have run.
|
||||
* It is only called if visible is set to true.
|
||||
* @method Phaser.Plugin#postRender
|
||||
*/
|
||||
postRender: function () {
|
||||
},
|
||||
|
||||
/**
|
||||
* Clear down this Plugin and null out references
|
||||
* @method Phaser.Plugin#destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
|
||||
this.game = null;
|
||||
this.parent = null;
|
||||
this.active = false;
|
||||
this.visible = false;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.Plugin.prototype.constructor = Phaser.Plugin;
|
|
@ -1,294 +0,0 @@
|
|||
/* jshint newcap: false */
|
||||
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Plugin Manager is responsible for the loading, running and unloading of Phaser Plugins.
|
||||
*
|
||||
* @class Phaser.PluginManager
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
Phaser.PluginManager = function(game) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Plugin[]} plugins - An array of all the plugins being managed by this PluginManager.
|
||||
*/
|
||||
this.plugins = [];
|
||||
|
||||
/**
|
||||
* @property {number} _len - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._len = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _i - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._i = 0;
|
||||
|
||||
};
|
||||
|
||||
Phaser.PluginManager.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new Plugin into the PluginManager.
|
||||
* The Plugin must have 2 properties: game and parent. Plugin.game is set to the game reference the PluginManager uses, and parent is set to the PluginManager.
|
||||
*
|
||||
* @method Phaser.PluginManager#add
|
||||
* @param {object|Phaser.Plugin} plugin - The Plugin to add into the PluginManager. This can be a function or an existing object.
|
||||
* @param {...*} parameter - Additional arguments that will be passed to the Plugin.init method.
|
||||
* @return {Phaser.Plugin} The Plugin that was added to the manager.
|
||||
*/
|
||||
add: function (plugin) {
|
||||
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
var result = false;
|
||||
|
||||
// Prototype?
|
||||
if (typeof plugin === 'function')
|
||||
{
|
||||
plugin = new plugin(this.game, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin.game = this.game;
|
||||
plugin.parent = this;
|
||||
}
|
||||
|
||||
// Check for methods now to avoid having to do this every loop
|
||||
if (typeof plugin['preUpdate'] === 'function')
|
||||
{
|
||||
plugin.hasPreUpdate = true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (typeof plugin['update'] === 'function')
|
||||
{
|
||||
plugin.hasUpdate = true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (typeof plugin['postUpdate'] === 'function')
|
||||
{
|
||||
plugin.hasPostUpdate = true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (typeof plugin['render'] === 'function')
|
||||
{
|
||||
plugin.hasRender = true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (typeof plugin['postRender'] === 'function')
|
||||
{
|
||||
plugin.hasPostRender = true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
// The plugin must have at least one of the above functions to be added to the PluginManager.
|
||||
if (result)
|
||||
{
|
||||
if (plugin.hasPreUpdate || plugin.hasUpdate || plugin.hasPostUpdate)
|
||||
{
|
||||
plugin.active = true;
|
||||
}
|
||||
|
||||
if (plugin.hasRender || plugin.hasPostRender)
|
||||
{
|
||||
plugin.visible = true;
|
||||
}
|
||||
|
||||
this._len = this.plugins.push(plugin);
|
||||
|
||||
// Allows plugins to run potentially destructive code outside of the constructor, and only if being added to the PluginManager
|
||||
if (typeof plugin['init'] === 'function')
|
||||
{
|
||||
plugin.init.apply(plugin, args);
|
||||
}
|
||||
|
||||
return plugin;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove a Plugin from the PluginManager. It calls Plugin.destroy on the plugin before removing it from the manager.
|
||||
*
|
||||
* @method Phaser.PluginManager#remove
|
||||
* @param {Phaser.Plugin} plugin - The plugin to be removed.
|
||||
* @param {boolean} [destroy=true] - Call destroy on the plugin that is removed?
|
||||
*/
|
||||
remove: function (plugin, destroy) {
|
||||
|
||||
if (destroy === undefined) { destroy = true; }
|
||||
|
||||
this._i = this._len;
|
||||
|
||||
while (this._i--)
|
||||
{
|
||||
if (this.plugins[this._i] === plugin)
|
||||
{
|
||||
if (destroy)
|
||||
{
|
||||
plugin.destroy();
|
||||
}
|
||||
|
||||
this.plugins.splice(this._i, 1);
|
||||
this._len--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove all Plugins from the PluginManager. It calls Plugin.destroy on every plugin before removing it from the manager.
|
||||
*
|
||||
* @method Phaser.PluginManager#removeAll
|
||||
*/
|
||||
removeAll: function() {
|
||||
|
||||
this._i = this._len;
|
||||
|
||||
while (this._i--)
|
||||
{
|
||||
this.plugins[this._i].destroy();
|
||||
}
|
||||
|
||||
this.plugins.length = 0;
|
||||
this._len = 0;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Pre-update is called at the very start of the update cycle, before any other subsystems have been updated (including Physics).
|
||||
* It only calls plugins who have active=true.
|
||||
*
|
||||
* @method Phaser.PluginManager#preUpdate
|
||||
*/
|
||||
preUpdate: function () {
|
||||
|
||||
this._i = this._len;
|
||||
|
||||
while (this._i--)
|
||||
{
|
||||
if (this.plugins[this._i].active && this.plugins[this._i].hasPreUpdate)
|
||||
{
|
||||
this.plugins[this._i].preUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Update is called after all the core subsystems (Input, Tweens, Sound, etc) and the State have updated, but before the render.
|
||||
* It only calls plugins who have active=true.
|
||||
*
|
||||
* @method Phaser.PluginManager#update
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
this._i = this._len;
|
||||
|
||||
while (this._i--)
|
||||
{
|
||||
if (this.plugins[this._i].active && this.plugins[this._i].hasUpdate)
|
||||
{
|
||||
this.plugins[this._i].update();
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* PostUpdate is the last thing to be called before the world render.
|
||||
* In particular, it is called after the world postUpdate, which means the camera has been adjusted.
|
||||
* It only calls plugins who have active=true.
|
||||
*
|
||||
* @method Phaser.PluginManager#postUpdate
|
||||
*/
|
||||
postUpdate: function () {
|
||||
|
||||
this._i = this._len;
|
||||
|
||||
while (this._i--)
|
||||
{
|
||||
if (this.plugins[this._i].active && this.plugins[this._i].hasPostUpdate)
|
||||
{
|
||||
this.plugins[this._i].postUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Render is called right after the Game Renderer completes, but before the State.render.
|
||||
* It only calls plugins who have visible=true.
|
||||
*
|
||||
* @method Phaser.PluginManager#render
|
||||
*/
|
||||
render: function () {
|
||||
|
||||
this._i = this._len;
|
||||
|
||||
while (this._i--)
|
||||
{
|
||||
if (this.plugins[this._i].visible && this.plugins[this._i].hasRender)
|
||||
{
|
||||
this.plugins[this._i].render();
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Post-render is called after the Game Renderer and State.render have run.
|
||||
* It only calls plugins who have visible=true.
|
||||
*
|
||||
* @method Phaser.PluginManager#postRender
|
||||
*/
|
||||
postRender: function () {
|
||||
|
||||
this._i = this._len;
|
||||
|
||||
while (this._i--)
|
||||
{
|
||||
if (this.plugins[this._i].visible && this.plugins[this._i].hasPostRender)
|
||||
{
|
||||
this.plugins[this._i].postRender();
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Clear down this PluginManager, calls destroy on every plugin and nulls out references.
|
||||
*
|
||||
* @method Phaser.PluginManager#destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
|
||||
this.removeAll();
|
||||
|
||||
this.game = null;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.PluginManager.prototype.constructor = Phaser.PluginManager;
|
File diff suppressed because it is too large
Load diff
|
@ -1,505 +0,0 @@
|
|||
/**
|
||||
* @author Miller Medeiros http://millermedeiros.github.com/js-signals/
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Signals are what Phaser uses to handle events and event dispatching.
|
||||
* You can listen for a Signal by binding a callback / function to it.
|
||||
* This is done by using either `Signal.add` or `Signal.addOnce`.
|
||||
*
|
||||
* For example you can listen for a touch or click event from the Input Manager
|
||||
* by using its `onDown` Signal:
|
||||
*
|
||||
* `game.input.onDown.add(function() { ... });`
|
||||
*
|
||||
* Rather than inline your function, you can pass a reference:
|
||||
*
|
||||
* `game.input.onDown.add(clicked, this);`
|
||||
* `function clicked () { ... }`
|
||||
*
|
||||
* In this case the second argument (`this`) is the context in which your function should be called.
|
||||
*
|
||||
* Now every time the InputManager dispatches the `onDown` signal (or event), your function
|
||||
* will be called.
|
||||
*
|
||||
* Very often a Signal will send arguments to your function.
|
||||
* This is specific to the Signal itself.
|
||||
* If you're unsure then check the documentation, or failing that simply do:
|
||||
*
|
||||
* `Signal.add(function() { console.log(arguments); })`
|
||||
*
|
||||
* and it will log all of the arguments your function received from the Signal.
|
||||
*
|
||||
* Sprites have lots of default signals you can listen to in their Events class, such as:
|
||||
*
|
||||
* `sprite.events.onKilled`
|
||||
*
|
||||
* Which is called automatically whenever the Sprite is killed.
|
||||
* There are lots of other events, see the Events component for a list.
|
||||
*
|
||||
* As well as listening to pre-defined Signals you can also create your own:
|
||||
*
|
||||
* `var mySignal = new Phaser.Signal();`
|
||||
*
|
||||
* This creates a new Signal. You can bind a callback to it:
|
||||
*
|
||||
* `mySignal.add(myCallback, this);`
|
||||
*
|
||||
* and then finally when ready you can dispatch the Signal:
|
||||
*
|
||||
* `mySignal.dispatch(your arguments);`
|
||||
*
|
||||
* And your callback will be invoked. See the dispatch method for more details.
|
||||
*
|
||||
* @class Phaser.Signal
|
||||
* @constructor
|
||||
*/
|
||||
Phaser.Signal = function () {};
|
||||
|
||||
Phaser.Signal.prototype = {
|
||||
|
||||
/**
|
||||
* @property {?Array.<Phaser.SignalBinding>} _bindings - Internal variable.
|
||||
* @private
|
||||
*/
|
||||
_bindings: null,
|
||||
|
||||
/**
|
||||
* @property {any} _prevParams - Internal variable.
|
||||
* @private
|
||||
*/
|
||||
_prevParams: null,
|
||||
|
||||
/**
|
||||
* Memorize the previously dispatched event?
|
||||
*
|
||||
* If an event has been memorized it is automatically dispatched when a new listener is added with {@link #add} or {@link #addOnce}.
|
||||
* Use {@link #forget} to clear any currently memorized event.
|
||||
*
|
||||
* @property {boolean} memorize
|
||||
*/
|
||||
memorize: false,
|
||||
|
||||
/**
|
||||
* @property {boolean} _shouldPropagate
|
||||
* @private
|
||||
*/
|
||||
_shouldPropagate: true,
|
||||
|
||||
/**
|
||||
* Is the Signal active? Only active signals will broadcast dispatched events.
|
||||
*
|
||||
* Setting this property during a dispatch will only affect the next dispatch. To stop the propagation of a signal from a listener use {@link #halt}.
|
||||
*
|
||||
* @property {boolean} active
|
||||
* @default
|
||||
*/
|
||||
active: true,
|
||||
|
||||
/**
|
||||
* @property {function} _boundDispatch - The bound dispatch function, if any.
|
||||
* @private
|
||||
*/
|
||||
_boundDispatch: false,
|
||||
|
||||
/**
|
||||
* @method Phaser.Signal#validateListener
|
||||
* @param {function} listener - Signal handler function.
|
||||
* @param {string} fnName - Function name.
|
||||
* @private
|
||||
*/
|
||||
validateListener: function (listener, fnName) {
|
||||
|
||||
if (typeof listener !== 'function')
|
||||
{
|
||||
throw new Error('Phaser.Signal: listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName));
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.Signal#_registerListener
|
||||
* @private
|
||||
* @param {function} listener - Signal handler function.
|
||||
* @param {boolean} isOnce - Should the listener only be called once?
|
||||
* @param {object} [listenerContext] - The context under which the listener is invoked.
|
||||
* @param {number} [priority] - The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
|
||||
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
|
||||
*/
|
||||
_registerListener: function (listener, isOnce, listenerContext, priority, args) {
|
||||
|
||||
var prevIndex = this._indexOfListener(listener, listenerContext);
|
||||
var binding;
|
||||
|
||||
if (prevIndex !== -1)
|
||||
{
|
||||
binding = this._bindings[prevIndex];
|
||||
|
||||
if (binding.isOnce() !== isOnce)
|
||||
{
|
||||
throw new Error('You cannot add' + (isOnce ? '' : 'Once') + '() then add' + (!isOnce ? '' : 'Once') + '() the same listener without removing the relationship first.');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority, args);
|
||||
this._addBinding(binding);
|
||||
}
|
||||
|
||||
if (this.memorize && this._prevParams)
|
||||
{
|
||||
binding.execute(this._prevParams);
|
||||
}
|
||||
|
||||
return binding;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.Signal#_addBinding
|
||||
* @private
|
||||
* @param {Phaser.SignalBinding} binding - An Object representing the binding between the Signal and listener.
|
||||
*/
|
||||
_addBinding: function (binding) {
|
||||
|
||||
if (!this._bindings)
|
||||
{
|
||||
this._bindings = [];
|
||||
}
|
||||
|
||||
// Simplified insertion sort
|
||||
var n = this._bindings.length;
|
||||
|
||||
do {
|
||||
n--;
|
||||
}
|
||||
while (this._bindings[n] && binding._priority <= this._bindings[n]._priority);
|
||||
|
||||
this._bindings.splice(n + 1, 0, binding);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.Signal#_indexOfListener
|
||||
* @private
|
||||
* @param {function} listener - Signal handler function.
|
||||
* @param {object} [context=null] - Signal handler function.
|
||||
* @return {number} The index of the listener within the private bindings array.
|
||||
*/
|
||||
_indexOfListener: function (listener, context) {
|
||||
|
||||
if (!this._bindings)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (context === undefined) { context = null; }
|
||||
|
||||
var n = this._bindings.length;
|
||||
var cur;
|
||||
|
||||
while (n--)
|
||||
{
|
||||
cur = this._bindings[n];
|
||||
|
||||
if (cur._listener === listener && cur.context === context)
|
||||
{
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if a specific listener is attached.
|
||||
*
|
||||
* @method Phaser.Signal#has
|
||||
* @param {function} listener - Signal handler function.
|
||||
* @param {object} [context] - Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @return {boolean} If Signal has the specified listener.
|
||||
*/
|
||||
has: function (listener, context) {
|
||||
|
||||
return this._indexOfListener(listener, context) !== -1;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add an event listener for this signal.
|
||||
*
|
||||
* An event listener is a callback with a related context and priority.
|
||||
*
|
||||
* You can optionally provide extra arguments which will be passed to the callback after any internal parameters.
|
||||
*
|
||||
* For example: `Phaser.Key.onDown` when dispatched will send the Phaser.Key object that caused the signal as the first parameter.
|
||||
* Any arguments you've specified after `priority` will be sent as well:
|
||||
*
|
||||
* `fireButton.onDown.add(shoot, this, 0, 'lazer', 100);`
|
||||
*
|
||||
* When onDown dispatches it will call the `shoot` callback passing it: `Phaser.Key, 'lazer', 100`.
|
||||
*
|
||||
* Where the first parameter is the one that Key.onDown dispatches internally and 'lazer',
|
||||
* and the value 100 were the custom arguments given in the call to 'add'.
|
||||
*
|
||||
* @method Phaser.Signal#add
|
||||
* @param {function} listener - The function to call when this Signal is dispatched.
|
||||
* @param {object} [listenerContext] - The context under which the listener will be executed (i.e. the object that should represent the `this` variable).
|
||||
* @param {number} [priority] - The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added (default = 0)
|
||||
* @param {...any} [args=(none)] - Additional arguments to pass to the callback (listener) function. They will be appended after any arguments usually dispatched.
|
||||
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
|
||||
*/
|
||||
add: function (listener, listenerContext, priority) {
|
||||
|
||||
this.validateListener(listener, 'add');
|
||||
|
||||
var args = [];
|
||||
|
||||
if (arguments.length > 3)
|
||||
{
|
||||
for (var i = 3; i < arguments.length; i++)
|
||||
{
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return this._registerListener(listener, false, listenerContext, priority, args);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a one-time listener - the listener is automatically removed after the first execution.
|
||||
*
|
||||
* If there is as {@link Phaser.Signal#memorize memorized} event then it will be dispatched and
|
||||
* the listener will be removed immediately.
|
||||
*
|
||||
* @method Phaser.Signal#addOnce
|
||||
* @param {function} listener - The function to call when this Signal is dispatched.
|
||||
* @param {object} [listenerContext] - The context under which the listener will be executed (i.e. the object that should represent the `this` variable).
|
||||
* @param {number} [priority] - The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added (default = 0)
|
||||
* @param {...any} [args=(none)] - Additional arguments to pass to the callback (listener) function. They will be appended after any arguments usually dispatched.
|
||||
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
|
||||
*/
|
||||
addOnce: function (listener, listenerContext, priority) {
|
||||
|
||||
this.validateListener(listener, 'addOnce');
|
||||
|
||||
var args = [];
|
||||
|
||||
if (arguments.length > 3)
|
||||
{
|
||||
for (var i = 3; i < arguments.length; i++)
|
||||
{
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return this._registerListener(listener, true, listenerContext, priority, args);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove a single event listener.
|
||||
*
|
||||
* @method Phaser.Signal#remove
|
||||
* @param {function} listener - Handler function that should be removed.
|
||||
* @param {object} [context=null] - Execution context (since you can add the same handler multiple times if executing in a different context).
|
||||
* @return {function} Listener handler function.
|
||||
*/
|
||||
remove: function (listener, context) {
|
||||
|
||||
this.validateListener(listener, 'remove');
|
||||
|
||||
var i = this._indexOfListener(listener, context);
|
||||
|
||||
if (i !== -1)
|
||||
{
|
||||
this._bindings[i]._destroy(); //no reason to a Phaser.SignalBinding exist if it isn't attached to a signal
|
||||
this._bindings.splice(i, 1);
|
||||
}
|
||||
|
||||
return listener;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove all event listeners.
|
||||
*
|
||||
* @method Phaser.Signal#removeAll
|
||||
* @param {object} [context=null] - If specified only listeners for the given context will be removed.
|
||||
*/
|
||||
removeAll: function (context) {
|
||||
|
||||
if (context === undefined) { context = null; }
|
||||
|
||||
if (!this._bindings)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var n = this._bindings.length;
|
||||
|
||||
while (n--)
|
||||
{
|
||||
if (context)
|
||||
{
|
||||
if (this._bindings[n].context === context)
|
||||
{
|
||||
this._bindings[n]._destroy();
|
||||
this._bindings.splice(n, 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this._bindings[n]._destroy();
|
||||
}
|
||||
}
|
||||
|
||||
if (!context)
|
||||
{
|
||||
this._bindings.length = 0;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the total number of listeners attached to this Signal.
|
||||
*
|
||||
* @method Phaser.Signal#getNumListeners
|
||||
* @return {integer} Number of listeners attached to the Signal.
|
||||
*/
|
||||
getNumListeners: function () {
|
||||
|
||||
return this._bindings ? this._bindings.length : 0;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Stop propagation of the event, blocking the dispatch to next listener on the queue.
|
||||
*
|
||||
* This should be called only during event dispatch as calling it before/after dispatch won't affect another broadcast.
|
||||
* See {@link #active} to enable/disable the signal entirely.
|
||||
*
|
||||
* @method Phaser.Signal#halt
|
||||
*/
|
||||
halt: function () {
|
||||
|
||||
this._shouldPropagate = false;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Dispatch / broadcast the event to all listeners.
|
||||
*
|
||||
* To create an instance-bound dispatch for this Signal, use {@link #boundDispatch}.
|
||||
*
|
||||
* @method Phaser.Signal#dispatch
|
||||
* @param {any} [params] - Parameters that should be passed to each handler.
|
||||
*/
|
||||
dispatch: function () {
|
||||
|
||||
if (!this.active || !this._bindings)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var paramsArr = Array.prototype.slice.call(arguments);
|
||||
var n = this._bindings.length;
|
||||
var bindings;
|
||||
|
||||
if (this.memorize)
|
||||
{
|
||||
this._prevParams = paramsArr;
|
||||
}
|
||||
|
||||
if (!n)
|
||||
{
|
||||
// Should come after memorize
|
||||
return;
|
||||
}
|
||||
|
||||
bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch
|
||||
this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch.
|
||||
|
||||
//execute all callbacks until end of the list or until a callback returns `false` or stops propagation
|
||||
//reverse loop since listeners with higher priority will be added at the end of the list
|
||||
do {
|
||||
n--;
|
||||
}
|
||||
while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Forget the currently {@link Phaser.Signal#memorize memorized} event, if any.
|
||||
*
|
||||
* @method Phaser.Signal#forget
|
||||
*/
|
||||
forget: function() {
|
||||
|
||||
if (this._prevParams)
|
||||
{
|
||||
this._prevParams = null;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Dispose the signal - no more events can be dispatched.
|
||||
*
|
||||
* This removes all event listeners and clears references to external objects.
|
||||
* Calling methods on a disposed objects results in undefined behavior.
|
||||
*
|
||||
* @method Phaser.Signal#dispose
|
||||
*/
|
||||
dispose: function () {
|
||||
|
||||
this.removeAll();
|
||||
|
||||
this._bindings = null;
|
||||
if (this._prevParams)
|
||||
{
|
||||
this._prevParams = null;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* A string representation of the object.
|
||||
*
|
||||
* @method Phaser.Signal#toString
|
||||
* @return {string} String representation of the object.
|
||||
*/
|
||||
toString: function () {
|
||||
|
||||
return '[Phaser.Signal active:'+ this.active +' numListeners:'+ this.getNumListeners() +']';
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a `dispatch` function that maintains a binding to the original Signal context.
|
||||
*
|
||||
* Use the resulting value if the dispatch function needs to be passed somewhere
|
||||
* or called independently of the Signal object.
|
||||
*
|
||||
* @memberof Phaser.Signal
|
||||
* @property {function} boundDispatch
|
||||
*/
|
||||
Object.defineProperty(Phaser.Signal.prototype, "boundDispatch", {
|
||||
|
||||
get: function () {
|
||||
var _this = this;
|
||||
return this._boundDispatch || (this._boundDispatch = function () {
|
||||
return _this.dispatch.apply(_this, arguments);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Phaser.Signal.prototype.constructor = Phaser.Signal;
|
|
@ -1,199 +0,0 @@
|
|||
/**
|
||||
* @author Miller Medeiros http://millermedeiros.github.com/js-signals/
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Object that represents a binding between a Signal and a listener function.
|
||||
* This is an internal constructor and shouldn't be created directly.
|
||||
* Inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes.
|
||||
*
|
||||
* @class Phaser.SignalBinding
|
||||
* @constructor
|
||||
* @param {Phaser.Signal} signal - Reference to Signal object that listener is currently bound to.
|
||||
* @param {function} listener - Handler function bound to the signal.
|
||||
* @param {boolean} isOnce - If binding should be executed just once.
|
||||
* @param {object} [listenerContext=null] - Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @param {number} [priority] - The priority level of the event listener. (default = 0).
|
||||
* @param {...any} [args=(none)] - Additional arguments to pass to the callback (listener) function. They will be appended after any arguments usually dispatched.
|
||||
*/
|
||||
Phaser.SignalBinding = function (signal, listener, isOnce, listenerContext, priority, args) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} _listener - Handler function bound to the signal.
|
||||
* @private
|
||||
*/
|
||||
this._listener = listener;
|
||||
|
||||
if (isOnce)
|
||||
{
|
||||
this._isOnce = true;
|
||||
}
|
||||
|
||||
if (listenerContext != null) /* not null/undefined */
|
||||
{
|
||||
this.context = listenerContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {Phaser.Signal} _signal - Reference to Signal object that listener is currently bound to.
|
||||
* @private
|
||||
*/
|
||||
this._signal = signal;
|
||||
|
||||
if (priority)
|
||||
{
|
||||
this._priority = priority;
|
||||
}
|
||||
|
||||
if (args && args.length)
|
||||
{
|
||||
this._args = args;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.SignalBinding.prototype = {
|
||||
|
||||
/**
|
||||
* @property {?object} context - Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
*/
|
||||
context: null,
|
||||
|
||||
/**
|
||||
* @property {boolean} _isOnce - If binding should be executed just once.
|
||||
* @private
|
||||
*/
|
||||
_isOnce: false,
|
||||
|
||||
/**
|
||||
* @property {number} _priority - Listener priority.
|
||||
* @private
|
||||
*/
|
||||
_priority: 0,
|
||||
|
||||
/**
|
||||
* @property {array} _args - Listener arguments.
|
||||
* @private
|
||||
*/
|
||||
_args: null,
|
||||
|
||||
/**
|
||||
* @property {number} callCount - The number of times the handler function has been called.
|
||||
*/
|
||||
callCount: 0,
|
||||
|
||||
/**
|
||||
* If binding is active and should be executed.
|
||||
* @property {boolean} active
|
||||
* @default
|
||||
*/
|
||||
active: true,
|
||||
|
||||
/**
|
||||
* Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute` (curried parameters).
|
||||
* @property {array|null} params
|
||||
* @default
|
||||
*/
|
||||
params: null,
|
||||
|
||||
/**
|
||||
* Call listener passing arbitrary parameters.
|
||||
* If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.
|
||||
* @method Phaser.SignalBinding#execute
|
||||
* @param {any[]} [paramsArr] - Array of parameters that should be passed to the listener.
|
||||
* @return {any} Value returned by the listener.
|
||||
*/
|
||||
execute: function(paramsArr) {
|
||||
|
||||
var handlerReturn, params;
|
||||
|
||||
if (this.active && !!this._listener)
|
||||
{
|
||||
params = this.params ? this.params.concat(paramsArr) : paramsArr;
|
||||
|
||||
if (this._args)
|
||||
{
|
||||
params = params.concat(this._args);
|
||||
}
|
||||
|
||||
handlerReturn = this._listener.apply(this.context, params);
|
||||
|
||||
this.callCount++;
|
||||
|
||||
if (this._isOnce)
|
||||
{
|
||||
this.detach();
|
||||
}
|
||||
}
|
||||
|
||||
return handlerReturn;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Detach binding from signal.
|
||||
* alias to: @see mySignal.remove(myBinding.getListener());
|
||||
* @method Phaser.SignalBinding#detach
|
||||
* @return {function|null} Handler function bound to the signal or `null` if binding was previously detached.
|
||||
*/
|
||||
detach: function () {
|
||||
return this.isBound() ? this._signal.remove(this._listener, this.context) : null;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.SignalBinding#isBound
|
||||
* @return {boolean} True if binding is still bound to the signal and has a listener.
|
||||
*/
|
||||
isBound: function () {
|
||||
return (!!this._signal && !!this._listener);
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.SignalBinding#isOnce
|
||||
* @return {boolean} If SignalBinding will only be executed once.
|
||||
*/
|
||||
isOnce: function () {
|
||||
return this._isOnce;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.SignalBinding#getListener
|
||||
* @return {function} Handler function bound to the signal.
|
||||
*/
|
||||
getListener: function () {
|
||||
return this._listener;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.SignalBinding#getSignal
|
||||
* @return {Phaser.Signal} Signal that listener is currently bound to.
|
||||
*/
|
||||
getSignal: function () {
|
||||
return this._signal;
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete instance properties
|
||||
* @method Phaser.SignalBinding#_destroy
|
||||
* @private
|
||||
*/
|
||||
_destroy: function () {
|
||||
delete this._signal;
|
||||
delete this._listener;
|
||||
delete this.context;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.SignalBinding#toString
|
||||
* @return {string} String representation of the object.
|
||||
*/
|
||||
toString: function () {
|
||||
return '[Phaser.SignalBinding isOnce:' + this._isOnce +', isBound:'+ this.isBound() +', active:' + this.active + ']';
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.SignalBinding.prototype.constructor = Phaser.SignalBinding;
|
|
@ -1,794 +0,0 @@
|
|||
/* jshint newcap: false */
|
||||
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The State Manager is responsible for loading, setting up and switching game states.
|
||||
*
|
||||
* @class Phaser.StateManager
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {Phaser.State|Object} [pendingState=null] - A State object to seed the manager with.
|
||||
*/
|
||||
Phaser.StateManager = function (game, pendingState) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {object} states - The object containing Phaser.States.
|
||||
*/
|
||||
this.states = {};
|
||||
|
||||
/**
|
||||
* @property {Phaser.State} _pendingState - The state to be switched to in the next frame.
|
||||
* @private
|
||||
*/
|
||||
this._pendingState = null;
|
||||
|
||||
if (typeof pendingState !== 'undefined' && pendingState !== null)
|
||||
{
|
||||
this._pendingState = pendingState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {boolean} _clearWorld - Clear the world when we switch state?
|
||||
* @private
|
||||
*/
|
||||
this._clearWorld = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} _clearCache - Clear the cache when we switch state?
|
||||
* @private
|
||||
*/
|
||||
this._clearCache = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} _created - Flag that sets if the State has been created or not.
|
||||
* @private
|
||||
*/
|
||||
this._created = false;
|
||||
|
||||
/**
|
||||
* @property {any[]} _args - Temporary container when you pass vars from one State to another.
|
||||
* @private
|
||||
*/
|
||||
this._args = [];
|
||||
|
||||
/**
|
||||
* @property {string} current - The current active State object.
|
||||
* @default
|
||||
*/
|
||||
this.current = '';
|
||||
|
||||
/**
|
||||
* onStateChange is a Phaser.Signal that is dispatched whenever the game changes state.
|
||||
*
|
||||
* It is dispatched only when the new state is started, which isn't usually at the same time as StateManager.start
|
||||
* is called because state swapping is done in sync with the game loop. It is dispatched *before* any of the new states
|
||||
* methods (such as preload and create) are called, and *after* the previous states shutdown method has been run.
|
||||
*
|
||||
* The callback you specify is sent two parameters: the string based key of the new state,
|
||||
* and the second parameter is the string based key of the old / previous state.
|
||||
*
|
||||
* @property {Phaser.Signal} onStateChange
|
||||
*/
|
||||
this.onStateChange = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* @property {function} onInitCallback - This is called when the state is set as the active state.
|
||||
* @default
|
||||
*/
|
||||
this.onInitCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onPreloadCallback - This is called when the state starts to load assets.
|
||||
* @default
|
||||
*/
|
||||
this.onPreloadCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onCreateCallback - This is called when the state preload has finished and creation begins.
|
||||
* @default
|
||||
*/
|
||||
this.onCreateCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onUpdateCallback - This is called when the state is updated, every game loop. It doesn't happen during preload (@see onLoadUpdateCallback).
|
||||
* @default
|
||||
*/
|
||||
this.onUpdateCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onRenderCallback - This is called post-render. It doesn't happen during preload (see onLoadRenderCallback).
|
||||
* @default
|
||||
*/
|
||||
this.onRenderCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onResizeCallback - This is called if ScaleManager.scalemode is RESIZE and a resize event occurs. It's passed the new width and height.
|
||||
* @default
|
||||
*/
|
||||
this.onResizeCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onPreRenderCallback - This is called before the state is rendered and before the stage is cleared but after all game objects have had their final properties adjusted.
|
||||
* @default
|
||||
*/
|
||||
this.onPreRenderCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onLoadUpdateCallback - This is called when the State is updated during the preload phase.
|
||||
* @default
|
||||
*/
|
||||
this.onLoadUpdateCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onLoadRenderCallback - This is called when the State is rendered during the preload phase.
|
||||
* @default
|
||||
*/
|
||||
this.onLoadRenderCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onPausedCallback - This is called when the game is paused.
|
||||
* @default
|
||||
*/
|
||||
this.onPausedCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onResumedCallback - This is called when the game is resumed from a paused state.
|
||||
* @default
|
||||
*/
|
||||
this.onResumedCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onPauseUpdateCallback - This is called every frame while the game is paused.
|
||||
* @default
|
||||
*/
|
||||
this.onPauseUpdateCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onShutDownCallback - This is called when the state is shut down (i.e. swapped to another state).
|
||||
* @default
|
||||
*/
|
||||
this.onShutDownCallback = null;
|
||||
|
||||
};
|
||||
|
||||
Phaser.StateManager.prototype = {
|
||||
|
||||
/**
|
||||
* The Boot handler is called by Phaser.Game when it first starts up.
|
||||
* @method Phaser.StateManager#boot
|
||||
* @private
|
||||
*/
|
||||
boot: function () {
|
||||
|
||||
this.game.onPause.add(this.pause, this);
|
||||
this.game.onResume.add(this.resume, this);
|
||||
|
||||
if (this._pendingState !== null && typeof this._pendingState !== 'string')
|
||||
{
|
||||
this.add('default', this._pendingState, true);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a new State into the StateManager. You must give each State a unique key by which you'll identify it.
|
||||
* The State can be either a Phaser.State object (or an object that extends it), a plain JavaScript object or a function.
|
||||
* If a function is given a new state object will be created by calling it.
|
||||
*
|
||||
* @method Phaser.StateManager#add
|
||||
* @param {string} key - A unique key you use to reference this state, i.e. "MainMenu", "Level1".
|
||||
* @param {Phaser.State|object|function} state - The state you want to switch to.
|
||||
* @param {boolean} [autoStart=false] - If true the State will be started immediately after adding it.
|
||||
*/
|
||||
add: function (key, state, autoStart) {
|
||||
|
||||
if (autoStart === undefined) { autoStart = false; }
|
||||
|
||||
var newState;
|
||||
|
||||
if (state instanceof Phaser.State)
|
||||
{
|
||||
newState = state;
|
||||
}
|
||||
else if (typeof state === 'object')
|
||||
{
|
||||
newState = state;
|
||||
newState.game = this.game;
|
||||
}
|
||||
else if (typeof state === 'function')
|
||||
{
|
||||
newState = new state(this.game);
|
||||
}
|
||||
|
||||
this.states[key] = newState;
|
||||
|
||||
if (autoStart)
|
||||
{
|
||||
if (this.game.isBooted)
|
||||
{
|
||||
this.start(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._pendingState = key;
|
||||
}
|
||||
}
|
||||
|
||||
return newState;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete the given state.
|
||||
* @method Phaser.StateManager#remove
|
||||
* @param {string} key - A unique key you use to reference this state, i.e. "MainMenu", "Level1".
|
||||
*/
|
||||
remove: function (key) {
|
||||
|
||||
if (this.current === key)
|
||||
{
|
||||
this.callbackContext = null;
|
||||
|
||||
this.onInitCallback = null;
|
||||
this.onShutDownCallback = null;
|
||||
|
||||
this.onPreloadCallback = null;
|
||||
this.onLoadRenderCallback = null;
|
||||
this.onLoadUpdateCallback = null;
|
||||
this.onCreateCallback = null;
|
||||
this.onUpdateCallback = null;
|
||||
this.onPreRenderCallback = null;
|
||||
this.onRenderCallback = null;
|
||||
this.onResizeCallback = null;
|
||||
this.onPausedCallback = null;
|
||||
this.onResumedCallback = null;
|
||||
this.onPauseUpdateCallback = null;
|
||||
}
|
||||
|
||||
delete this.states[key];
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Start the given State. If a State is already running then State.shutDown will be called (if it exists) before switching to the new State.
|
||||
*
|
||||
* @method Phaser.StateManager#start
|
||||
* @param {string} key - The key of the state you want to start.
|
||||
* @param {boolean} [clearWorld=true] - Clear everything in the world? This clears the World display list fully (but not the Stage, so if you've added your own objects to the Stage they will need managing directly)
|
||||
* @param {boolean} [clearCache=false] - Clear the Game.Cache? This purges out all loaded assets. The default is false and you must have clearWorld=true if you want to clearCache as well.
|
||||
* @param {...*} parameter - Additional parameters that will be passed to the State.init function (if it has one).
|
||||
*/
|
||||
start: function (key, clearWorld, clearCache) {
|
||||
|
||||
if (clearWorld === undefined) { clearWorld = true; }
|
||||
if (clearCache === undefined) { clearCache = false; }
|
||||
|
||||
if (this.checkState(key))
|
||||
{
|
||||
// Place the state in the queue. It will be started the next time the game loop begins.
|
||||
this._pendingState = key;
|
||||
this._clearWorld = clearWorld;
|
||||
this._clearCache = clearCache;
|
||||
|
||||
if (arguments.length > 3)
|
||||
{
|
||||
this._args = Array.prototype.splice.call(arguments, 3);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Restarts the current State. State.shutDown will be called (if it exists) before the State is restarted.
|
||||
*
|
||||
* @method Phaser.StateManager#restart
|
||||
* @param {boolean} [clearWorld=true] - Clear everything in the world? This clears the World display list fully (but not the Stage, so if you've added your own objects to the Stage they will need managing directly)
|
||||
* @param {boolean} [clearCache=false] - Clear the Game.Cache? This purges out all loaded assets. The default is false and you must have clearWorld=true if you want to clearCache as well.
|
||||
* @param {...*} parameter - Additional parameters that will be passed to the State.init function if it has one.
|
||||
*/
|
||||
restart: function (clearWorld, clearCache) {
|
||||
|
||||
if (clearWorld === undefined) { clearWorld = true; }
|
||||
if (clearCache === undefined) { clearCache = false; }
|
||||
|
||||
// Place the state in the queue. It will be started the next time the game loop starts.
|
||||
this._pendingState = this.current;
|
||||
this._clearWorld = clearWorld;
|
||||
this._clearCache = clearCache;
|
||||
|
||||
if (arguments.length > 2)
|
||||
{
|
||||
this._args = Array.prototype.slice.call(arguments, 2);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Used by onInit and onShutdown when those functions don't exist on the state
|
||||
* @method Phaser.StateManager#dummy
|
||||
* @private
|
||||
*/
|
||||
dummy: function () {
|
||||
},
|
||||
|
||||
/**
|
||||
* preUpdate is called right at the start of the game loop. It is responsible for changing to a new state that was requested previously.
|
||||
*
|
||||
* @method Phaser.StateManager#preUpdate
|
||||
*/
|
||||
preUpdate: function () {
|
||||
|
||||
if (this._pendingState && this.game.isBooted)
|
||||
{
|
||||
var previousStateKey = this.current;
|
||||
|
||||
// Already got a state running?
|
||||
this.clearCurrentState();
|
||||
|
||||
this.setCurrentState(this._pendingState);
|
||||
|
||||
this.onStateChange.dispatch(this.current, previousStateKey);
|
||||
|
||||
if (this.current !== this._pendingState)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._pendingState = null;
|
||||
}
|
||||
|
||||
// If StateManager.start has been called from the init of a State that ALSO has a preload, then
|
||||
// onPreloadCallback will be set, but must be ignored
|
||||
if (this.onPreloadCallback)
|
||||
{
|
||||
this.game.load.reset(true);
|
||||
this.onPreloadCallback.call(this.callbackContext, this.game);
|
||||
|
||||
// Is the loader empty?
|
||||
if (this.game.load.totalQueuedFiles() === 0 && this.game.load.totalQueuedPacks() === 0)
|
||||
{
|
||||
this.loadComplete();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Start the loader going as we have something in the queue
|
||||
this.game.load.start();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No init? Then there was nothing to load either
|
||||
this.loadComplete();
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* This method clears the current State, calling its shutdown callback. The process also removes any active tweens,
|
||||
* resets the camera, resets input, clears physics, removes timers and if set clears the world and cache too.
|
||||
*
|
||||
* @method Phaser.StateManager#clearCurrentState
|
||||
*/
|
||||
clearCurrentState: function () {
|
||||
|
||||
if (this.current)
|
||||
{
|
||||
if (this.onShutDownCallback)
|
||||
{
|
||||
this.onShutDownCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
|
||||
this.game.tweens.removeAll();
|
||||
|
||||
this.game.camera.reset();
|
||||
|
||||
this.game.input.reset(true);
|
||||
|
||||
this.game.physics.clear();
|
||||
|
||||
this.game.time.removeAll();
|
||||
|
||||
this.game.scale.reset(this._clearWorld);
|
||||
|
||||
if (this.game.debug)
|
||||
{
|
||||
this.game.debug.reset();
|
||||
}
|
||||
|
||||
if (this._clearWorld)
|
||||
{
|
||||
this.game.world.shutdown();
|
||||
|
||||
if (this._clearCache)
|
||||
{
|
||||
this.game.cache.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if a given phaser state is valid. A State is considered valid if it has at least one of the core functions: preload, create, update or render.
|
||||
*
|
||||
* @method Phaser.StateManager#checkState
|
||||
* @param {string} key - The key of the state you want to check.
|
||||
* @return {boolean} true if the State has the required functions, otherwise false.
|
||||
*/
|
||||
checkState: function (key) {
|
||||
|
||||
if (this.states[key])
|
||||
{
|
||||
if (this.states[key]['preload'] || this.states[key]['create'] || this.states[key]['update'] || this.states[key]['render'])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn("Invalid Phaser State object given. Must contain at least a one of the required functions: preload, create, update or render");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn("Phaser.StateManager - No state found with the key: " + key);
|
||||
return false;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Links game properties to the State given by the key.
|
||||
*
|
||||
* @method Phaser.StateManager#link
|
||||
* @param {string} key - State key.
|
||||
* @protected
|
||||
*/
|
||||
link: function (key) {
|
||||
|
||||
this.states[key].game = this.game;
|
||||
this.states[key].add = this.game.add;
|
||||
this.states[key].make = this.game.make;
|
||||
this.states[key].camera = this.game.camera;
|
||||
this.states[key].cache = this.game.cache;
|
||||
this.states[key].input = this.game.input;
|
||||
this.states[key].load = this.game.load;
|
||||
this.states[key].math = this.game.math;
|
||||
this.states[key].sound = this.game.sound;
|
||||
this.states[key].scale = this.game.scale;
|
||||
this.states[key].state = this;
|
||||
this.states[key].stage = this.game.stage;
|
||||
this.states[key].textures = this.game.textures;
|
||||
this.states[key].time = this.game.time;
|
||||
this.states[key].tweens = this.game.tweens;
|
||||
this.states[key].world = this.game.world;
|
||||
this.states[key].particles = this.game.particles;
|
||||
this.states[key].rnd = this.game.rnd;
|
||||
this.states[key].physics = this.game.physics;
|
||||
this.states[key].key = key;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Nulls all State level Phaser properties, including a reference to Game.
|
||||
*
|
||||
* @method Phaser.StateManager#unlink
|
||||
* @param {string} key - State key.
|
||||
* @protected
|
||||
*/
|
||||
unlink: function (key) {
|
||||
|
||||
if (this.states[key])
|
||||
{
|
||||
this.states[key].game = null;
|
||||
this.states[key].add = null;
|
||||
this.states[key].make = null;
|
||||
this.states[key].camera = null;
|
||||
this.states[key].cache = null;
|
||||
this.states[key].input = null;
|
||||
this.states[key].load = null;
|
||||
this.states[key].math = null;
|
||||
this.states[key].sound = null;
|
||||
this.states[key].scale = null;
|
||||
this.states[key].state = null;
|
||||
this.states[key].stage = null;
|
||||
this.states[key].textures = null;
|
||||
this.states[key].time = null;
|
||||
this.states[key].tweens = null;
|
||||
this.states[key].world = null;
|
||||
this.states[key].particles = null;
|
||||
this.states[key].rnd = null;
|
||||
this.states[key].physics = null;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the current State. Should not be called directly (use StateManager.start)
|
||||
*
|
||||
* @method Phaser.StateManager#setCurrentState
|
||||
* @param {string} key - State key.
|
||||
* @private
|
||||
*/
|
||||
setCurrentState: function (key)
|
||||
{
|
||||
this.callbackContext = this.states[key];
|
||||
|
||||
this.link(key);
|
||||
|
||||
// Used when the state is set as being the current active state
|
||||
this.onInitCallback = this.states[key]['init'] || this.dummy;
|
||||
|
||||
this.onPreloadCallback = this.states[key]['preload'] || null;
|
||||
this.onLoadRenderCallback = this.states[key]['loadRender'] || null;
|
||||
this.onLoadUpdateCallback = this.states[key]['loadUpdate'] || null;
|
||||
this.onCreateCallback = this.states[key]['create'] || null;
|
||||
this.onUpdateCallback = this.states[key]['update'] || null;
|
||||
this.onPreRenderCallback = this.states[key]['preRender'] || null;
|
||||
this.onRenderCallback = this.states[key]['render'] || null;
|
||||
this.onResizeCallback = this.states[key]['resize'] || null;
|
||||
this.onPausedCallback = this.states[key]['paused'] || null;
|
||||
this.onResumedCallback = this.states[key]['resumed'] || null;
|
||||
this.onPauseUpdateCallback = this.states[key]['pauseUpdate'] || null;
|
||||
|
||||
// Used when the state is no longer the current active state
|
||||
this.onShutDownCallback = this.states[key]['shutdown'] || this.dummy;
|
||||
|
||||
// Reset the physics system, but not on the first state start
|
||||
if (this.current !== '')
|
||||
{
|
||||
this.game.physics.reset();
|
||||
}
|
||||
|
||||
this.current = key;
|
||||
this._created = false;
|
||||
|
||||
// At this point key and pendingState should equal each other
|
||||
this.onInitCallback.apply(this.callbackContext, this._args);
|
||||
|
||||
// If they no longer do then the init callback hit StateManager.start
|
||||
if (key === this._pendingState)
|
||||
{
|
||||
this._args = [];
|
||||
}
|
||||
|
||||
this.game._kickstart = true;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the current State.
|
||||
*
|
||||
* @method Phaser.StateManager#getCurrentState
|
||||
* @return {Phaser.State}
|
||||
* @public
|
||||
*/
|
||||
getCurrentState: function() {
|
||||
return this.states[this.current];
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.StateManager#loadComplete
|
||||
* @protected
|
||||
*/
|
||||
loadComplete: function () {
|
||||
|
||||
// Make sure to do load-update one last time before state is set to _created
|
||||
if (this._created === false && this.onLoadUpdateCallback)
|
||||
{
|
||||
this.onLoadUpdateCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
|
||||
if (this._created === false && this.onCreateCallback)
|
||||
{
|
||||
this._created = true;
|
||||
this.onCreateCallback.call(this.callbackContext, this.game);
|
||||
this.game.updates.running = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._created = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.StateManager#pause
|
||||
* @protected
|
||||
*/
|
||||
pause: function () {
|
||||
|
||||
if (this._created && this.onPausedCallback)
|
||||
{
|
||||
this.onPausedCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.StateManager#resume
|
||||
* @protected
|
||||
*/
|
||||
resume: function () {
|
||||
|
||||
if (this._created && this.onResumedCallback)
|
||||
{
|
||||
this.onResumedCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.StateManager#update
|
||||
* @protected
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
if (this._created)
|
||||
{
|
||||
if (this.onUpdateCallback)
|
||||
{
|
||||
this.onUpdateCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.onLoadUpdateCallback)
|
||||
{
|
||||
this.onLoadUpdateCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.StateManager#pauseUpdate
|
||||
* @protected
|
||||
*/
|
||||
pauseUpdate: function () {
|
||||
|
||||
if (this._created)
|
||||
{
|
||||
if (this.onPauseUpdateCallback)
|
||||
{
|
||||
this.onPauseUpdateCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.onLoadUpdateCallback)
|
||||
{
|
||||
this.onLoadUpdateCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.StateManager#preRender
|
||||
* @protected
|
||||
* @param {number} elapsedTime - The time elapsed since the last update.
|
||||
*/
|
||||
preRender: function (elapsedTime) {
|
||||
|
||||
if (this._created && this.onPreRenderCallback)
|
||||
{
|
||||
this.onPreRenderCallback.call(this.callbackContext, this.game, elapsedTime);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.StateManager#resize
|
||||
* @protected
|
||||
*/
|
||||
resize: function (width, height) {
|
||||
|
||||
if (this.onResizeCallback)
|
||||
{
|
||||
this.onResizeCallback.call(this.callbackContext, width, height);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.StateManager#render
|
||||
* @protected
|
||||
*/
|
||||
render: function () {
|
||||
|
||||
if (this._created)
|
||||
{
|
||||
if (this.onRenderCallback)
|
||||
{
|
||||
if (this.game.renderType === Phaser.CANVAS)
|
||||
{
|
||||
// this.game.context.save();
|
||||
this.game.context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
this.onRenderCallback.call(this.callbackContext, this.game);
|
||||
// this.game.context.restore();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.onRenderCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.onLoadRenderCallback)
|
||||
{
|
||||
this.onLoadRenderCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes all StateManager callback references to the State object, nulls the game reference and clears the States object.
|
||||
* You don't recover from this without rebuilding the Phaser instance again.
|
||||
* @method Phaser.StateManager#destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
|
||||
this._clearWorld = true;
|
||||
this._clearCache = true;
|
||||
|
||||
this.clearCurrentState();
|
||||
|
||||
this.callbackContext = null;
|
||||
|
||||
this.onInitCallback = null;
|
||||
this.onShutDownCallback = null;
|
||||
|
||||
this.onPreloadCallback = null;
|
||||
this.onLoadRenderCallback = null;
|
||||
this.onLoadUpdateCallback = null;
|
||||
this.onCreateCallback = null;
|
||||
this.onUpdateCallback = null;
|
||||
this.onRenderCallback = null;
|
||||
this.onPausedCallback = null;
|
||||
this.onResumedCallback = null;
|
||||
this.onPauseUpdateCallback = null;
|
||||
|
||||
this.game = null;
|
||||
this.states = {};
|
||||
this._pendingState = null;
|
||||
this.current = '';
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.StateManager.prototype.constructor = Phaser.StateManager;
|
||||
|
||||
/**
|
||||
* @name Phaser.StateManager#created
|
||||
* @property {boolean} created - True if the current state has had its `create` method run (if it has one, if not this is true by default).
|
||||
* @readOnly
|
||||
*/
|
||||
Object.defineProperty(Phaser.StateManager.prototype, "created", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this._created;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* "It's like nailing jelly to a kitten" - Gary Penn
|
||||
*/
|
|
@ -1,361 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* "This world is but a canvas to our imagination." - Henry David Thoreau
|
||||
*
|
||||
* A game has only one world. The world is an abstract place in which all game objects live. It is not bound
|
||||
* by stage limits and can be any size. You look into the world via cameras. All game objects live within
|
||||
* the world at world-based coordinates. By default a world is created the same size as your Stage.
|
||||
*
|
||||
* @class Phaser.World
|
||||
* @extends Phaser.Group
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - Reference to the current game instance.
|
||||
*/
|
||||
Phaser.World = function (game) {
|
||||
|
||||
Phaser.Group.call(this, game, null, '__world', false);
|
||||
|
||||
/**
|
||||
* The World has no fixed size, but it does have a bounds outside of which objects are no longer considered as being "in world" and you should use this to clean-up the display list and purge dead objects.
|
||||
* By default we set the Bounds to be from 0,0 to Game.width,Game.height. I.e. it will match the size given to the game constructor with 0,0 representing the top-left of the display.
|
||||
* However 0,0 is actually the center of the world, and if you rotate or scale the world all of that will happen from 0,0.
|
||||
* So if you want to make a game in which the world itself will rotate you should adjust the bounds so that 0,0 is the center point, i.e. set them to -1000,-1000,2000,2000 for a 2000x2000 sized world centered around 0,0.
|
||||
* @property {Phaser.Rectangle} bounds - Bound of this world that objects can not escape from.
|
||||
*/
|
||||
this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Camera} camera - Camera instance.
|
||||
*/
|
||||
this.camera = null;
|
||||
|
||||
/**
|
||||
* @property {boolean} _definedSize - True if the World has been given a specifically defined size (i.e. from a Tilemap or direct in code) or false if it's just matched to the Game dimensions.
|
||||
* @readonly
|
||||
*/
|
||||
this._definedSize = false;
|
||||
|
||||
/**
|
||||
* @property {number} width - The defined width of the World. Sometimes the bounds needs to grow larger than this (if you resize the game) but this retains the original requested dimension.
|
||||
*/
|
||||
this._width = game.width;
|
||||
|
||||
/**
|
||||
* @property {number} height - The defined height of the World. Sometimes the bounds needs to grow larger than this (if you resize the game) but this retains the original requested dimension.
|
||||
*/
|
||||
this._height = game.height;
|
||||
|
||||
this.game.state.onStateChange.add(this.stateChange, this);
|
||||
|
||||
};
|
||||
|
||||
Phaser.World.prototype = Object.create(Phaser.Group.prototype);
|
||||
Phaser.World.prototype.constructor = Phaser.World;
|
||||
|
||||
/**
|
||||
* Initialises the game world.
|
||||
*
|
||||
* @method Phaser.World#boot
|
||||
* @protected
|
||||
*/
|
||||
Phaser.World.prototype.boot = function () {
|
||||
|
||||
this.camera = new Phaser.Camera(this.game, 0, 0, 0, this.game.width, this.game.height);
|
||||
|
||||
this.game.stage.addChild(this);
|
||||
|
||||
this.camera.boot();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Called whenever the State changes or resets.
|
||||
*
|
||||
* It resets the world.x and world.y coordinates back to zero,
|
||||
* then resets the Camera.
|
||||
*
|
||||
* @method Phaser.World#stateChange
|
||||
* @protected
|
||||
*/
|
||||
Phaser.World.prototype.stateChange = function () {
|
||||
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
|
||||
this.camera.reset();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the size of this world and sets World.x/y to the given values
|
||||
* The Camera bounds and Physics bounds (if set) are also updated to match the new World bounds.
|
||||
*
|
||||
* @method Phaser.World#setBounds
|
||||
* @param {number} x - Top left most corner of the world.
|
||||
* @param {number} y - Top left most corner of the world.
|
||||
* @param {number} width - New width of the game world in pixels.
|
||||
* @param {number} height - New height of the game world in pixels.
|
||||
*/
|
||||
Phaser.World.prototype.setBounds = function (x, y, width, height) {
|
||||
|
||||
this._definedSize = true;
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
|
||||
this.bounds.setTo(x, y, width, height);
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
if (this.camera.bounds)
|
||||
{
|
||||
// The Camera can never be smaller than the game size
|
||||
this.camera.bounds.setTo(x, y, Math.max(width, this.game.width), Math.max(height, this.game.height));
|
||||
}
|
||||
|
||||
this.game.physics.setBoundsToWorld();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the size of this world. Note that this doesn't modify the world x/y coordinates, just the width and height.
|
||||
*
|
||||
* @method Phaser.World#resize
|
||||
* @param {number} width - New width of the game world in pixels.
|
||||
* @param {number} height - New height of the game world in pixels.
|
||||
*/
|
||||
Phaser.World.prototype.resize = function (width, height) {
|
||||
|
||||
// Don't ever scale the World bounds lower than the original requested dimensions if it's a defined world size
|
||||
|
||||
if (this._definedSize)
|
||||
{
|
||||
if (width < this._width)
|
||||
{
|
||||
width = this._width;
|
||||
}
|
||||
|
||||
if (height < this._height)
|
||||
{
|
||||
height = this._height;
|
||||
}
|
||||
}
|
||||
|
||||
this.bounds.width = width;
|
||||
this.bounds.height = height;
|
||||
|
||||
this.game.camera.setBoundsToWorld();
|
||||
|
||||
this.game.physics.setBoundsToWorld();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroyer of worlds.
|
||||
*
|
||||
* @method Phaser.World#shutdown
|
||||
*/
|
||||
Phaser.World.prototype.shutdown = function () {
|
||||
|
||||
// World is a Group, so run a soft destruction on this and all children.
|
||||
this.destroy(true, true);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* This will take the given game object and check if its x/y coordinates fall outside of the world bounds.
|
||||
* If they do it will reposition the object to the opposite side of the world, creating a wrap-around effect.
|
||||
* If sprite has a P2 body then the body (sprite.body) should be passed as first parameter to the function.
|
||||
*
|
||||
* Please understand there are limitations to this method. For example if you have scaled the World
|
||||
* then objects won't always be re-positioned correctly, and you'll need to employ your own wrapping function.
|
||||
*
|
||||
* @method Phaser.World#wrap
|
||||
* @param {Phaser.Sprite|Phaser.Image|Phaser.TileSprite|Phaser.Text} sprite - The object you wish to wrap around the world bounds.
|
||||
* @param {number} [padding=0] - Extra padding added equally to the sprite.x and y coordinates before checking if within the world bounds. Ignored if useBounds is true.
|
||||
* @param {boolean} [useBounds=false] - If useBounds is false wrap checks the object.x/y coordinates. If true it does a more accurate bounds check, which is more expensive.
|
||||
* @param {boolean} [horizontal=true] - If horizontal is false, wrap will not wrap the object.x coordinates horizontally.
|
||||
* @param {boolean} [vertical=true] - If vertical is false, wrap will not wrap the object.y coordinates vertically.
|
||||
*/
|
||||
Phaser.World.prototype.wrap = function (sprite, padding, useBounds, horizontal, vertical) {
|
||||
|
||||
if (padding === undefined) { padding = 0; }
|
||||
if (useBounds === undefined) { useBounds = false; }
|
||||
if (horizontal === undefined) { horizontal = true; }
|
||||
if (vertical === undefined) { vertical = true; }
|
||||
|
||||
if (!useBounds)
|
||||
{
|
||||
if (horizontal && sprite.x + padding < this.bounds.x)
|
||||
{
|
||||
sprite.x = this.bounds.right + padding;
|
||||
}
|
||||
else if (horizontal && sprite.x - padding > this.bounds.right)
|
||||
{
|
||||
sprite.x = this.bounds.left - padding;
|
||||
}
|
||||
|
||||
if (vertical && sprite.y + padding < this.bounds.top)
|
||||
{
|
||||
sprite.y = this.bounds.bottom + padding;
|
||||
}
|
||||
else if (vertical && sprite.y - padding > this.bounds.bottom)
|
||||
{
|
||||
sprite.y = this.bounds.top - padding;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.getBounds();
|
||||
|
||||
if (horizontal)
|
||||
{
|
||||
if ((sprite.x + sprite._currentBounds.width) < this.bounds.x)
|
||||
{
|
||||
sprite.x = this.bounds.right;
|
||||
}
|
||||
else if (sprite.x > this.bounds.right)
|
||||
{
|
||||
sprite.x = this.bounds.left;
|
||||
}
|
||||
}
|
||||
|
||||
if (vertical)
|
||||
{
|
||||
if ((sprite.y + sprite._currentBounds.height) < this.bounds.top)
|
||||
{
|
||||
sprite.y = this.bounds.bottom;
|
||||
}
|
||||
else if (sprite.y > this.bounds.bottom)
|
||||
{
|
||||
sprite.y = this.bounds.top;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @name Phaser.World#width
|
||||
* @property {number} width - Gets or sets the current width of the game world. The world can never be smaller than the game (canvas) dimensions.
|
||||
*/
|
||||
Object.defineProperty(Phaser.World.prototype, "width", {
|
||||
|
||||
get: function () {
|
||||
return this.bounds.width;
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value < this.game.width)
|
||||
{
|
||||
value = this.game.width;
|
||||
}
|
||||
|
||||
this.bounds.width = value;
|
||||
this._width = value;
|
||||
this._definedSize = true;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.World#height
|
||||
* @property {number} height - Gets or sets the current height of the game world. The world can never be smaller than the game (canvas) dimensions.
|
||||
*/
|
||||
Object.defineProperty(Phaser.World.prototype, "height", {
|
||||
|
||||
get: function () {
|
||||
return this.bounds.height;
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value < this.game.height)
|
||||
{
|
||||
value = this.game.height;
|
||||
}
|
||||
|
||||
this.bounds.height = value;
|
||||
this._height = value;
|
||||
this._definedSize = true;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.World#centerX
|
||||
* @property {number} centerX - Gets the X position corresponding to the center point of the world.
|
||||
* @readonly
|
||||
*/
|
||||
Object.defineProperty(Phaser.World.prototype, "centerX", {
|
||||
|
||||
get: function () {
|
||||
return this.bounds.halfWidth + this.bounds.x;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.World#centerY
|
||||
* @property {number} centerY - Gets the Y position corresponding to the center point of the world.
|
||||
* @readonly
|
||||
*/
|
||||
Object.defineProperty(Phaser.World.prototype, "centerY", {
|
||||
|
||||
get: function () {
|
||||
return this.bounds.halfHeight + this.bounds.y;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.World#randomX
|
||||
* @property {number} randomX - Gets a random integer which is lesser than or equal to the current width of the game world.
|
||||
* @readonly
|
||||
*/
|
||||
Object.defineProperty(Phaser.World.prototype, "randomX", {
|
||||
|
||||
get: function () {
|
||||
|
||||
if (this.bounds.x < 0)
|
||||
{
|
||||
return this.game.rnd.between(this.bounds.x, (this.bounds.width - Math.abs(this.bounds.x)));
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.game.rnd.between(this.bounds.x, this.bounds.width);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.World#randomY
|
||||
* @property {number} randomY - Gets a random integer which is lesser than or equal to the current height of the game world.
|
||||
* @readonly
|
||||
*/
|
||||
Object.defineProperty(Phaser.World.prototype, "randomY", {
|
||||
|
||||
get: function () {
|
||||
|
||||
if (this.bounds.y < 0)
|
||||
{
|
||||
return this.game.rnd.between(this.bounds.y, (this.bounds.height - Math.abs(this.bounds.y)));
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.game.rnd.between(this.bounds.y, this.bounds.height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -1,249 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The GameObjects Factory is a quick way to create many common game objects
|
||||
* using {@linkcode Phaser.Game#add `game.add`}.
|
||||
*
|
||||
* Created objects are _automatically added_ to the appropriate Manager, World, or manually specified parent Group.
|
||||
*
|
||||
* @class Phaser.GameObject.Factory
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
Phaser.GameObject.Factory = function (state)
|
||||
{
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
* @protected
|
||||
*/
|
||||
this.game = state.game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.State} state - The State that owns this Factory
|
||||
* @protected
|
||||
*/
|
||||
this.state = state;
|
||||
};
|
||||
|
||||
Phaser.GameObject.Factory.prototype.constructor = Phaser.GameObject.Factory;
|
||||
|
||||
Phaser.GameObject.Factory.prototype = {
|
||||
|
||||
/**
|
||||
* Adds an existing display object to the game world.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#existing
|
||||
* @param {any} object - An instance of Phaser.Sprite, Phaser.Button or any other display object.
|
||||
* @return {any} The child that was added to the World.
|
||||
*/
|
||||
existing: function (object)
|
||||
{
|
||||
return this.state.children.add(object);
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a tween on a specific object.
|
||||
*
|
||||
* The object can be any JavaScript object or Phaser object such as Sprite.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#tween
|
||||
* @param {object} object - Object the tween will be run on.
|
||||
* @return {Phaser.Tween} The newly created Phaser.Tween object.
|
||||
*/
|
||||
tween: function (object)
|
||||
{
|
||||
return this.state.sys.tweens.create(object);
|
||||
},
|
||||
|
||||
/**
|
||||
* A Group is a container for display objects that allows for fast pooling, recycling and collision checks.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#group
|
||||
* @param {any} [parent] - The parent Group or DisplayObjectContainer that will hold this group, if any. If set to null the Group won't be added to the display list. If undefined it will be added to World by default.
|
||||
* @param {string} [name='group'] - A name for this Group. Not used internally but useful for debugging.
|
||||
* @param {boolean} [addToStage=false] - If set to true this Group will be added directly to the Game.Stage instead of Game.World.
|
||||
* @param {boolean} [enableBody=false] - If true all Sprites created with `Group.create` or `Group.createMulitple` will have a physics body created on them. Change the body type with physicsBodyType.
|
||||
* @param {number} [physicsBodyType=0] - If enableBody is true this is the type of physics body that is created on new Sprites. Phaser.Physics.ARCADE, Phaser.Physics.P2, Phaser.Physics.NINJA, etc.
|
||||
* @return {Phaser.Group} The newly created Group.
|
||||
*/
|
||||
group: function (parent, name, addToStage, enableBody, physicsBodyType)
|
||||
{
|
||||
return new Phaser.Group(this.game, parent, name, addToStage, enableBody, physicsBodyType);
|
||||
},
|
||||
|
||||
/**
|
||||
* A Group is a container for display objects that allows for fast pooling, recycling and collision checks.
|
||||
*
|
||||
* A Physics Group is the same as an ordinary Group except that is has enableBody turned on by default, so any Sprites it creates
|
||||
* are automatically given a physics body.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#physicsGroup
|
||||
* @param {number} [physicsBodyType=Phaser.Physics.ARCADE] - If enableBody is true this is the type of physics body that is created on new Sprites. Phaser.Physics.ARCADE, Phaser.Physics.P2JS, Phaser.Physics.NINJA, etc.
|
||||
* @param {any} [parent] - The parent Group or DisplayObjectContainer that will hold this group, if any. If set to null the Group won't be added to the display list. If undefined it will be added to World by default.
|
||||
* @param {string} [name='group'] - A name for this Group. Not used internally but useful for debugging.
|
||||
* @param {boolean} [addToStage=false] - If set to true this Group will be added directly to the Game.Stage instead of Game.World.
|
||||
* @return {Phaser.Group} The newly created Group.
|
||||
*/
|
||||
physicsGroup: function (physicsBodyType, parent, name, addToStage)
|
||||
{
|
||||
return new Phaser.Group(this.game, parent, name, addToStage, true, physicsBodyType);
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Sound object.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#sound
|
||||
* @param {string} key - The Game.cache key of the sound that this object will use.
|
||||
* @param {number} [volume=1] - The volume at which the sound will be played.
|
||||
* @param {boolean} [loop=false] - Whether or not the sound will loop.
|
||||
* @param {boolean} [connect=true] - Controls if the created Sound object will connect to the master gainNode of the SoundManager when running under WebAudio.
|
||||
* @return {Phaser.Sound} The newly created sound object.
|
||||
*/
|
||||
sound: function (key, volume, loop, connect)
|
||||
{
|
||||
return this.game.sound.add(key, volume, loop, connect);
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new AudioSprite object.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#audioSprite
|
||||
* @param {string} key - The Game.cache key of the sound that this object will use.
|
||||
* @return {Phaser.AudioSprite} The newly created AudioSprite object.
|
||||
*/
|
||||
audioSprite: function (key)
|
||||
{
|
||||
return this.game.sound.addSprite(key);
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a new Emitter.
|
||||
*
|
||||
* A particle emitter can be used for one-time explosions or for
|
||||
* continuous effects like rain and fire. All it really does is launch Particle objects out
|
||||
* at set intervals, and fixes their positions and velocities accordingly.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#emitter
|
||||
* @param {number} [x=0] - The x coordinate within the Emitter that the particles are emitted from.
|
||||
* @param {number} [y=0] - The y coordinate within the Emitter that the particles are emitted from.
|
||||
* @param {number} [maxParticles=50] - The total number of particles in this emitter.
|
||||
* @return {Phaser.Particles.Arcade.Emitter} The newly created emitter object.
|
||||
*/
|
||||
emitter: function (x, y, maxParticles)
|
||||
{
|
||||
return this.game.particles.add(new Phaser.Particles.Arcade.Emitter(this.game, x, y, maxParticles));
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Phaser.Tilemap object.
|
||||
*
|
||||
* The map can either be populated with data from a Tiled JSON file or from a CSV file.
|
||||
* To do this pass the Cache key as the first parameter. When using Tiled data you need only provide the key.
|
||||
* When using CSV data you must provide the key and the tileWidth and tileHeight parameters.
|
||||
* If creating a blank tilemap to be populated later, you can either specify no parameters at all and then use `Tilemap.create` or pass the map and tile dimensions here.
|
||||
* Note that all Tilemaps use a base tile size to calculate dimensions from, but that a TilemapLayer may have its own unique tile size that overrides it.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#tilemap
|
||||
* @param {string} [key] - The key of the tilemap data as stored in the Cache. If you're creating a blank map either leave this parameter out or pass `null`.
|
||||
* @param {number} [tileWidth=32] - The pixel width of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data.
|
||||
* @param {number} [tileHeight=32] - The pixel height of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data.
|
||||
* @param {number} [width=10] - The width of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this.
|
||||
* @param {number} [height=10] - The height of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this.
|
||||
* @return {Phaser.Tilemap} The newly created tilemap object.
|
||||
*/
|
||||
tilemap: function (key, tileWidth, tileHeight, width, height)
|
||||
{
|
||||
return new Phaser.Tilemap(this.game, key, tileWidth, tileHeight, width, height);
|
||||
},
|
||||
|
||||
/**
|
||||
* A dynamic initially blank canvas to which images can be drawn.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#renderTexture
|
||||
* @param {number} [width=100] - the width of the RenderTexture.
|
||||
* @param {number} [height=100] - the height of the RenderTexture.
|
||||
* @param {string} [key=''] - Asset key for the RenderTexture when stored in the Cache (see addToCache parameter).
|
||||
* @param {boolean} [addToCache=false] - Should this RenderTexture be added to the Game.Cache? If so you can retrieve it with Cache.getTexture(key)
|
||||
* @return {Phaser.RenderTexture} The newly created RenderTexture object.
|
||||
*/
|
||||
renderTexture: function (width, height, key, addToCache)
|
||||
{
|
||||
if (key === undefined || key === '') { key = this.game.rnd.uuid(); }
|
||||
if (addToCache === undefined) { addToCache = false; }
|
||||
|
||||
var texture = new Phaser.RenderTexture(this.game, width, height, key);
|
||||
|
||||
if (addToCache)
|
||||
{
|
||||
this.game.cache.addRenderTexture(key, texture);
|
||||
}
|
||||
|
||||
return texture;
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a BitmapData object.
|
||||
*
|
||||
* A BitmapData object can be manipulated and drawn to like a traditional Canvas object and used to texture Sprites.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#bitmapData
|
||||
* @param {number} [width=256] - The width of the BitmapData in pixels.
|
||||
* @param {number} [height=256] - The height of the BitmapData in pixels.
|
||||
* @param {string} [key=''] - Asset key for the BitmapData when stored in the Cache (see addToCache parameter).
|
||||
* @param {boolean} [addToCache=false] - Should this BitmapData be added to the Game.Cache? If so you can retrieve it with Cache.getBitmapData(key)
|
||||
* @return {Phaser.BitmapData} The newly created BitmapData object.
|
||||
*/
|
||||
bitmapData: function (width, height, key, addToCache)
|
||||
{
|
||||
if (addToCache === undefined) { addToCache = false; }
|
||||
if (key === undefined || key === '') { key = this.game.rnd.uuid(); }
|
||||
|
||||
var texture = new Phaser.BitmapData(this.game, key, width, height);
|
||||
|
||||
if (addToCache)
|
||||
{
|
||||
this.game.cache.addBitmapData(key, texture);
|
||||
}
|
||||
|
||||
return texture;
|
||||
},
|
||||
|
||||
/**
|
||||
* A WebGL shader/filter that can be applied to Sprites.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#filter
|
||||
* @param {string} filter - The name of the filter you wish to create, for example HueRotate or SineWave.
|
||||
* @param {any} - Whatever parameters are needed to be passed to the filter init function.
|
||||
* @return {Phaser.Filter} The newly created Phaser.Filter object.
|
||||
*/
|
||||
filter: function (filter)
|
||||
{
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
|
||||
var filter = new Phaser.Filter[filter](this.game);
|
||||
|
||||
filter.init.apply(filter, args);
|
||||
|
||||
return filter;
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new Plugin into the PluginManager.
|
||||
*
|
||||
* The Plugin must have 2 properties: `game` and `parent`. Plugin.game is set to the game reference the PluginManager uses, and parent is set to the PluginManager.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#plugin
|
||||
* @param {object|Phaser.Plugin} plugin - The Plugin to add into the PluginManager. This can be a function or an existing object.
|
||||
* @param {...*} parameter - Additional parameters that will be passed to the Plugin.init method.
|
||||
* @return {Phaser.Plugin} The Plugin that was added to the manager.
|
||||
*/
|
||||
plugin: function (plugin)
|
||||
{
|
||||
return this.game.plugins.add(plugin);
|
||||
}
|
||||
|
||||
};
|
|
@ -1,356 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is the base Game Object class that you can use when creating your own extended Game Objects.
|
||||
* It hides away the 'private' stuff and exposes only the useful getters, setters and properties.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
// Phaser.Texture and Phaser.Frame objects passed in here, instead of looked-up.
|
||||
// Allows override from non-standard GO types
|
||||
Phaser.GameObject = function (state, x, y, texture, frame, parent)
|
||||
{
|
||||
this.state = state;
|
||||
|
||||
this.game = state.game;
|
||||
|
||||
this.name = '';
|
||||
|
||||
this.type = 0;
|
||||
|
||||
this.parent = parent;
|
||||
|
||||
// Texture is globally shared between GameObjects, not specific to this one
|
||||
this.texture = texture;
|
||||
|
||||
// Frame is globally shared between GameObjects, not specific to this one
|
||||
this.frame = frame;
|
||||
|
||||
// All GameObjects have the following components, always:
|
||||
this.transform = new Phaser.Component.Transform(this, x, y);
|
||||
|
||||
// Optional? Maybe set on a per GO basis?
|
||||
this.data = new Phaser.Component.Data(this);
|
||||
|
||||
this.color = new Phaser.Component.Color(this);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// ----------------------------------------------------------------
|
||||
// The following properties are debatable to have in this class
|
||||
// ----------------------------------------------------------------
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
this.scaleMode = Phaser.scaleModes.DEFAULT;
|
||||
|
||||
// Allows you to turn off a GameObject from rendering, but still render its children (if it has any)
|
||||
// Maybe this should move?
|
||||
// this.skipRender = (key === undefined);
|
||||
this.skipRender = false;
|
||||
|
||||
this.visible = true;
|
||||
|
||||
// Either null, or the Children component
|
||||
this.children = null;
|
||||
|
||||
this.exists = true;
|
||||
};
|
||||
|
||||
Phaser.GameObject.prototype.constructor = Phaser.GameObject;
|
||||
|
||||
Phaser.GameObject.prototype = {
|
||||
|
||||
preUpdate: function ()
|
||||
{
|
||||
// NOOP
|
||||
},
|
||||
|
||||
update: function ()
|
||||
{
|
||||
// NOOP
|
||||
},
|
||||
|
||||
postUpdate: function ()
|
||||
{
|
||||
// NOOP
|
||||
},
|
||||
|
||||
render: function ()
|
||||
{
|
||||
// NOOP
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
// NOOP
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperties(Phaser.GameObject.prototype, {
|
||||
|
||||
// Transform getters / setters
|
||||
|
||||
x: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._posX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._posX = value;
|
||||
this.transform.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
y: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._posY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._posY = value;
|
||||
this.transform.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
scale: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._scaleX = value;
|
||||
this.transform._scaleY = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
scaleX: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._scaleX = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
scaleY: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._scaleY = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
anchor: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._anchorX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform.setAnchor(value);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
anchorX: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._anchorX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._anchorX = value;
|
||||
this.transform.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
anchorY: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._anchorY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._anchorY = value;
|
||||
this.transform.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
pivotX: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._pivotX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._pivotX = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
pivotY: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._pivotY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._pivotY = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
angle: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return Phaser.Math.wrapAngle(this.rotation * Phaser.Math.RAD_TO_DEG);
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.rotation = Phaser.Math.wrapAngle(value) * Phaser.Math.DEG_TO_RAD;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
rotation: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._rotation;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
if (this.transform._rotation === value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.transform._rotation = value;
|
||||
this.transform.dirty = true;
|
||||
|
||||
if (this.transform._rotation % Phaser.Math.PI2)
|
||||
{
|
||||
this.transform.cache.sr = Math.sin(this.transform._rotation);
|
||||
this.transform.cache.cr = Math.cos(this.transform._rotation);
|
||||
this.transform.updateCache();
|
||||
this.transform.hasLocalRotation = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.transform.hasLocalRotation = false;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
// Color getters / setters
|
||||
|
||||
alpha: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.color._alpha;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.color.alpha = value;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
blendMode: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.color._blendMode;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.color.blendMode = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -1,429 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The GameObjectCreator is a quick way to create common game objects _without_ adding them to the game world.
|
||||
* The object creator can be accessed with {@linkcode Phaser.Game#make `game.make`}.
|
||||
*
|
||||
* @class Phaser.GameObjectCreator
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
Phaser.GameObjectCreator = function (game) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
* @protected
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.World} world - A reference to the game world.
|
||||
* @protected
|
||||
*/
|
||||
this.world = this.game.world;
|
||||
|
||||
};
|
||||
|
||||
Phaser.GameObjectCreator.prototype = {
|
||||
|
||||
/**
|
||||
* Create a new Image object.
|
||||
*
|
||||
* An Image is a light-weight object you can use to display anything that doesn't need physics or animation.
|
||||
* It can still rotate, scale, crop and receive input events. This makes it perfect for logos, backgrounds, simple buttons and other non-Sprite graphics.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#image
|
||||
* @param {number} x - X position of the image.
|
||||
* @param {number} y - Y position of the image.
|
||||
* @param {string|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
|
||||
* @param {string|number} [frame] - If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
|
||||
* @return {Phaser.Image} the newly created sprite object.
|
||||
*/
|
||||
image: function (x, y, key, frame) {
|
||||
|
||||
return new Phaser.Image(this.game, x, y, key, frame);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a new Sprite with specific position and sprite sheet key.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#sprite
|
||||
* @param {number} x - X position of the new sprite.
|
||||
* @param {number} y - Y position of the new sprite.
|
||||
* @param {string|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
|
||||
* @param {string|number} [frame] - If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
|
||||
* @return {Phaser.Sprite} the newly created sprite object.
|
||||
*/
|
||||
sprite: function (x, y, key, frame) {
|
||||
|
||||
return new Phaser.Sprite(this.game, x, y, key, frame);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a tween object for a specific object.
|
||||
*
|
||||
* The object can be any JavaScript object or Phaser object such as Sprite.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#tween
|
||||
* @param {object} obj - Object the tween will be run on.
|
||||
* @return {Phaser.Tween} The Tween object.
|
||||
*/
|
||||
tween: function (obj) {
|
||||
|
||||
return new Phaser.Tween(obj, this.game, this.game.tweens);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* A Group is a container for display objects that allows for fast pooling, recycling and collision checks.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#group
|
||||
* @param {any} parent - The parent Group or DisplayObjectContainer that will hold this group, if any.
|
||||
* @param {string} [name='group'] - A name for this Group. Not used internally but useful for debugging.
|
||||
* @param {boolean} [addToStage=false] - If set to true this Group will be added directly to the Game.Stage instead of Game.World.
|
||||
* @param {boolean} [enableBody=false] - If true all Sprites created with `Group.create` or `Group.createMulitple` will have a physics body created on them. Change the body type with physicsBodyType.
|
||||
* @param {number} [physicsBodyType=0] - If enableBody is true this is the type of physics body that is created on new Sprites. Phaser.Physics.ARCADE, Phaser.Physics.P2, Phaser.Physics.NINJA, etc.
|
||||
* @return {Phaser.Group} The newly created Group.
|
||||
*/
|
||||
group: function (parent, name, addToStage, enableBody, physicsBodyType) {
|
||||
|
||||
return new Phaser.Group(this.game, parent, name, addToStage, enableBody, physicsBodyType);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a new SpriteBatch.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#spriteBatch
|
||||
* @param {any} parent - The parent Group or DisplayObjectContainer that will hold this group, if any.
|
||||
* @param {string} [name='group'] - A name for this Group. Not used internally but useful for debugging.
|
||||
* @param {boolean} [addToStage=false] - If set to true this Group will be added directly to the Game.Stage instead of Game.World.
|
||||
* @return {Phaser.SpriteBatch} The newly created group.
|
||||
*/
|
||||
spriteBatch: function (parent, name, addToStage) {
|
||||
|
||||
if (name === undefined) { name = 'group'; }
|
||||
if (addToStage === undefined) { addToStage = false; }
|
||||
|
||||
return new Phaser.SpriteBatch(this.game, parent, name, addToStage);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Sound object.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#audio
|
||||
* @param {string} key - The Game.cache key of the sound that this object will use.
|
||||
* @param {number} [volume=1] - The volume at which the sound will be played.
|
||||
* @param {boolean} [loop=false] - Whether or not the sound will loop.
|
||||
* @param {boolean} [connect=true] - Controls if the created Sound object will connect to the master gainNode of the SoundManager when running under WebAudio.
|
||||
* @return {Phaser.Sound} The newly created text object.
|
||||
*/
|
||||
audio: function (key, volume, loop, connect) {
|
||||
|
||||
return this.game.sound.add(key, volume, loop, connect);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new AudioSprite object.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#audioSprite
|
||||
* @param {string} key - The Game.cache key of the sound that this object will use.
|
||||
* @return {Phaser.AudioSprite} The newly created AudioSprite object.
|
||||
*/
|
||||
audioSprite: function (key) {
|
||||
|
||||
return this.game.sound.addSprite(key);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Sound object.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#sound
|
||||
* @param {string} key - The Game.cache key of the sound that this object will use.
|
||||
* @param {number} [volume=1] - The volume at which the sound will be played.
|
||||
* @param {boolean} [loop=false] - Whether or not the sound will loop.
|
||||
* @param {boolean} [connect=true] - Controls if the created Sound object will connect to the master gainNode of the SoundManager when running under WebAudio.
|
||||
* @return {Phaser.Sound} The newly created text object.
|
||||
*/
|
||||
sound: function (key, volume, loop, connect) {
|
||||
|
||||
return this.game.sound.add(key, volume, loop, connect);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new TileSprite object.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#tileSprite
|
||||
* @param {number} x - The x coordinate (in world space) to position the TileSprite at.
|
||||
* @param {number} y - The y coordinate (in world space) to position the TileSprite at.
|
||||
* @param {number} width - The width of the TileSprite.
|
||||
* @param {number} height - The height of the TileSprite.
|
||||
* @param {string|Phaser.BitmapData|PIXI.Texture} key - This is the image or texture used by the TileSprite during rendering. It can be a string which is a reference to the Phaser Image Cache entry, or an instance of a PIXI.Texture or BitmapData.
|
||||
* @param {string|number} frame - If this TileSprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
|
||||
* @return {Phaser.TileSprite} The newly created tileSprite object.
|
||||
*/
|
||||
tileSprite: function (x, y, width, height, key, frame) {
|
||||
|
||||
return new Phaser.TileSprite(this.game, x, y, width, height, key, frame);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Rope object.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#rope
|
||||
* @param {number} x - The x coordinate (in world space) to position the Rope at.
|
||||
* @param {number} y - The y coordinate (in world space) to position the Rope at.
|
||||
* @param {number} width - The width of the Rope.
|
||||
* @param {number} height - The height of the Rope.
|
||||
* @param {string|Phaser.RenderTexture|Phaser.BitmapData|PIXI.Texture} key - This is the image or texture used by the TileSprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
|
||||
* @param {string|number} frame - If this Rope is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
|
||||
* @return {Phaser.Rope} The newly created rope object.
|
||||
*/
|
||||
rope: function (x, y, key, frame, points) {
|
||||
|
||||
return new Phaser.Rope(this.game, x, y, key, frame, points);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Text object.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#text
|
||||
* @param {number} x - X position of the new text object.
|
||||
* @param {number} y - Y position of the new text object.
|
||||
* @param {string} text - The actual text that will be written.
|
||||
* @param {object} style - The style object containing style attributes like font, font size , etc.
|
||||
* @return {Phaser.Text} The newly created text object.
|
||||
*/
|
||||
text: function (x, y, text, style) {
|
||||
|
||||
return new Phaser.Text(this.game, x, y, text, style);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Button object.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#button
|
||||
* @param {number} [x] X position of the new button object.
|
||||
* @param {number} [y] Y position of the new button object.
|
||||
* @param {string} [key] The image key as defined in the Game.Cache to use as the texture for this button.
|
||||
* @param {function} [callback] The function to call when this button is pressed
|
||||
* @param {object} [callbackContext] The context in which the callback will be called (usually 'this')
|
||||
* @param {string|number} [overFrame] This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @param {string|number} [outFrame] This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @param {string|number} [downFrame] This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @param {string|number} [upFrame] This is the frame or frameName that will be set when this button is in an up state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @return {Phaser.Button} The newly created button object.
|
||||
*/
|
||||
button: function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame) {
|
||||
|
||||
return new Phaser.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Graphics object.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#graphics
|
||||
* @param {number} [x=0] - X position of the new graphics object.
|
||||
* @param {number} [y=0] - Y position of the new graphics object.
|
||||
* @return {Phaser.Graphics} The newly created graphics object.
|
||||
*/
|
||||
graphics: function (x, y) {
|
||||
|
||||
return new Phaser.Graphics(this.game, x, y);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creat a new Emitter.
|
||||
*
|
||||
* An Emitter is a lightweight particle emitter. It can be used for one-time explosions or for
|
||||
* continuous effects like rain and fire. All it really does is launch Particle objects out
|
||||
* at set intervals, and fixes their positions and velocities accorindgly.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#emitter
|
||||
* @param {number} [x=0] - The x coordinate within the Emitter that the particles are emitted from.
|
||||
* @param {number} [y=0] - The y coordinate within the Emitter that the particles are emitted from.
|
||||
* @param {number} [maxParticles=50] - The total number of particles in this emitter.
|
||||
* @return {Phaser.Emitter} The newly created emitter object.
|
||||
*/
|
||||
emitter: function (x, y, maxParticles) {
|
||||
|
||||
return new Phaser.Particles.Arcade.Emitter(this.game, x, y, maxParticles);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a new RetroFont object.
|
||||
*
|
||||
* A RetroFont can be used as a texture for an Image or Sprite and optionally add it to the Cache.
|
||||
* A RetroFont uses a bitmap which contains fixed with characters for the font set. You use character spacing to define the set.
|
||||
* If you need variable width character support then use a BitmapText object instead. The main difference between a RetroFont and a BitmapText
|
||||
* is that a RetroFont creates a single texture that you can apply to a game object, where-as a BitmapText creates one Sprite object per letter of text.
|
||||
* The texture can be asssigned or one or multiple images/sprites, but note that the text the RetroFont uses will be shared across them all,
|
||||
* i.e. if you need each Image to have different text in it, then you need to create multiple RetroFont objects.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#retroFont
|
||||
* @param {string} font - The key of the image in the Game.Cache that the RetroFont will use.
|
||||
* @param {number} characterWidth - The width of each character in the font set.
|
||||
* @param {number} characterHeight - The height of each character in the font set.
|
||||
* @param {string} chars - The characters used in the font set, in display order. You can use the TEXT_SET consts for common font set arrangements.
|
||||
* @param {number} charsPerRow - The number of characters per row in the font set.
|
||||
* @param {number} [xSpacing=0] - If the characters in the font set have horizontal spacing between them set the required amount here.
|
||||
* @param {number} [ySpacing=0] - If the characters in the font set have vertical spacing between them set the required amount here.
|
||||
* @param {number} [xOffset=0] - If the font set doesn't start at the top left of the given image, specify the X coordinate offset here.
|
||||
* @param {number} [yOffset=0] - If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here.
|
||||
* @return {Phaser.RetroFont} The newly created RetroFont texture which can be applied to an Image or Sprite.
|
||||
*/
|
||||
retroFont: function (font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset) {
|
||||
|
||||
return new Phaser.RetroFont(this.game, font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a new BitmapText object.
|
||||
*
|
||||
* BitmapText objects work by taking a texture file and an XML file that describes the font structure.
|
||||
* It then generates a new Sprite object for each letter of the text, proportionally spaced out and aligned to
|
||||
* match the font structure.
|
||||
*
|
||||
* BitmapText objects are less flexible than Text objects, in that they have less features such as shadows, fills and the ability
|
||||
* to use Web Fonts. However you trade this flexibility for pure rendering speed. You can also create visually compelling BitmapTexts by
|
||||
* processing the font texture in an image editor first, applying fills and any other effects required.
|
||||
*
|
||||
* To create multi-line text insert \r, \n or \r\n escape codes into the text string.
|
||||
*
|
||||
* To create a BitmapText data files you can use:
|
||||
*
|
||||
* BMFont (Windows, free): http://www.angelcode.com/products/bmfont/
|
||||
* Glyph Designer (OS X, commercial): http://www.71squared.com/en/glyphdesigner
|
||||
* Littera (Web-based, free): http://kvazars.com/littera/
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#bitmapText
|
||||
* @param {number} x - X coordinate to display the BitmapText object at.
|
||||
* @param {number} y - Y coordinate to display the BitmapText object at.
|
||||
* @param {string} font - The key of the BitmapText as stored in Phaser.Cache.
|
||||
* @param {string} [text=''] - The text that will be rendered. This can also be set later via BitmapText.text.
|
||||
* @param {number} [size=32] - The size the font will be rendered at in pixels.
|
||||
* @param {string} [align='left'] - The alignment of multi-line text. Has no effect if there is only one line of text.
|
||||
* @return {Phaser.BitmapText} The newly created bitmapText object.
|
||||
*/
|
||||
bitmapText: function (x, y, font, text, size, align) {
|
||||
|
||||
return new Phaser.BitmapText(this.game, x, y, font, text, size, align);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Phaser.Tilemap object.
|
||||
*
|
||||
* The map can either be populated with data from a Tiled JSON file or from a CSV file.
|
||||
* To do this pass the Cache key as the first parameter. When using Tiled data you need only provide the key.
|
||||
* When using CSV data you must provide the key and the tileWidth and tileHeight parameters.
|
||||
* If creating a blank tilemap to be populated later, you can either specify no parameters at all and then use `Tilemap.create` or pass the map and tile dimensions here.
|
||||
* Note that all Tilemaps use a base tile size to calculate dimensions from, but that a TilemapLayer may have its own unique tile size that overrides it.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#tilemap
|
||||
* @param {string} [key] - The key of the tilemap data as stored in the Cache. If you're creating a blank map either leave this parameter out or pass `null`.
|
||||
* @param {number} [tileWidth=32] - The pixel width of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data.
|
||||
* @param {number} [tileHeight=32] - The pixel height of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data.
|
||||
* @param {number} [width=10] - The width of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this.
|
||||
* @param {number} [height=10] - The height of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this.
|
||||
*/
|
||||
tilemap: function (key, tileWidth, tileHeight, width, height) {
|
||||
|
||||
return new Phaser.Tilemap(this.game, key, tileWidth, tileHeight, width, height);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* A dynamic initially blank canvas to which images can be drawn.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#renderTexture
|
||||
* @param {number} [width=100] - the width of the RenderTexture.
|
||||
* @param {number} [height=100] - the height of the RenderTexture.
|
||||
* @param {string} [key=''] - Asset key for the RenderTexture when stored in the Cache (see addToCache parameter).
|
||||
* @param {boolean} [addToCache=false] - Should this RenderTexture be added to the Game.Cache? If so you can retrieve it with Cache.getTexture(key)
|
||||
* @return {Phaser.RenderTexture} The newly created RenderTexture object.
|
||||
*/
|
||||
renderTexture: function (width, height, key, addToCache) {
|
||||
|
||||
if (key === undefined || key === '') { key = this.game.rnd.uuid(); }
|
||||
if (addToCache === undefined) { addToCache = false; }
|
||||
|
||||
var texture = new Phaser.RenderTexture(this.game, width, height, key);
|
||||
|
||||
if (addToCache)
|
||||
{
|
||||
this.game.cache.addRenderTexture(key, texture);
|
||||
}
|
||||
|
||||
return texture;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a BitmpaData object.
|
||||
*
|
||||
* A BitmapData object can be manipulated and drawn to like a traditional Canvas object and used to texture Sprites.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#bitmapData
|
||||
* @param {number} [width=256] - The width of the BitmapData in pixels.
|
||||
* @param {number} [height=256] - The height of the BitmapData in pixels.
|
||||
* @param {string} [key=''] - Asset key for the BitmapData when stored in the Cache (see addToCache parameter).
|
||||
* @param {boolean} [addToCache=false] - Should this BitmapData be added to the Game.Cache? If so you can retrieve it with Cache.getBitmapData(key)
|
||||
* @return {Phaser.BitmapData} The newly created BitmapData object.
|
||||
*/
|
||||
bitmapData: function (width, height, key, addToCache) {
|
||||
|
||||
if (addToCache === undefined) { addToCache = false; }
|
||||
if (key === undefined || key === '') { key = this.game.rnd.uuid(); }
|
||||
|
||||
var texture = new Phaser.BitmapData(this.game, key, width, height);
|
||||
|
||||
if (addToCache)
|
||||
{
|
||||
this.game.cache.addBitmapData(key, texture);
|
||||
}
|
||||
|
||||
return texture;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* A WebGL shader/filter that can be applied to Sprites.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#filter
|
||||
* @param {string} filter - The name of the filter you wish to create, for example HueRotate or SineWave.
|
||||
* @param {any} - Whatever parameters are needed to be passed to the filter init function.
|
||||
* @return {Phaser.Filter} The newly created Phaser.Filter object.
|
||||
*/
|
||||
filter: function (filter) {
|
||||
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
|
||||
var filter = new Phaser.Filter[filter](this.game);
|
||||
|
||||
filter.init.apply(filter, args);
|
||||
|
||||
return filter;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.GameObjectCreator.prototype.constructor = Phaser.GameObjectCreator;
|
|
@ -1,712 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* BitmapText objects work by taking a texture file and an XML or JSON file that describes the font structure.
|
||||
* It then generates a new Sprite object for each letter of the text, proportionally spaced out and aligned to
|
||||
* match the font structure.
|
||||
*
|
||||
* BitmapText objects are less flexible than Text objects, in that they have less features such as shadows, fills and the ability
|
||||
* to use Web Fonts, however you trade this flexibility for rendering speed. You can also create visually compelling BitmapTexts by
|
||||
* processing the font texture in an image editor, applying fills and any other effects required.
|
||||
*
|
||||
* To create multi-line text insert \r, \n or \r\n escape codes into the text string.
|
||||
*
|
||||
* If you are having performance issues due to the volume of sprites being rendered, and do not require the text to be constantly
|
||||
* updating, you can use BitmapText.generateTexture to create a static texture from this BitmapText.
|
||||
*
|
||||
* To create a BitmapText data files you can use:
|
||||
*
|
||||
* BMFont (Windows, free): http://www.angelcode.com/products/bmfont/
|
||||
* Glyph Designer (OS X, commercial): http://www.71squared.com/en/glyphdesigner
|
||||
* Littera (Web-based, free): http://kvazars.com/littera/
|
||||
*
|
||||
* For most use cases it is recommended to use XML. If you wish to use JSON, the formatting should be equal to the result of
|
||||
* converting a valid XML file through the popular X2JS library. An online tool for conversion can be found here: http://codebeautify.org/xmltojson
|
||||
*
|
||||
* If you were using an older version of Phaser (< 2.4) and using the DOMish parser hack, please remove this. It isn't required any longer.
|
||||
*
|
||||
* @class Phaser.GameObject.BitmapText
|
||||
* @constructor
|
||||
* @extends PIXI.DisplayObjectContainer
|
||||
* @extends Phaser.Component.Core
|
||||
* @extends Phaser.Component.Angle
|
||||
* @extends Phaser.Component.AutoCull
|
||||
* @extends Phaser.Component.Bounds
|
||||
* @extends Phaser.Component.Destroy
|
||||
* @extends Phaser.Component.FixedToCamera
|
||||
* @extends Phaser.Component.InputEnabled
|
||||
* @extends Phaser.Component.InWorld
|
||||
* @extends Phaser.Component.LifeSpan
|
||||
* @extends Phaser.Component.PhysicsBody
|
||||
* @extends Phaser.Component.Reset
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {number} x - X coordinate to display the BitmapText object at.
|
||||
* @param {number} y - Y coordinate to display the BitmapText object at.
|
||||
* @param {string} font - The key of the BitmapText as stored in Phaser.Cache.
|
||||
* @param {string} [text=''] - The text that will be rendered. This can also be set later via BitmapText.text.
|
||||
* @param {number} [size=32] - The size the font will be rendered at in pixels.
|
||||
* @param {string} [align='left'] - The alignment of multi-line text. Has no effect if there is only one line of text.
|
||||
*/
|
||||
Phaser.GameObject.BitmapText = function (game, x, y, font, text, size, align) {
|
||||
|
||||
x = x || 0;
|
||||
y = y || 0;
|
||||
font = font || '';
|
||||
text = text || '';
|
||||
size = size || 32;
|
||||
align = align || 'left';
|
||||
|
||||
PIXI.DisplayObjectContainer.call(this);
|
||||
|
||||
/**
|
||||
* @property {number} type - The const type of this object.
|
||||
* @readonly
|
||||
*/
|
||||
this.type = Phaser.BITMAPTEXT;
|
||||
|
||||
/**
|
||||
* @property {number} physicsType - The const physics body type of this object.
|
||||
* @readonly
|
||||
*/
|
||||
this.physicsType = Phaser.SPRITE;
|
||||
|
||||
/**
|
||||
* @property {number} textWidth - The width in pixels of the overall text area, taking into consideration multi-line text.
|
||||
* @readOnly
|
||||
*/
|
||||
this.textWidth = 0;
|
||||
|
||||
/**
|
||||
* @property {number} textHeight - The height in pixels of the overall text area, taking into consideration multi-line text.
|
||||
* @readOnly
|
||||
*/
|
||||
this.textHeight = 0;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} anchor - The anchor value of this BitmapText.
|
||||
*/
|
||||
this.anchor = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} _prevAnchor - The previous anchor value.
|
||||
* @private
|
||||
*/
|
||||
this._prevAnchor = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {array} _glyphs - Private tracker for the letter sprite pool.
|
||||
* @private
|
||||
*/
|
||||
this._glyphs = [];
|
||||
|
||||
/**
|
||||
* @property {number} _maxWidth - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._maxWidth = 0;
|
||||
|
||||
/**
|
||||
* @property {string} _text - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._text = text.toString() || '';
|
||||
|
||||
/**
|
||||
* @property {string} _data - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._data = game.cache.getBitmapFont(font);
|
||||
|
||||
/**
|
||||
* @property {string} _font - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._font = font;
|
||||
|
||||
/**
|
||||
* @property {number} _fontSize - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._fontSize = size;
|
||||
|
||||
/**
|
||||
* @property {string} _align - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._align = align;
|
||||
|
||||
/**
|
||||
* @property {number} _tint - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._tint = 0xFFFFFF;
|
||||
|
||||
this.updateText();
|
||||
|
||||
/**
|
||||
* @property {boolean} dirty - The dirty state of this object.
|
||||
*/
|
||||
this.dirty = false;
|
||||
|
||||
Phaser.Component.Core.init.call(this, game, x, y, '', null);
|
||||
|
||||
};
|
||||
|
||||
Phaser.GameObject.BitmapText.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
|
||||
Phaser.GameObject.BitmapText.prototype.constructor = Phaser.GameObject.BitmapText;
|
||||
|
||||
Phaser.Component.Core.install.call(Phaser.GameObject.BitmapText.prototype, [
|
||||
'Angle',
|
||||
'AutoCull',
|
||||
'Bounds',
|
||||
'Destroy',
|
||||
'FixedToCamera',
|
||||
'InputEnabled',
|
||||
'InWorld',
|
||||
'LifeSpan',
|
||||
'PhysicsBody',
|
||||
'Reset'
|
||||
]);
|
||||
|
||||
Phaser.GameObject.BitmapText.prototype.preUpdatePhysics = Phaser.Component.PhysicsBody.preUpdate;
|
||||
Phaser.GameObject.BitmapText.prototype.preUpdateLifeSpan = Phaser.Component.LifeSpan.preUpdate;
|
||||
Phaser.GameObject.BitmapText.prototype.preUpdateInWorld = Phaser.Component.InWorld.preUpdate;
|
||||
Phaser.GameObject.BitmapText.prototype.preUpdateCore = Phaser.Component.Core.preUpdate;
|
||||
|
||||
/**
|
||||
* Automatically called by World.preUpdate.
|
||||
*
|
||||
* @method
|
||||
* @memberof Phaser.GameObject.BitmapText
|
||||
* @return {boolean} True if the BitmapText was rendered, otherwise false.
|
||||
*/
|
||||
Phaser.GameObject.BitmapText.prototype.preUpdate = function () {
|
||||
|
||||
if (!this.preUpdatePhysics() || !this.preUpdateLifeSpan() || !this.preUpdateInWorld())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.preUpdateCore();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Automatically called by World.preUpdate.
|
||||
* @method Phaser.GameObject.BitmapText.prototype.postUpdate
|
||||
*/
|
||||
Phaser.GameObject.BitmapText.prototype.postUpdate = function () {
|
||||
|
||||
Phaser.Component.PhysicsBody.postUpdate.call(this);
|
||||
Phaser.Component.FixedToCamera.postUpdate.call(this);
|
||||
|
||||
if (this.body && this.body.type === Phaser.Physics.ARCADE)
|
||||
{
|
||||
if ((this.textWidth !== this.body.sourceWidth) || (this.textHeight !== this.body.sourceHeight))
|
||||
{
|
||||
this.body.setSize(this.textWidth, this.textHeight);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The text to be displayed by this BitmapText object.
|
||||
*
|
||||
* It's faster to use `BitmapText.text = string`, but this is kept for backwards compatibility.
|
||||
*
|
||||
* @method Phaser.GameObject.BitmapText.prototype.setText
|
||||
* @param {string} text - The text to be displayed by this BitmapText object.
|
||||
*/
|
||||
Phaser.GameObject.BitmapText.prototype.setText = function (text) {
|
||||
|
||||
this.text = text;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Given the input text this will scan the characters until either a newline is encountered,
|
||||
* or the line exceeds maxWidth, taking into account kerning, character widths and scaling.
|
||||
*
|
||||
* @method Phaser.GameObject.BitmapText.prototype.scanLine
|
||||
* @private
|
||||
* @param {object} data - A reference to the font object in the Phaser.Cache.
|
||||
* @param {float} scale - The scale of the font in relation to the texture.
|
||||
* @param {string} text - The text to parse.
|
||||
* @return {object} An object containing the parsed characters, total pixel width and x offsets.
|
||||
*/
|
||||
Phaser.GameObject.BitmapText.prototype.scanLine = function (data, scale, text) {
|
||||
|
||||
var x = 0;
|
||||
var w = 0;
|
||||
var lastSpace = -1;
|
||||
var wrappedWidth = 0;
|
||||
var prevCharCode = null;
|
||||
var maxWidth = (this._maxWidth > 0) ? this._maxWidth : null;
|
||||
var chars = [];
|
||||
|
||||
// Let's scan the text and work out if any of the lines are > maxWidth
|
||||
for (var i = 0; i < text.length; i++)
|
||||
{
|
||||
var end = (i === text.length - 1) ? true : false;
|
||||
|
||||
if (/(?:\r\n|\r|\n)/.test(text.charAt(i)))
|
||||
{
|
||||
return { width: w, text: text.substr(0, i), end: end, chars: chars };
|
||||
}
|
||||
else
|
||||
{
|
||||
var charCode = text.charCodeAt(i);
|
||||
var charData = data.chars[charCode];
|
||||
|
||||
var c = 0;
|
||||
|
||||
// If the character data isn't found in the data array
|
||||
// then we replace it with a blank space
|
||||
if (charData === undefined)
|
||||
{
|
||||
charCode = 32;
|
||||
charData = data.chars[charCode];
|
||||
}
|
||||
|
||||
// Adjust for kerning from previous character to this one
|
||||
var kerning = (prevCharCode && charData.kerning[prevCharCode]) ? charData.kerning[prevCharCode] : 0;
|
||||
|
||||
// Record the last space in the string and the current width
|
||||
if (/(\s)/.test(text.charAt(i)))
|
||||
{
|
||||
lastSpace = i;
|
||||
wrappedWidth = w;
|
||||
}
|
||||
|
||||
// What will the line width be if we add this character to it?
|
||||
c = (kerning + charData.texture.width + charData.xOffset) * scale;
|
||||
|
||||
// Do we need to line-wrap?
|
||||
if (maxWidth && ((w + c) >= maxWidth) && lastSpace > -1)
|
||||
{
|
||||
// The last space was at "lastSpace" which was "i - lastSpace" characters ago
|
||||
return { width: wrappedWidth || w, text: text.substr(0, i - (i - lastSpace)), end: end, chars: chars };
|
||||
}
|
||||
else
|
||||
{
|
||||
w += (charData.xAdvance + kerning) * scale;
|
||||
|
||||
chars.push(x + (charData.xOffset + kerning) * scale);
|
||||
|
||||
x += (charData.xAdvance + kerning) * scale;
|
||||
|
||||
prevCharCode = charCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { width: w, text: text, end: end, chars: chars };
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Given a text string this will scan each character in the string to ensure it exists
|
||||
* in the BitmapText font data. If it doesn't the character is removed, or replaced with the `replace` argument.
|
||||
*
|
||||
* If no font data has been loaded at all this returns an empty string, as nothing can be rendered.
|
||||
*
|
||||
* @method Phaser.GameObject.BitmapText.prototype.cleanText
|
||||
* @param {string} text - The text to parse.
|
||||
* @param {string} [replace=''] - The replacement string for any missing characters.
|
||||
* @return {string} The cleaned text string.
|
||||
*/
|
||||
Phaser.GameObject.BitmapText.prototype.cleanText = function (text, replace) {
|
||||
|
||||
if (replace === undefined)
|
||||
{
|
||||
replace = '';
|
||||
}
|
||||
|
||||
var data = this._data.font;
|
||||
|
||||
if (!data)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
var re = /\r\n|\n\r|\n|\r/g;
|
||||
var lines = text.replace(re, "\n").split("\n");
|
||||
|
||||
for (var i = 0; i < lines.length; i++)
|
||||
{
|
||||
var output = '';
|
||||
var line = lines[i];
|
||||
|
||||
for (var c = 0; c < line.length; c++)
|
||||
{
|
||||
if (data.chars[line.charCodeAt(c)])
|
||||
{
|
||||
output = output.concat(line[c]);
|
||||
}
|
||||
else
|
||||
{
|
||||
output = output.concat(replace);
|
||||
}
|
||||
}
|
||||
|
||||
lines[i] = output;
|
||||
}
|
||||
|
||||
return lines.join("\n");
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders text and updates it when needed.
|
||||
*
|
||||
* @method Phaser.GameObject.BitmapText.prototype.updateText
|
||||
* @private
|
||||
*/
|
||||
Phaser.GameObject.BitmapText.prototype.updateText = function () {
|
||||
|
||||
var data = this._data.font;
|
||||
|
||||
if (!data)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var text = this.text;
|
||||
var scale = this._fontSize / data.size;
|
||||
var lines = [];
|
||||
|
||||
var y = 0;
|
||||
|
||||
this.textWidth = 0;
|
||||
|
||||
do
|
||||
{
|
||||
var line = this.scanLine(data, scale, text);
|
||||
|
||||
line.y = y;
|
||||
|
||||
lines.push(line);
|
||||
|
||||
if (line.width > this.textWidth)
|
||||
{
|
||||
this.textWidth = line.width;
|
||||
}
|
||||
|
||||
y += (data.lineHeight * scale);
|
||||
|
||||
text = text.substr(line.text.length + 1);
|
||||
|
||||
} while (line.end === false);
|
||||
|
||||
this.textHeight = y;
|
||||
|
||||
var t = 0;
|
||||
var align = 0;
|
||||
var ax = this.textWidth * this.anchor.x;
|
||||
var ay = this.textHeight * this.anchor.y;
|
||||
|
||||
for (var i = 0; i < lines.length; i++)
|
||||
{
|
||||
var line = lines[i];
|
||||
|
||||
if (this._align === 'right')
|
||||
{
|
||||
align = this.textWidth - line.width;
|
||||
}
|
||||
else if (this._align === 'center')
|
||||
{
|
||||
align = (this.textWidth - line.width) / 2;
|
||||
}
|
||||
|
||||
for (var c = 0; c < line.text.length; c++)
|
||||
{
|
||||
var charCode = line.text.charCodeAt(c);
|
||||
var charData = data.chars[charCode];
|
||||
|
||||
if (charData === undefined)
|
||||
{
|
||||
charCode = 32;
|
||||
charData = data.chars[charCode];
|
||||
}
|
||||
|
||||
var g = this._glyphs[t];
|
||||
|
||||
if (g)
|
||||
{
|
||||
// Sprite already exists in the glyphs pool, so we'll reuse it for this letter
|
||||
g.texture = charData.texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We need a new sprite as the pool is empty or exhausted
|
||||
g = new PIXI.Sprite(charData.texture);
|
||||
g.name = line.text[c];
|
||||
this._glyphs.push(g);
|
||||
}
|
||||
|
||||
g.position.x = (line.chars[c] + align) - ax;
|
||||
g.position.y = (line.y + (charData.yOffset * scale)) - ay;
|
||||
|
||||
g.scale.set(scale);
|
||||
g.tint = this.tint;
|
||||
g.texture.requiresReTint = true;
|
||||
|
||||
if (!g.parent)
|
||||
{
|
||||
this.addChild(g);
|
||||
}
|
||||
|
||||
t++;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove unnecessary children
|
||||
// This moves them from the display list (children array) but retains them in the _glyphs pool
|
||||
for (i = t; i < this._glyphs.length; i++)
|
||||
{
|
||||
this.removeChild(this._glyphs[i]);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* If a BitmapText changes from having a large number of characters to having very few characters it will cause lots of
|
||||
* Sprites to be retained in the BitmapText._glyphs array. Although they are not attached to the display list they
|
||||
* still take up memory while sat in the glyphs pool waiting to be re-used in the future.
|
||||
*
|
||||
* If you know that the BitmapText will not grow any larger then you can purge out the excess glyphs from the pool
|
||||
* by calling this method.
|
||||
*
|
||||
* Calling this doesn't prevent you from increasing the length of the text again in the future.
|
||||
*
|
||||
* @method Phaser.GameObject.BitmapText.prototype.purgeGlyphs
|
||||
* @return {integer} The amount of glyphs removed from the pool.
|
||||
*/
|
||||
Phaser.GameObject.BitmapText.prototype.purgeGlyphs = function () {
|
||||
|
||||
var len = this._glyphs.length;
|
||||
var kept = [];
|
||||
|
||||
for (var i = 0; i < this._glyphs.length; i++)
|
||||
{
|
||||
if (this._glyphs[i].parent !== this)
|
||||
{
|
||||
this._glyphs[i].destroy();
|
||||
}
|
||||
else
|
||||
{
|
||||
kept.push(this._glyphs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
this._glyphs = [];
|
||||
this._glyphs = kept;
|
||||
|
||||
this.updateText();
|
||||
|
||||
return len - kept.length;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the transform of this object.
|
||||
*
|
||||
* @method Phaser.GameObject.BitmapText.prototype.updateTransform
|
||||
* @private
|
||||
*/
|
||||
Phaser.GameObject.BitmapText.prototype.updateTransform = function () {
|
||||
|
||||
if (this.dirty || !this.anchor.equals(this._prevAnchor))
|
||||
{
|
||||
this.updateText();
|
||||
this.dirty = false;
|
||||
this._prevAnchor.copyFrom(this.anchor);
|
||||
}
|
||||
|
||||
PIXI.DisplayObjectContainer.prototype.updateTransform.call(this);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @name Phaser.GameObject.BitmapText#align
|
||||
* @property {string} align - Alignment for multi-line text ('left', 'center' or 'right'), does not affect single lines of text.
|
||||
*/
|
||||
Object.defineProperty(Phaser.GameObject.BitmapText.prototype, 'align', {
|
||||
|
||||
get: function() {
|
||||
return this._align;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
if (value !== this._align && (value === 'left' || value === 'center' || value === 'right'))
|
||||
{
|
||||
this._align = value;
|
||||
this.updateText();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.GameObject.BitmapText#tint
|
||||
* @property {number} tint - The tint applied to the BitmapText. This is a hex value. Set to white to disable (0xFFFFFF)
|
||||
*/
|
||||
Object.defineProperty(Phaser.GameObject.BitmapText.prototype, 'tint', {
|
||||
|
||||
get: function() {
|
||||
return this._tint;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
if (value !== this._tint)
|
||||
{
|
||||
this._tint = value;
|
||||
this.updateText();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.GameObject.BitmapText#font
|
||||
* @property {string} font - The font the text will be rendered in, i.e. 'Arial'. Must be loaded in the browser before use.
|
||||
*/
|
||||
Object.defineProperty(Phaser.GameObject.BitmapText.prototype, 'font', {
|
||||
|
||||
get: function() {
|
||||
return this._font;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
if (value !== this._font)
|
||||
{
|
||||
this._font = value.trim();
|
||||
this._data = this.game.cache.getBitmapFont(this._font);
|
||||
this.updateText();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.GameObject.BitmapText#fontSize
|
||||
* @property {number} fontSize - The size of the font in pixels.
|
||||
*/
|
||||
Object.defineProperty(Phaser.GameObject.BitmapText.prototype, 'fontSize', {
|
||||
|
||||
get: function() {
|
||||
return this._fontSize;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
value = parseInt(value, 10);
|
||||
|
||||
if (value !== this._fontSize && value > 0)
|
||||
{
|
||||
this._fontSize = value;
|
||||
this.updateText();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.GameObject.BitmapText#text
|
||||
* @property {string} text - The text to be displayed by this BitmapText object.
|
||||
*/
|
||||
Object.defineProperty(Phaser.GameObject.BitmapText.prototype, 'text', {
|
||||
|
||||
get: function() {
|
||||
return this._text;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
if (value !== this._text)
|
||||
{
|
||||
this._text = value.toString() || '';
|
||||
this.updateText();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The maximum display width of this BitmapText in pixels.
|
||||
*
|
||||
* If BitmapText.text is longer than maxWidth then the lines will be automatically wrapped
|
||||
* based on the last whitespace character found in the line.
|
||||
*
|
||||
* If no whitespace was found then no wrapping will take place and consequently the maxWidth value will not be honored.
|
||||
*
|
||||
* Disable maxWidth by setting the value to 0.
|
||||
*
|
||||
* @name Phaser.GameObject.BitmapText#maxWidth
|
||||
* @property {number} maxWidth - The maximum width of this BitmapText in pixels.
|
||||
*/
|
||||
Object.defineProperty(Phaser.GameObject.BitmapText.prototype, 'maxWidth', {
|
||||
|
||||
get: function() {
|
||||
|
||||
return this._maxWidth;
|
||||
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
if (value !== this._maxWidth)
|
||||
{
|
||||
this._maxWidth = value;
|
||||
this.updateText();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Enable or disable texture smoothing for this BitmapText.
|
||||
*
|
||||
* The smoothing is applied to the BaseTexture of this font, which all letters of the text reference.
|
||||
*
|
||||
* Smoothing is enabled by default.
|
||||
*
|
||||
* @name Phaser.GameObject.BitmapText#smoothed
|
||||
* @property {boolean} smoothed
|
||||
*/
|
||||
Object.defineProperty(Phaser.GameObject.BitmapText.prototype, 'smoothed', {
|
||||
|
||||
get: function() {
|
||||
|
||||
return !this._data.base.scaleMode;
|
||||
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
if (value)
|
||||
{
|
||||
this._data.base.scaleMode = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._data.base.scaleMode = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -1,75 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.GameObject.BitmapText.FACTORY_KEY = 'bitmapText';
|
||||
|
||||
/**
|
||||
* Create a new BitmapText object.
|
||||
*
|
||||
* BitmapText objects work by taking a texture file and an XML file that describes the font structure.
|
||||
* It then generates a new Sprite object for each letter of the text, proportionally spaced out and aligned to
|
||||
* match the font structure.
|
||||
*
|
||||
* BitmapText objects are less flexible than Text objects, in that they have less features such as shadows, fills and the ability
|
||||
* to use Web Fonts. However you trade this flexibility for pure rendering speed. You can also create visually compelling BitmapTexts by
|
||||
* processing the font texture in an image editor first, applying fills and any other effects required.
|
||||
*
|
||||
* To create multi-line text insert \r, \n or \r\n escape codes into the text string.
|
||||
*
|
||||
* To create a BitmapText data files you can use:
|
||||
*
|
||||
* BMFont (Windows, free): http://www.angelcode.com/products/bmfont/
|
||||
* Glyph Designer (OS X, commercial): http://www.71squared.com/en/glyphdesigner
|
||||
* Littera (Web-based, free): http://kvazars.com/littera/
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#bitmapText
|
||||
* @param {number} x - X coordinate to display the BitmapText object at.
|
||||
* @param {number} y - Y coordinate to display the BitmapText object at.
|
||||
* @param {string} font - The key of the BitmapText as stored in Phaser.Cache.
|
||||
* @param {string} [text=''] - The text that will be rendered. This can also be set later via BitmapText.text.
|
||||
* @param {number} [size=32] - The size the font will be rendered at in pixels.
|
||||
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
|
||||
* @return {Phaser.BitmapText} The newly created bitmapText object.
|
||||
*/
|
||||
Phaser.GameObject.BitmapText.FACTORY_ADD = function (x, y, font, text, size, group)
|
||||
{
|
||||
if (group === undefined) { group = this.world; }
|
||||
|
||||
return group.add(new Phaser.GameObject.BitmapText(this.game, x, y, font, text, size));
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new BitmapText object.
|
||||
*
|
||||
* BitmapText objects work by taking a texture file and an XML file that describes the font structure.
|
||||
* It then generates a new Sprite object for each letter of the text, proportionally spaced out and aligned to
|
||||
* match the font structure.
|
||||
*
|
||||
* BitmapText objects are less flexible than Text objects, in that they have less features such as shadows, fills and the ability
|
||||
* to use Web Fonts. However you trade this flexibility for pure rendering speed. You can also create visually compelling BitmapTexts by
|
||||
* processing the font texture in an image editor first, applying fills and any other effects required.
|
||||
*
|
||||
* To create multi-line text insert \r, \n or \r\n escape codes into the text string.
|
||||
*
|
||||
* To create a BitmapText data files you can use:
|
||||
*
|
||||
* BMFont (Windows, free): http://www.angelcode.com/products/bmfont/
|
||||
* Glyph Designer (OS X, commercial): http://www.71squared.com/en/glyphdesigner
|
||||
* Littera (Web-based, free): http://kvazars.com/littera/
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#bitmapText
|
||||
* @param {number} x - X coordinate to display the BitmapText object at.
|
||||
* @param {number} y - Y coordinate to display the BitmapText object at.
|
||||
* @param {string} font - The key of the BitmapText as stored in Phaser.Cache.
|
||||
* @param {string} [text=''] - The text that will be rendered. This can also be set later via BitmapText.text.
|
||||
* @param {number} [size=32] - The size the font will be rendered at in pixels.
|
||||
* @param {string} [align='left'] - The alignment of multi-line text. Has no effect if there is only one line of text.
|
||||
* @return {Phaser.BitmapText} The newly created bitmapText object.
|
||||
*/
|
||||
Phaser.GameObject.BitmapText.FACTORY_MAKE = function (x, y, font, text, size, align)
|
||||
{
|
||||
return new Phaser.GameObject.BitmapText(this.game, x, y, font, text, size, align);
|
||||
};
|
|
@ -1,93 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Blitter Game Object.
|
||||
*
|
||||
* The Blitter Game Object is a special type of Container, that contains Blitter.Bob objects.
|
||||
* These objects can be thought of as just texture frames with a transform, and nothing more.
|
||||
* Bobs don't have any update methods, or the ability to have children, or any kind of special effects.
|
||||
* They are essentially just texture renderers, and the Blitter object creates and manages them.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.GameObject.Blitter = function (state, parent)
|
||||
{
|
||||
Phaser.GameObject.call(this, state, 0, 0, null, null, parent);
|
||||
|
||||
this.type = Phaser.BLITTER;
|
||||
|
||||
this.children = new Phaser.Component.Children(this);
|
||||
};
|
||||
|
||||
Phaser.GameObject.Blitter.prototype = Object.create(Phaser.GameObject.prototype);
|
||||
Phaser.GameObject.Blitter.prototype.constructor = Phaser.GameObject.Blitter;
|
||||
|
||||
Phaser.GameObject.Blitter.prototype.preUpdate = function ()
|
||||
{
|
||||
if (this.parent)
|
||||
{
|
||||
this.color.worldAlpha = this.parent.color.worldAlpha;
|
||||
}
|
||||
};
|
||||
|
||||
Phaser.GameObject.Blitter.prototype.create = function (x, y, key, frame, visible, index)
|
||||
{
|
||||
if (visible === undefined) { visible = true; }
|
||||
if (index === undefined) { index = 0; }
|
||||
|
||||
var bob = new Phaser.GameObject.Blitter.Bob(this, x, y, key, frame, visible);
|
||||
|
||||
this.children.addAt(bob, index, false);
|
||||
|
||||
return bob;
|
||||
};
|
||||
|
||||
Phaser.GameObject.Blitter.prototype.createFromCallback = function (callback, quantity, key, frame, visible)
|
||||
{
|
||||
var bobs = this.createMultiple(quantity, key, frame, visible);
|
||||
|
||||
for (var i = 0; i < bobs.length; i++)
|
||||
{
|
||||
var bob = bobs[i];
|
||||
|
||||
callback.call(this, bob, i);
|
||||
}
|
||||
|
||||
return bobs;
|
||||
};
|
||||
|
||||
Phaser.GameObject.Blitter.prototype.createMultiple = function (quantity, key, frame, visible)
|
||||
{
|
||||
if (frame === undefined) { frame = 0; }
|
||||
if (visible === undefined) { visible = true; }
|
||||
|
||||
if (!Array.isArray(key))
|
||||
{
|
||||
key = [ key ];
|
||||
}
|
||||
|
||||
if (!Array.isArray(frame))
|
||||
{
|
||||
frame = [ frame ];
|
||||
}
|
||||
|
||||
var bobs = [];
|
||||
var _this = this;
|
||||
|
||||
key.forEach(function (singleKey)
|
||||
{
|
||||
frame.forEach(function (singleFrame)
|
||||
{
|
||||
for (var i = 0; i < quantity; i++)
|
||||
{
|
||||
bobs.push(_this.create(0, 0, singleKey, singleFrame, visible));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return bobs;
|
||||
};
|
|
@ -1,19 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.GameObject.Blitter.FACTORY_KEY = 'blitter';
|
||||
|
||||
Phaser.GameObject.Blitter.FACTORY_ADD = function (parent)
|
||||
{
|
||||
if (parent === undefined) { parent = this.state; }
|
||||
|
||||
return parent.children.add(new Phaser.GameObject.Blitter(this.state, parent));
|
||||
};
|
||||
|
||||
Phaser.GameObject.Blitter.FACTORY_MAKE = function (parent)
|
||||
{
|
||||
return new Phaser.GameObject.Blitter(this.state, parent);
|
||||
};
|
|
@ -1,41 +0,0 @@
|
|||
Phaser.Renderer.WebGL.GameObjects.Blitter = {
|
||||
|
||||
TYPES: [
|
||||
Phaser.GameObject.Blitter.prototype
|
||||
],
|
||||
|
||||
render: function (renderer, src, interpolationPercentage)
|
||||
{
|
||||
var blitterAlpha = src.color.worldAlpha * 255 << 24;
|
||||
|
||||
// Skip rendering?
|
||||
if (src.skipRender || !src.visible || blitterAlpha === 0 || src.children.list.length === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var bg = src.color._glBg;
|
||||
var tint = src.color._glTint;
|
||||
var worldAlpha = src.color._worldAlpha;
|
||||
|
||||
// Render children
|
||||
for (var i = 0; i < src.children.list.length; i++)
|
||||
{
|
||||
var bob = src.children.list[i];
|
||||
var frame = bob.frame;
|
||||
var alpha = (worldAlpha * bob.alpha) * 255 << 24;
|
||||
|
||||
if (!bob.visible || alpha === 0 || !frame.cutWidth || !frame.cutHeight)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var index = frame.source.glTextureIndex;
|
||||
var verts = bob.transform.getVertexData(interpolationPercentage);
|
||||
|
||||
// tint and bg values come from the parent Blitter object, not the Bob
|
||||
renderer.batch.add(frame.source, src.blendMode, verts, frame.uvs, index, alpha, tint, bg);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
|
@ -1,281 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.GameObject.Blitter.Bob = function (parent, x, y, key, frame, visible)
|
||||
{
|
||||
if (visible === undefined) { visible = true; }
|
||||
|
||||
this.parent = parent;
|
||||
|
||||
this.texture = parent.state.game.textures.get(key);
|
||||
|
||||
this.frame = this.texture.get(frame);
|
||||
|
||||
this.transform = new Phaser.Component.Transform(this, x, y);
|
||||
|
||||
// Don't need to spam the UpdateManager with a Transform with no children
|
||||
this.transform.immediate = true;
|
||||
|
||||
this.type = 0;
|
||||
|
||||
// Do we need this?
|
||||
// this.color = new Phaser.Component.Color(this);
|
||||
|
||||
this.alpha = 1;
|
||||
|
||||
this.scaleMode = Phaser.scaleModes.DEFAULT;
|
||||
|
||||
this.visible = visible;
|
||||
};
|
||||
|
||||
Phaser.GameObject.Blitter.Bob.prototype.constructor = Phaser.GameObject.Blitter.Bob;
|
||||
|
||||
Phaser.GameObject.Blitter.Bob.prototype = {
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
this.parent.children.remove(this);
|
||||
|
||||
this.transform.destroy();
|
||||
|
||||
this.texture = undefined;
|
||||
this.frame = undefined;
|
||||
|
||||
this.parent = undefined;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperties(Phaser.GameObject.Blitter.Bob.prototype, {
|
||||
|
||||
// Transform getters / setters
|
||||
|
||||
x: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._posX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._posX = value;
|
||||
this.transform.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
y: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._posY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._posY = value;
|
||||
this.transform.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
scale: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._scaleX = value;
|
||||
this.transform._scaleY = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
scaleX: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._scaleX = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
scaleY: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._scaleY = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
anchor: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._anchorX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform.setAnchor(value);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
anchorX: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._anchorX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._anchorX = value;
|
||||
this.transform.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
anchorY: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._anchorY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._anchorY = value;
|
||||
this.transform.dirty = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
pivotX: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._pivotX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._pivotX = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
pivotY: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._pivotY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.transform._pivotY = value;
|
||||
this.transform.dirty = true;
|
||||
this.transform.updateCache();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
angle: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return Phaser.Math.wrapAngle(this.rotation * Phaser.Math.RAD_TO_DEG);
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.rotation = Phaser.Math.wrapAngle(value) * Phaser.Math.DEG_TO_RAD;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
rotation: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._rotation;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
if (this.transform._rotation === value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.transform._rotation = value;
|
||||
this.transform.dirty = true;
|
||||
|
||||
if (this.transform._rotation % Phaser.Math.PI2)
|
||||
{
|
||||
this.transform.cache.sr = Math.sin(this.transform._rotation);
|
||||
this.transform.cache.cr = Math.cos(this.transform._rotation);
|
||||
this.transform.updateCache();
|
||||
this.transform.hasLocalRotation = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.transform.hasLocalRotation = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -1,595 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a new `Button` object. A Button is a special type of Sprite that is set-up to handle Pointer events automatically.
|
||||
*
|
||||
* The four states a Button responds to are:
|
||||
*
|
||||
* * 'Over' - when the Pointer moves over the Button. This is also commonly known as 'hover'.
|
||||
* * 'Out' - when the Pointer that was previously over the Button moves out of it.
|
||||
* * 'Down' - when the Pointer is pressed down on the Button. I.e. touched on a touch enabled device or clicked with the mouse.
|
||||
* * 'Up' - when the Pointer that was pressed down on the Button is released again.
|
||||
*
|
||||
* A different texture/frame and activation sound can be specified for any of the states.
|
||||
*
|
||||
* Frames can be specified as either an integer (the frame ID) or a string (the frame name); the same values that can be used with a Sprite constructor.
|
||||
*
|
||||
* @class Phaser.GameObject.Button
|
||||
* @constructor
|
||||
* @extends Phaser.Image
|
||||
* @param {Phaser.Game} game Current game instance.
|
||||
* @param {number} [x=0] - X position of the Button.
|
||||
* @param {number} [y=0] - Y position of the Button.
|
||||
* @param {string} [key] - The image key (in the Game.Cache) to use as the texture for this Button.
|
||||
* @param {function} [callback] - The function to call when this Button is pressed.
|
||||
* @param {object} [callbackContext] - The context in which the callback will be called (usually 'this').
|
||||
* @param {string|integer} [overFrame] - The frame / frameName when the button is in the Over state.
|
||||
* @param {string|integer} [outFrame] - The frame / frameName when the button is in the Out state.
|
||||
* @param {string|integer} [downFrame] - The frame / frameName when the button is in the Down state.
|
||||
* @param {string|integer} [upFrame] - The frame / frameName when the button is in the Up state.
|
||||
*/
|
||||
Phaser.GameObject.Button = function (game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame) {
|
||||
|
||||
x = x || 0;
|
||||
y = y || 0;
|
||||
key = key || null;
|
||||
callback = callback || null;
|
||||
callbackContext = callbackContext || this;
|
||||
|
||||
Phaser.GameObject.Image.call(this, game, x, y, key, outFrame);
|
||||
|
||||
/**
|
||||
* The Phaser Object Type.
|
||||
* @property {number} type
|
||||
* @readonly
|
||||
*/
|
||||
this.type = Phaser.BUTTON;
|
||||
|
||||
/**
|
||||
* @property {number} physicsType - The const physics body type of this object.
|
||||
* @readonly
|
||||
*/
|
||||
this.physicsType = Phaser.SPRITE;
|
||||
|
||||
/**
|
||||
* The name or ID of the Over state frame.
|
||||
* @property {string|integer} onOverFrame
|
||||
* @private
|
||||
*/
|
||||
this._onOverFrame = null;
|
||||
|
||||
/**
|
||||
* The name or ID of the Out state frame.
|
||||
* @property {string|integer} onOutFrame
|
||||
* @private
|
||||
*/
|
||||
this._onOutFrame = null;
|
||||
|
||||
/**
|
||||
* The name or ID of the Down state frame.
|
||||
* @property {string|integer} onDownFrame
|
||||
* @private
|
||||
*/
|
||||
this._onDownFrame = null;
|
||||
|
||||
/**
|
||||
* The name or ID of the Up state frame.
|
||||
* @property {string|integer} onUpFrame
|
||||
* @private
|
||||
*/
|
||||
this._onUpFrame = null;
|
||||
|
||||
/**
|
||||
* The Sound to be played when this Buttons Over state is activated.
|
||||
* @property {Phaser.Sound|Phaser.AudioSprite|null} onOverSound
|
||||
* @readonly
|
||||
*/
|
||||
this.onOverSound = null;
|
||||
|
||||
/**
|
||||
* The Sound to be played when this Buttons Out state is activated.
|
||||
* @property {Phaser.Sound|Phaser.AudioSprite|null} onOutSound
|
||||
* @readonly
|
||||
*/
|
||||
this.onOutSound = null;
|
||||
|
||||
/**
|
||||
* The Sound to be played when this Buttons Down state is activated.
|
||||
* @property {Phaser.Sound|Phaser.AudioSprite|null} onDownSound
|
||||
* @readonly
|
||||
*/
|
||||
this.onDownSound = null;
|
||||
|
||||
/**
|
||||
* The Sound to be played when this Buttons Up state is activated.
|
||||
* @property {Phaser.Sound|Phaser.AudioSprite|null} onUpSound
|
||||
* @readonly
|
||||
*/
|
||||
this.onUpSound = null;
|
||||
|
||||
/**
|
||||
* The Sound Marker used in conjunction with the onOverSound.
|
||||
* @property {string} onOverSoundMarker
|
||||
* @readonly
|
||||
*/
|
||||
this.onOverSoundMarker = '';
|
||||
|
||||
/**
|
||||
* The Sound Marker used in conjunction with the onOutSound.
|
||||
* @property {string} onOutSoundMarker
|
||||
* @readonly
|
||||
*/
|
||||
this.onOutSoundMarker = '';
|
||||
|
||||
/**
|
||||
* The Sound Marker used in conjunction with the onDownSound.
|
||||
* @property {string} onDownSoundMarker
|
||||
* @readonly
|
||||
*/
|
||||
this.onDownSoundMarker = '';
|
||||
|
||||
/**
|
||||
* The Sound Marker used in conjunction with the onUpSound.
|
||||
* @property {string} onUpSoundMarker
|
||||
* @readonly
|
||||
*/
|
||||
this.onUpSoundMarker = '';
|
||||
|
||||
/**
|
||||
* The Signal (or event) dispatched when this Button is in an Over state.
|
||||
* @property {Phaser.Signal} onInputOver
|
||||
*/
|
||||
this.onInputOver = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* The Signal (or event) dispatched when this Button is in an Out state.
|
||||
* @property {Phaser.Signal} onInputOut
|
||||
*/
|
||||
this.onInputOut = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* The Signal (or event) dispatched when this Button is in an Down state.
|
||||
* @property {Phaser.Signal} onInputDown
|
||||
*/
|
||||
this.onInputDown = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* The Signal (or event) dispatched when this Button is in an Up state.
|
||||
* @property {Phaser.Signal} onInputUp
|
||||
*/
|
||||
this.onInputUp = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* If true then onOver events (such as onOverSound) will only be triggered if the Pointer object causing them was the Mouse Pointer.
|
||||
* The frame will still be changed as applicable.
|
||||
*
|
||||
* @property {boolean} onOverMouseOnly
|
||||
* @default
|
||||
*/
|
||||
this.onOverMouseOnly = true;
|
||||
|
||||
/**
|
||||
* Suppress the over event if a pointer was just released and it matches the given {@link Phaser.PointerModer pointer mode bitmask}.
|
||||
*
|
||||
* This behavior was introduced in Phaser 2.3.1; this property is a soft-revert of the change.
|
||||
*
|
||||
* @property {Phaser.PointerMode?} justReleasedPreventsOver=ACTIVE_CURSOR
|
||||
*/
|
||||
this.justReleasedPreventsOver = Phaser.PointerMode.TOUCH;
|
||||
|
||||
/**
|
||||
* When true the the texture frame will not be automatically switched on up/down/over/out events.
|
||||
* @property {boolean} freezeFrames
|
||||
* @default
|
||||
*/
|
||||
this.freezeFrames = false;
|
||||
|
||||
/**
|
||||
* When the Button is touched / clicked and then released you can force it to enter a state of "out" instead of "up".
|
||||
*
|
||||
* This can also accept a {@link Phaser.PointerModer pointer mode bitmask} for more refined control.
|
||||
*
|
||||
* @property {boolean|Phaser.PointerMode} forceOut=false
|
||||
* @default
|
||||
*/
|
||||
this.forceOut = false;
|
||||
|
||||
this.inputEnabled = true;
|
||||
|
||||
this.input.start(0, true);
|
||||
|
||||
this.input.useHandCursor = true;
|
||||
|
||||
this.setFrames(overFrame, outFrame, downFrame, upFrame);
|
||||
|
||||
if (callback !== null)
|
||||
{
|
||||
this.onInputUp.add(callback, callbackContext);
|
||||
}
|
||||
|
||||
// Redirect the input events to here so we can handle animation updates, etc
|
||||
this.events.onInputOver.add(this.onInputOverHandler, this);
|
||||
this.events.onInputOut.add(this.onInputOutHandler, this);
|
||||
this.events.onInputDown.add(this.onInputDownHandler, this);
|
||||
this.events.onInputUp.add(this.onInputUpHandler, this);
|
||||
|
||||
this.events.onRemovedFromWorld.add(this.removedFromWorld, this);
|
||||
|
||||
};
|
||||
|
||||
Phaser.GameObject.Button.prototype = Object.create(Phaser.GameObject.Image.prototype);
|
||||
Phaser.GameObject.Button.prototype.constructor = Phaser.GameObject.Button;
|
||||
|
||||
// State constants; local only. These are tied to property names in Phaser.GameObject.Button.
|
||||
var STATE_OVER = 'Over';
|
||||
var STATE_OUT = 'Out';
|
||||
var STATE_DOWN = 'Down';
|
||||
var STATE_UP = 'Up';
|
||||
|
||||
/**
|
||||
* Clears all of the frames set on this Button.
|
||||
*
|
||||
* @method Phaser.GameObject.Button#clearFrames
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.clearFrames = function () {
|
||||
|
||||
this.setFrames(null, null, null, null);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when this Button is removed from the World.
|
||||
*
|
||||
* @method Phaser.GameObject.Button#removedFromWorld
|
||||
* @protected
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.removedFromWorld = function () {
|
||||
|
||||
this.inputEnabled = false;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the frame name/ID for the given state.
|
||||
*
|
||||
* @method Phaser.GameObject.Button#setStateFrame
|
||||
* @private
|
||||
* @param {object} state - See `STATE_*`
|
||||
* @param {number|string} frame - The number or string representing the frame.
|
||||
* @param {boolean} switchImmediately - Immediately switch to the frame if it was set - and this is true.
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.setStateFrame = function (state, frame, switchImmediately)
|
||||
{
|
||||
var frameKey = '_on' + state + 'Frame';
|
||||
|
||||
if (frame !== null) // not null or undefined
|
||||
{
|
||||
this[frameKey] = frame;
|
||||
|
||||
if (switchImmediately)
|
||||
{
|
||||
this.changeStateFrame(state);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this[frameKey] = null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Change the frame to that of the given state, _if_ the state has a frame assigned _and_ if the frames are not currently "frozen".
|
||||
*
|
||||
* @method Phaser.GameObject.Button#changeStateFrame
|
||||
* @private
|
||||
* @param {object} state - See `STATE_*`
|
||||
* @return {boolean} True only if the frame was assigned a value, possibly the same one it already had.
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.changeStateFrame = function (state) {
|
||||
|
||||
if (this.freezeFrames)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var frameKey = '_on' + state + 'Frame';
|
||||
var frame = this[frameKey];
|
||||
|
||||
if (typeof frame === 'string')
|
||||
{
|
||||
this.frameName = frame;
|
||||
return true;
|
||||
}
|
||||
else if (typeof frame === 'number')
|
||||
{
|
||||
this.frame = frame;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Used to manually set the frames that will be used for the different states of the Button.
|
||||
*
|
||||
* Frames can be specified as either an integer (the frame ID) or a string (the frame name); these are the same values that can be used with a Sprite constructor.
|
||||
*
|
||||
* @method Phaser.GameObject.Button#setFrames
|
||||
* @public
|
||||
* @param {string|integer} [overFrame] - The frame / frameName when the button is in the Over state.
|
||||
* @param {string|integer} [outFrame] - The frame / frameName when the button is in the Out state.
|
||||
* @param {string|integer} [downFrame] - The frame / frameName when the button is in the Down state.
|
||||
* @param {string|integer} [upFrame] - The frame / frameName when the button is in the Up state.
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.setFrames = function (overFrame, outFrame, downFrame, upFrame) {
|
||||
|
||||
this.setStateFrame(STATE_OVER, overFrame, this.input.pointerOver());
|
||||
this.setStateFrame(STATE_OUT, outFrame, !this.input.pointerOver());
|
||||
this.setStateFrame(STATE_DOWN, downFrame, this.input.pointerDown());
|
||||
this.setStateFrame(STATE_UP, upFrame, this.input.pointerUp());
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the sound/marker for the given state.
|
||||
*
|
||||
* @method Phaser.GameObject.Button#setStateSound
|
||||
* @private
|
||||
* @param {object} state - See `STATE_*`
|
||||
* @param {Phaser.Sound|Phaser.AudioSprite} [sound] - Sound.
|
||||
* @param {string} [marker=''] - Sound marker.
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.setStateSound = function (state, sound, marker) {
|
||||
|
||||
var soundKey = 'on' + state + 'Sound';
|
||||
var markerKey = 'on' + state + 'SoundMarker';
|
||||
|
||||
if (sound instanceof Phaser.Sound || sound instanceof Phaser.AudioSprite)
|
||||
{
|
||||
this[soundKey] = sound;
|
||||
this[markerKey] = typeof marker === 'string' ? marker : '';
|
||||
}
|
||||
else
|
||||
{
|
||||
this[soundKey] = null;
|
||||
this[markerKey] = '';
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Play the sound for the given state, _if_ the state has a sound assigned.
|
||||
*
|
||||
* @method Phaser.GameObject.Button#playStateSound
|
||||
* @private
|
||||
* @param {object} state - See `STATE_*`
|
||||
* @return {boolean} True only if a sound was played.
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.playStateSound = function (state) {
|
||||
|
||||
var soundKey = 'on' + state + 'Sound';
|
||||
var sound = this[soundKey];
|
||||
|
||||
if (sound)
|
||||
{
|
||||
var markerKey = 'on' + state + 'SoundMarker';
|
||||
var marker = this[markerKey];
|
||||
|
||||
sound.play(marker);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the sounds to be played whenever this Button is interacted with. Sounds can be either full Sound objects, or markers pointing to a section of a Sound object.
|
||||
* The most common forms of sounds are 'hover' effects and 'click' effects, which is why the order of the parameters is overSound then downSound.
|
||||
*
|
||||
* Call this function with no parameters to reset all sounds on this Button.
|
||||
*
|
||||
* @method Phaser.GameObject.Button#setSounds
|
||||
* @public
|
||||
* @param {Phaser.Sound|Phaser.AudioSprite} [overSound] - Over Button Sound.
|
||||
* @param {string} [overMarker] - Over Button Sound Marker.
|
||||
* @param {Phaser.Sound|Phaser.AudioSprite} [downSound] - Down Button Sound.
|
||||
* @param {string} [downMarker] - Down Button Sound Marker.
|
||||
* @param {Phaser.Sound|Phaser.AudioSprite} [outSound] - Out Button Sound.
|
||||
* @param {string} [outMarker] - Out Button Sound Marker.
|
||||
* @param {Phaser.Sound|Phaser.AudioSprite} [upSound] - Up Button Sound.
|
||||
* @param {string} [upMarker] - Up Button Sound Marker.
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.setSounds = function (overSound, overMarker, downSound, downMarker, outSound, outMarker, upSound, upMarker) {
|
||||
|
||||
this.setStateSound(STATE_OVER, overSound, overMarker);
|
||||
this.setStateSound(STATE_OUT, outSound, outMarker);
|
||||
this.setStateSound(STATE_DOWN, downSound, downMarker);
|
||||
this.setStateSound(STATE_UP, upSound, upMarker);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The Sound to be played when a Pointer moves over this Button.
|
||||
*
|
||||
* @method Phaser.GameObject.Button#setOverSound
|
||||
* @public
|
||||
* @param {Phaser.Sound|Phaser.AudioSprite} sound - The Sound that will be played.
|
||||
* @param {string} [marker] - A Sound Marker that will be used in the playback.
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.setOverSound = function (sound, marker) {
|
||||
|
||||
this.setStateSound(STATE_OVER, sound, marker);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The Sound to be played when a Pointer moves out of this Button.
|
||||
*
|
||||
* @method Phaser.GameObject.Button#setOutSound
|
||||
* @public
|
||||
* @param {Phaser.Sound|Phaser.AudioSprite} sound - The Sound that will be played.
|
||||
* @param {string} [marker] - A Sound Marker that will be used in the playback.
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.setOutSound = function (sound, marker) {
|
||||
|
||||
this.setStateSound(STATE_OUT, sound, marker);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The Sound to be played when a Pointer presses down on this Button.
|
||||
*
|
||||
* @method Phaser.GameObject.Button#setDownSound
|
||||
* @public
|
||||
* @param {Phaser.Sound|Phaser.AudioSprite} sound - The Sound that will be played.
|
||||
* @param {string} [marker] - A Sound Marker that will be used in the playback.
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.setDownSound = function (sound, marker) {
|
||||
|
||||
this.setStateSound(STATE_DOWN, sound, marker);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The Sound to be played when a Pointer has pressed down and is released from this Button.
|
||||
*
|
||||
* @method Phaser.GameObject.Button#setUpSound
|
||||
* @public
|
||||
* @param {Phaser.Sound|Phaser.AudioSprite} sound - The Sound that will be played.
|
||||
* @param {string} [marker] - A Sound Marker that will be used in the playback.
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.setUpSound = function (sound, marker) {
|
||||
|
||||
this.setStateSound(STATE_UP, sound, marker);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Internal function that handles input events.
|
||||
*
|
||||
* @method Phaser.GameObject.Button#onInputOverHandler
|
||||
* @protected
|
||||
* @param {Phaser.GameObject.Button} sprite - The Button that the event occurred on.
|
||||
* @param {Phaser.Pointer} pointer - The Pointer that activated the Button.
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.onInputOverHandler = function (sprite, pointer) {
|
||||
|
||||
if (pointer.justReleased() &&
|
||||
(this.justReleasedPreventsOver & pointer.pointerMode) === pointer.pointerMode)
|
||||
{
|
||||
// If the Pointer was only just released then we don't fire an over event
|
||||
return;
|
||||
}
|
||||
|
||||
this.changeStateFrame(STATE_OVER);
|
||||
|
||||
if (this.onOverMouseOnly && !pointer.isMouse)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.playStateSound(STATE_OVER);
|
||||
|
||||
if (this.onInputOver)
|
||||
{
|
||||
this.onInputOver.dispatch(this, pointer);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Internal function that handles input events.
|
||||
*
|
||||
* @method Phaser.GameObject.Button#onInputOutHandler
|
||||
* @protected
|
||||
* @param {Phaser.GameObject.Button} sprite - The Button that the event occurred on.
|
||||
* @param {Phaser.Pointer} pointer - The Pointer that activated the Button.
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.onInputOutHandler = function (sprite, pointer) {
|
||||
|
||||
this.changeStateFrame(STATE_OUT);
|
||||
|
||||
this.playStateSound(STATE_OUT);
|
||||
|
||||
if (this.onInputOut)
|
||||
{
|
||||
this.onInputOut.dispatch(this, pointer);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Internal function that handles input events.
|
||||
*
|
||||
* @method Phaser.GameObject.Button#onInputDownHandler
|
||||
* @protected
|
||||
* @param {Phaser.GameObject.Button} sprite - The Button that the event occurred on.
|
||||
* @param {Phaser.Pointer} pointer - The Pointer that activated the Button.
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.onInputDownHandler = function (sprite, pointer) {
|
||||
|
||||
this.changeStateFrame(STATE_DOWN);
|
||||
|
||||
this.playStateSound(STATE_DOWN);
|
||||
|
||||
if (this.onInputDown)
|
||||
{
|
||||
this.onInputDown.dispatch(this, pointer);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Internal function that handles input events.
|
||||
*
|
||||
* @method Phaser.GameObject.Button#onInputUpHandler
|
||||
* @protected
|
||||
* @param {Phaser.GameObject.Button} sprite - The Button that the event occurred on.
|
||||
* @param {Phaser.Pointer} pointer - The Pointer that activated the Button.
|
||||
*/
|
||||
Phaser.GameObject.Button.prototype.onInputUpHandler = function (sprite, pointer, isOver) {
|
||||
|
||||
this.playStateSound(STATE_UP);
|
||||
|
||||
// Input dispatched early, before state change (but after sound)
|
||||
if (this.onInputUp)
|
||||
{
|
||||
this.onInputUp.dispatch(this, pointer, isOver);
|
||||
}
|
||||
|
||||
if (this.freezeFrames)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.forceOut === true || (this.forceOut & pointer.pointerMode) === pointer.pointerMode)
|
||||
{
|
||||
this.changeStateFrame(STATE_OUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
var changedUp = this.changeStateFrame(STATE_UP);
|
||||
if (!changedUp)
|
||||
{
|
||||
// No Up frame to show..
|
||||
if (isOver)
|
||||
{
|
||||
this.changeStateFrame(STATE_OVER);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.changeStateFrame(STATE_OUT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
|
@ -1,50 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.GameObject.Button.FACTORY_KEY = 'button';
|
||||
|
||||
/**
|
||||
* Creates a new Button object.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#button
|
||||
* @param {number} [x=0] - The x coordinate of the Button. The coordinate is relative to any parent container this button may be in.
|
||||
* @param {number} [y=0] - The y coordinate of the Button. The coordinate is relative to any parent container this button may be in.
|
||||
* @param {string} [key] - The image key as defined in the Game.Cache to use as the texture for this button.
|
||||
* @param {function} [callback] - The function to call when this button is pressed
|
||||
* @param {object} [callbackContext] - The context in which the callback will be called (usually 'this')
|
||||
* @param {string|number} [overFrame] - This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @param {string|number} [outFrame] - This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @param {string|number} [downFrame] - This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @param {string|number} [upFrame] - This is the frame or frameName that will be set when this button is in an up state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
|
||||
* @return {Phaser.Button} The newly created Button object.
|
||||
*/
|
||||
Phaser.GameObject.Button.FACTORY_ADD = function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame, group)
|
||||
{
|
||||
if (group === undefined) { group = this.world; }
|
||||
|
||||
return group.add(new Phaser.GameObject.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame));
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new Button object.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#button
|
||||
* @param {number} [x] X position of the new button object.
|
||||
* @param {number} [y] Y position of the new button object.
|
||||
* @param {string} [key] The image key as defined in the Game.Cache to use as the texture for this button.
|
||||
* @param {function} [callback] The function to call when this button is pressed
|
||||
* @param {object} [callbackContext] The context in which the callback will be called (usually 'this')
|
||||
* @param {string|number} [overFrame] This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @param {string|number} [outFrame] This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @param {string|number} [downFrame] This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @param {string|number} [upFrame] This is the frame or frameName that will be set when this button is in an up state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @return {Phaser.Button} The newly created button object.
|
||||
*/
|
||||
Phaser.GameObject.Button.FACTORY_MAKE = function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame)
|
||||
{
|
||||
return new Phaser.GameObject.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame);
|
||||
};
|
|
@ -1,45 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Angle Component provides access to an `angle` property; the rotation of a Game Object in degrees.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.Angle = function () {};
|
||||
|
||||
Phaser.Component.Angle.prototype = {
|
||||
|
||||
/**
|
||||
* The angle property is the rotation of the Game Object in *degrees* from its original orientation.
|
||||
*
|
||||
* Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
|
||||
*
|
||||
* Values outside this range are added to or subtracted from 360 to obtain a value within the range.
|
||||
* For example, the statement player.angle = 450 is the same as player.angle = 90.
|
||||
*
|
||||
* If you wish to work in radians instead of degrees you can use the property `rotation` instead.
|
||||
* Working in radians is slightly faster as it doesn't have to perform any calculations.
|
||||
*
|
||||
* @property {number} angle
|
||||
*/
|
||||
angle: {
|
||||
|
||||
get: function() {
|
||||
|
||||
return Phaser.Math.wrapAngle(Phaser.Math.radToDeg(this.rotation));
|
||||
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
this.rotation = Phaser.Math.degToRad(Phaser.Math.wrapAngle(value));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,40 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Animation Component provides a `play` method, which is a proxy to the `AnimationManager.play` method.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.Animation = function () {};
|
||||
|
||||
Phaser.Component.Animation.prototype = {
|
||||
|
||||
/**
|
||||
* Plays an Animation.
|
||||
*
|
||||
* The animation should have previously been created via `animations.add`.
|
||||
*
|
||||
* If the animation is already playing calling this again won't do anything.
|
||||
* If you need to reset an already running animation do so directly on the Animation object itself or via `AnimationManager.stop`.
|
||||
*
|
||||
* @method
|
||||
* @param {string} name - The name of the animation to be played, e.g. "fire", "walk", "jump". Must have been previously created via 'AnimationManager.add'.
|
||||
* @param {number} [frameRate=null] - The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
|
||||
* @param {boolean} [loop=false] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
|
||||
* @param {boolean} [killOnComplete=false] - If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
|
||||
* @return {Phaser.Animation} A reference to playing Animation.
|
||||
*/
|
||||
play: function (name, frameRate, loop, killOnComplete) {
|
||||
|
||||
if (this.animations)
|
||||
{
|
||||
return this.animations.play(name, frameRate, loop, killOnComplete);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,54 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The AutoCull Component is responsible for providing methods that check if a Game Object is within the bounds of the World Camera.
|
||||
* It is used by the InWorld component.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.AutoCull = function () {};
|
||||
|
||||
Phaser.Component.AutoCull.prototype = {
|
||||
|
||||
/**
|
||||
* A Game Object with `autoCull` set to true will check its bounds against the World Camera every frame.
|
||||
* If it is not intersecting the Camera bounds at any point then it has its `renderable` property set to `false`.
|
||||
* This keeps the Game Object alive and still processing updates, but forces it to skip the render step entirely.
|
||||
*
|
||||
* This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required,
|
||||
* or you have tested performance and find it acceptable.
|
||||
*
|
||||
* @property {boolean} autoCull
|
||||
* @default
|
||||
*/
|
||||
autoCull: false,
|
||||
|
||||
/**
|
||||
* Checks if the Game Objects bounds intersect with the Game Camera bounds.
|
||||
* Returns `true` if they do, otherwise `false` if fully outside of the Cameras bounds.
|
||||
*
|
||||
* @property {boolean} inCamera
|
||||
* @readonly
|
||||
*/
|
||||
inCamera: {
|
||||
|
||||
get: function() {
|
||||
|
||||
if (!this.autoCull && !this.checkWorldBounds)
|
||||
{
|
||||
this._bounds.copyFrom(this.getBounds());
|
||||
this._bounds.x += this.game.camera.view.x;
|
||||
this._bounds.y += this.game.camera.view.y;
|
||||
}
|
||||
|
||||
return this.game.world.camera.view.intersects(this._bounds);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,399 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Bounds component contains properties related to the bounds of the Game Object.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.Bounds = function () {};
|
||||
|
||||
Phaser.Component.Bounds.prototype = {
|
||||
|
||||
/**
|
||||
* The amount the Game Object is visually offset from its x coordinate.
|
||||
* This is the same as `width * anchor.x`.
|
||||
* It will only be > 0 if anchor.x is not equal to zero.
|
||||
*
|
||||
* @property {number} offsetX
|
||||
* @readOnly
|
||||
*/
|
||||
offsetX: {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.anchor.x * this.width;
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The amount the Game Object is visually offset from its y coordinate.
|
||||
* This is the same as `height * anchor.y`.
|
||||
* It will only be > 0 if anchor.y is not equal to zero.
|
||||
*
|
||||
* @property {number} offsetY
|
||||
* @readOnly
|
||||
*/
|
||||
offsetY: {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.anchor.y * this.height;
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The center x coordinate of the Game Object.
|
||||
* This is the same as `(x - offsetX) + (width / 2)`.
|
||||
*
|
||||
* @property {number} centerX
|
||||
*/
|
||||
centerX: {
|
||||
|
||||
get: function () {
|
||||
|
||||
return (this.x - this.offsetX) + (this.width * 0.5);
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.x = (value + this.offsetX) - (this.width * 0.5);
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The center y coordinate of the Game Object.
|
||||
* This is the same as `(y - offsetY) + (height / 2)`.
|
||||
*
|
||||
* @property {number} centerY
|
||||
*/
|
||||
centerY: {
|
||||
|
||||
get: function () {
|
||||
|
||||
return (this.y - this.offsetY) + (this.height * 0.5);
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.y = (value + this.offsetY) - (this.height * 0.5);
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The left coordinate of the Game Object.
|
||||
* This is the same as `x - offsetX`.
|
||||
*
|
||||
* @property {number} left
|
||||
*/
|
||||
left: {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.x - this.offsetX;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.x = value + this.offsetX;
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The right coordinate of the Game Object.
|
||||
* This is the same as `x + width - offsetX`.
|
||||
*
|
||||
* @property {number} right
|
||||
*/
|
||||
right: {
|
||||
|
||||
get: function () {
|
||||
|
||||
return (this.x + this.width) - this.offsetX;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.x = value - (this.width) + this.offsetX;
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The y coordinate of the Game Object.
|
||||
* This is the same as `y - offsetY`.
|
||||
*
|
||||
* @property {number} top
|
||||
*/
|
||||
top: {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.y - this.offsetY;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.y = value + this.offsetY;
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The sum of the y and height properties.
|
||||
* This is the same as `y + height - offsetY`.
|
||||
*
|
||||
* @property {number} bottom
|
||||
*/
|
||||
bottom: {
|
||||
|
||||
get: function () {
|
||||
|
||||
return (this.y + this.height) - this.offsetY;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.y = value - (this.height) + this.offsetY;
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Aligns this Game Object within another Game Object, or Rectangle, known as the
|
||||
* 'container', to one of 9 possible positions.
|
||||
*
|
||||
* The container must be a Game Object, or Phaser.Rectangle object. This can include properties
|
||||
* such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world
|
||||
* and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
|
||||
* TileSprites or Buttons.
|
||||
*
|
||||
* Please note that aligning a Sprite to another Game Object does **not** make it a child of
|
||||
* the container. It simply modifies its position coordinates so it aligns with it.
|
||||
*
|
||||
* The position constants you can use are:
|
||||
*
|
||||
* `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`,
|
||||
* `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`,
|
||||
* `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`.
|
||||
*
|
||||
* The Game Objects are placed in such a way that their _bounds_ align with the
|
||||
* container, taking into consideration rotation, scale and the anchor property.
|
||||
* This allows you to neatly align Game Objects, irrespective of their position value.
|
||||
*
|
||||
* The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final
|
||||
* aligned position of the Game Object. For example:
|
||||
*
|
||||
* `sprite.alignIn(background, Phaser.BOTTOM_RIGHT, -20, -20)`
|
||||
*
|
||||
* Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner.
|
||||
* Think of the offsets as applying an adjustment to the containers bounds before the alignment takes place.
|
||||
* So providing a negative offset will 'shrink' the container bounds by that amount, and providing a positive
|
||||
* one expands it.
|
||||
*
|
||||
* @method
|
||||
* @param {Phaser.Rectangle|Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapText|Phaser.Button|Phaser.Graphics|Phaser.TileSprite} container - The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`.
|
||||
* @param {integer} [position] - The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
|
||||
* @param {integer} [offsetX=0] - A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
|
||||
* @param {integer} [offsetY=0] - A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
|
||||
* @return {Object} This Game Object.
|
||||
*/
|
||||
alignIn: function (container, position, offsetX, offsetY) {
|
||||
|
||||
if (offsetX === undefined) { offsetX = 0; }
|
||||
if (offsetY === undefined) { offsetY = 0; }
|
||||
|
||||
switch (position)
|
||||
{
|
||||
default:
|
||||
case Phaser.TOP_LEFT:
|
||||
this.left = container.left - offsetX;
|
||||
this.top = container.top - offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.TOP_CENTER:
|
||||
this.centerX = container.centerX + offsetX;
|
||||
this.top = container.top - offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.TOP_RIGHT:
|
||||
this.right = container.right + offsetX;
|
||||
this.top = container.top - offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.LEFT_CENTER:
|
||||
this.left = container.left - offsetX;
|
||||
this.centerY = container.centerY + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.CENTER:
|
||||
this.centerX = container.centerX + offsetX;
|
||||
this.centerY = container.centerY + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.RIGHT_CENTER:
|
||||
this.right = container.right + offsetX;
|
||||
this.centerY = container.centerY + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.BOTTOM_LEFT:
|
||||
this.left = container.left - offsetX;
|
||||
this.bottom = container.bottom + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.BOTTOM_CENTER:
|
||||
this.centerX = container.centerX + offsetX;
|
||||
this.bottom = container.bottom + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.BOTTOM_RIGHT:
|
||||
this.right = container.right + offsetX;
|
||||
this.bottom = container.bottom + offsetY;
|
||||
break;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Aligns this Game Object to the side of another Game Object, or Rectangle, known as the
|
||||
* 'parent', in one of 11 possible positions.
|
||||
*
|
||||
* The parent must be a Game Object, or Phaser.Rectangle object. This can include properties
|
||||
* such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world
|
||||
* and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
|
||||
* TileSprites or Buttons.
|
||||
*
|
||||
* Please note that aligning a Sprite to another Game Object does **not** make it a child of
|
||||
* the parent. It simply modifies its position coordinates so it aligns with it.
|
||||
*
|
||||
* The position constants you can use are:
|
||||
*
|
||||
* `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`,
|
||||
* `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`,
|
||||
* `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER`
|
||||
* and `Phaser.BOTTOM_RIGHT`.
|
||||
*
|
||||
* The Game Objects are placed in such a way that their _bounds_ align with the
|
||||
* parent, taking into consideration rotation, scale and the anchor property.
|
||||
* This allows you to neatly align Game Objects, irrespective of their position value.
|
||||
*
|
||||
* The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final
|
||||
* aligned position of the Game Object. For example:
|
||||
*
|
||||
* `sprite.alignTo(background, Phaser.BOTTOM_RIGHT, -20, -20)`
|
||||
*
|
||||
* Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner.
|
||||
* Think of the offsets as applying an adjustment to the parents bounds before the alignment takes place.
|
||||
* So providing a negative offset will 'shrink' the parent bounds by that amount, and providing a positive
|
||||
* one expands it.
|
||||
*
|
||||
* @method
|
||||
* @param {Phaser.Rectangle|Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapText|Phaser.Button|Phaser.Graphics|Phaser.TileSprite} parent - The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`.
|
||||
* @param {integer} [position] - The position constant. One of `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
|
||||
* @param {integer} [offsetX=0] - A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
|
||||
* @param {integer} [offsetY=0] - A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
|
||||
* @return {Object} This Game Object.
|
||||
*/
|
||||
alignTo: function (parent, position, offsetX, offsetY) {
|
||||
|
||||
if (offsetX === undefined) { offsetX = 0; }
|
||||
if (offsetY === undefined) { offsetY = 0; }
|
||||
|
||||
switch (position)
|
||||
{
|
||||
default:
|
||||
case Phaser.TOP_LEFT:
|
||||
this.left = parent.left - offsetX;
|
||||
this.bottom = parent.top - offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.TOP_CENTER:
|
||||
this.centerX = parent.centerX + offsetX;
|
||||
this.bottom = parent.top - offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.TOP_RIGHT:
|
||||
this.right = parent.right + offsetX;
|
||||
this.bottom = parent.top - offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.LEFT_TOP:
|
||||
this.right = parent.left - offsetX;
|
||||
this.top = parent.top - offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.LEFT_CENTER:
|
||||
this.right = parent.left - offsetX;
|
||||
this.centerY = parent.centerY + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.LEFT_BOTTOM:
|
||||
this.right = parent.left - offsetX;
|
||||
this.bottom = parent.bottom + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.RIGHT_TOP:
|
||||
this.left = parent.right + offsetX;
|
||||
this.top = parent.top - offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.RIGHT_CENTER:
|
||||
this.left = parent.right + offsetX;
|
||||
this.centerY = parent.centerY + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.RIGHT_BOTTOM:
|
||||
this.left = parent.right + offsetX;
|
||||
this.bottom = parent.bottom + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.BOTTOM_LEFT:
|
||||
this.left = parent.left - offsetX;
|
||||
this.top = parent.bottom + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.BOTTOM_CENTER:
|
||||
this.centerX = parent.centerX + offsetX;
|
||||
this.top = parent.bottom + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.BOTTOM_RIGHT:
|
||||
this.right = parent.right + offsetX;
|
||||
this.top = parent.bottom + offsetY;
|
||||
break;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Phaser.Group extensions
|
||||
|
||||
Phaser.Group.prototype.alignIn = Phaser.Component.Bounds.prototype.alignIn;
|
||||
Phaser.Group.prototype.alignTo = Phaser.Component.Bounds.prototype.alignTo;
|
|
@ -1,96 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The BringToTop Component features quick access to Group sorting related methods.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.BringToTop = function () {};
|
||||
|
||||
/**
|
||||
* Brings this Game Object to the top of its parents display list.
|
||||
* Visually this means it will render over the top of any old child in the same Group.
|
||||
*
|
||||
* If this Game Object hasn't been added to a custom Group then this method will bring it to the top of the Game World,
|
||||
* because the World is the root Group from which all Game Objects descend.
|
||||
*
|
||||
* @method
|
||||
* @return {PIXI.DisplayObject} This instance.
|
||||
*/
|
||||
Phaser.Component.BringToTop.prototype.bringToTop = function() {
|
||||
|
||||
if (this.parent)
|
||||
{
|
||||
this.parent.bringToTop(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends this Game Object to the bottom of its parents display list.
|
||||
* Visually this means it will render below all other children in the same Group.
|
||||
*
|
||||
* If this Game Object hasn't been added to a custom Group then this method will send it to the bottom of the Game World,
|
||||
* because the World is the root Group from which all Game Objects descend.
|
||||
*
|
||||
* @method
|
||||
* @return {PIXI.DisplayObject} This instance.
|
||||
*/
|
||||
Phaser.Component.BringToTop.prototype.sendToBack = function() {
|
||||
|
||||
if (this.parent)
|
||||
{
|
||||
this.parent.sendToBack(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Moves this Game Object up one place in its parents display list.
|
||||
* This call has no effect if the Game Object is already at the top of the display list.
|
||||
*
|
||||
* If this Game Object hasn't been added to a custom Group then this method will move it one object up within the Game World,
|
||||
* because the World is the root Group from which all Game Objects descend.
|
||||
*
|
||||
* @method
|
||||
* @return {PIXI.DisplayObject} This instance.
|
||||
*/
|
||||
Phaser.Component.BringToTop.prototype.moveUp = function () {
|
||||
|
||||
if (this.parent)
|
||||
{
|
||||
this.parent.moveUp(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Moves this Game Object down one place in its parents display list.
|
||||
* This call has no effect if the Game Object is already at the bottom of the display list.
|
||||
*
|
||||
* If this Game Object hasn't been added to a custom Group then this method will move it one object down within the Game World,
|
||||
* because the World is the root Group from which all Game Objects descend.
|
||||
*
|
||||
* @method
|
||||
* @return {PIXI.DisplayObject} This instance.
|
||||
*/
|
||||
Phaser.Component.BringToTop.prototype.moveDown = function () {
|
||||
|
||||
if (this.parent)
|
||||
{
|
||||
this.parent.moveDown(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
};
|
|
@ -1,7 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.Component = function () {};
|
|
@ -1,361 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Core Component Features.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.Core = function () {};
|
||||
|
||||
/**
|
||||
* Installs / registers mixin components.
|
||||
*
|
||||
* The `this` context should be that of the applicable object instance or prototype.
|
||||
*
|
||||
* @method
|
||||
* @protected
|
||||
*/
|
||||
Phaser.Component.Core.install = function (components) {
|
||||
|
||||
// Always install 'Core' first
|
||||
Phaser.Utils.mixinPrototype(this, Phaser.Component.Core.prototype);
|
||||
|
||||
this.components = {};
|
||||
|
||||
for (var i = 0; i < components.length; i++)
|
||||
{
|
||||
var id = components[i];
|
||||
var replace = false;
|
||||
|
||||
if (id === 'Destroy')
|
||||
{
|
||||
replace = true;
|
||||
}
|
||||
|
||||
Phaser.Utils.mixinPrototype(this, Phaser.Component[id].prototype, replace);
|
||||
|
||||
this.components[id] = true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes the mixin components.
|
||||
*
|
||||
* The `this` context should be an instance of the component mixin target.
|
||||
*
|
||||
* @method
|
||||
* @protected
|
||||
*/
|
||||
Phaser.Component.Core.init = function (game, x, y, key, frame)
|
||||
{
|
||||
this.game = game;
|
||||
|
||||
this.key = key;
|
||||
|
||||
this.data = {};
|
||||
|
||||
this.texture = game.textures.get(key);
|
||||
|
||||
this.frame = (this.texture) ? this.texture.get(frame) : null;
|
||||
|
||||
this.position.set(x, y);
|
||||
this.world = new Phaser.Point(x, y);
|
||||
this.previousPosition = new Phaser.Point(x, y);
|
||||
|
||||
this.events = new Phaser.Events(this);
|
||||
|
||||
this._bounds = new Phaser.Rectangle();
|
||||
|
||||
if (this.components.PhysicsBody)
|
||||
{
|
||||
// Enable-body checks for hasOwnProperty; makes sure to lift property from prototype.
|
||||
this.body = this.body;
|
||||
}
|
||||
|
||||
if (this.components.Animation)
|
||||
{
|
||||
this.animations = new Phaser.AnimationManager(this);
|
||||
}
|
||||
|
||||
if (this.components.FixedToCamera)
|
||||
{
|
||||
this.cameraOffset = new Phaser.Point(x, y);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.Component.Core.preUpdate = function () {
|
||||
|
||||
if (this.pendingDestroy)
|
||||
{
|
||||
this.destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
this.previousPosition.set(this.world.x, this.world.y);
|
||||
this.previousRotation = this.rotation;
|
||||
|
||||
if (!this.exists || !this.parent.exists)
|
||||
{
|
||||
this.renderOrderID = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.world.setTo(this.game.camera.x + this.worldTransform.tx, this.game.camera.y + this.worldTransform.ty);
|
||||
|
||||
if (this.visible)
|
||||
{
|
||||
this.renderOrderID = this.game.stage.currentRenderOrderID++;
|
||||
}
|
||||
|
||||
if (this.animations)
|
||||
{
|
||||
this.animations.update();
|
||||
}
|
||||
|
||||
if (this.body)
|
||||
{
|
||||
this.body.preUpdate();
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
{
|
||||
this.children[i].preUpdate();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Component.Core.prototype = {
|
||||
|
||||
/**
|
||||
* A reference to the currently running Game.
|
||||
* @property {Phaser.Game} game
|
||||
*/
|
||||
game: null,
|
||||
|
||||
/**
|
||||
* A user defined name given to this Game Object.
|
||||
* This value isn't ever used internally by Phaser, it is meant as a game level property.
|
||||
* @property {string} name
|
||||
* @default
|
||||
*/
|
||||
name: '',
|
||||
|
||||
/**
|
||||
* An empty Object that belongs to this Game Object.
|
||||
* This value isn't ever used internally by Phaser, but may be used by your own code, or
|
||||
* by Phaser Plugins, to store data that needs to be associated with the Game Object,
|
||||
* without polluting the Game Object directly.
|
||||
* @property {Object} data
|
||||
* @default
|
||||
*/
|
||||
data: {},
|
||||
|
||||
/**
|
||||
* The components this Game Object has installed.
|
||||
* @property {object} components
|
||||
* @protected
|
||||
*/
|
||||
components: {},
|
||||
|
||||
/**
|
||||
* The z depth of this Game Object within its parent Group.
|
||||
* No two objects in a Group can have the same z value.
|
||||
* This value is adjusted automatically whenever the Group hierarchy changes.
|
||||
* If you wish to re-order the layering of a Game Object then see methods like Group.moveUp or Group.bringToTop.
|
||||
* @property {number} z
|
||||
* @readOnly
|
||||
*/
|
||||
z: 0,
|
||||
|
||||
/**
|
||||
* All Phaser Game Objects have an Events class which contains all of the events that are dispatched when certain things happen to this
|
||||
* Game Object, or any of its components.
|
||||
* @see Phaser.Events
|
||||
* @property {Phaser.Events} events
|
||||
*/
|
||||
events: undefined,
|
||||
|
||||
/**
|
||||
* If the Game Object is enabled for animation (such as a Phaser.Sprite) this is a reference to its AnimationManager instance.
|
||||
* Through it you can create, play, pause and stop animations.
|
||||
* @see Phaser.AnimationManager
|
||||
* @property {Phaser.AnimationManager} animations
|
||||
*/
|
||||
animations: undefined,
|
||||
|
||||
/**
|
||||
* The key of the image or texture used by this Game Object during rendering.
|
||||
* If it is a string it's the string used to retrieve the texture from the Phaser Image Cache.
|
||||
* It can also be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
|
||||
* If a Game Object is created without a key it is automatically assigned the key `__default` which is a 32x32 transparent PNG stored within the Cache.
|
||||
* If a Game Object is given a key which doesn't exist in the Image Cache it is re-assigned the key `__missing` which is a 32x32 PNG of a green box with a line through it.
|
||||
* @property {string|Phaser.RenderTexture|Phaser.BitmapData|Phaser.Video|PIXI.Texture} key
|
||||
*/
|
||||
key: '',
|
||||
|
||||
/**
|
||||
* The world coordinates of this Game Object in pixels.
|
||||
* Depending on where in the display list this Game Object is placed this value can differ from `position`,
|
||||
* which contains the x/y coordinates relative to the Game Objects parent.
|
||||
* @property {Phaser.Point} world
|
||||
*/
|
||||
world: null,
|
||||
|
||||
/**
|
||||
* A debug flag designed for use with `Game.enableStep`.
|
||||
* @property {boolean} debug
|
||||
* @default
|
||||
*/
|
||||
debug: false,
|
||||
|
||||
/**
|
||||
* The position the Game Object was located in the previous frame.
|
||||
* @property {Phaser.Point} previousPosition
|
||||
* @readOnly
|
||||
*/
|
||||
previousPosition: null,
|
||||
|
||||
/**
|
||||
* The rotation the Game Object was in set to in the previous frame. Value is in radians.
|
||||
* @property {number} previousRotation
|
||||
* @readOnly
|
||||
*/
|
||||
previousRotation: 0,
|
||||
|
||||
/**
|
||||
* The render order ID is used internally by the renderer and Input Manager and should not be modified.
|
||||
* This property is mostly used internally by the renderers, but is exposed for the use of plugins.
|
||||
* @property {number} renderOrderID
|
||||
* @readOnly
|
||||
*/
|
||||
renderOrderID: 0,
|
||||
|
||||
/**
|
||||
* A Game Object is considered `fresh` if it has just been created or reset and is yet to receive a renderer transform update.
|
||||
* This property is mostly used internally by the physics systems, but is exposed for the use of plugins.
|
||||
* @property {boolean} fresh
|
||||
* @readOnly
|
||||
*/
|
||||
fresh: true,
|
||||
|
||||
/**
|
||||
* A Game Object is that is pendingDestroy is flagged to have its destroy method called on the next logic update.
|
||||
* You can set it directly to allow you to flag an object to be destroyed on its next update.
|
||||
*
|
||||
* This is extremely useful if you wish to destroy an object from within one of its own callbacks
|
||||
* such as with Buttons or other Input events.
|
||||
*
|
||||
* @property {boolean} pendingDestroy
|
||||
*/
|
||||
pendingDestroy: false,
|
||||
|
||||
/**
|
||||
* @property {Phaser.Rectangle} _bounds - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
_bounds: null,
|
||||
|
||||
/**
|
||||
* @property {boolean} _exists - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
_exists: true,
|
||||
|
||||
/**
|
||||
* Controls if this Game Object is processed by the core game loop.
|
||||
* If this Game Object has a physics body it also controls if its physics body is updated or not.
|
||||
* When `exists` is set to `false` it will remove its physics body from the physics world if it has one.
|
||||
* It also toggles the `visible` property to false as well.
|
||||
*
|
||||
* Setting `exists` to true will add its physics body back in to the physics world, if it has one.
|
||||
* It will also set the `visible` property to `true`.
|
||||
*
|
||||
* @property {boolean} exists
|
||||
*/
|
||||
exists: {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this._exists;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value)
|
||||
{
|
||||
this._exists = true;
|
||||
|
||||
if (this.body && this.body.type === Phaser.Physics.P2JS)
|
||||
{
|
||||
this.body.addToWorld();
|
||||
}
|
||||
|
||||
this.visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._exists = false;
|
||||
|
||||
if (this.body && this.body.type === Phaser.Physics.P2JS)
|
||||
{
|
||||
this.body.removeFromWorld();
|
||||
}
|
||||
|
||||
this.visible = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Override this method in your own custom objects to handle any update requirements.
|
||||
* It is called immediately after `preUpdate` and before `postUpdate`.
|
||||
* Remember if this Game Object has any children you should call update on those too.
|
||||
*
|
||||
* @method
|
||||
*/
|
||||
update: function() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal method called by the World postUpdate cycle.
|
||||
*
|
||||
* @method
|
||||
* @protected
|
||||
*/
|
||||
postUpdate: function() {
|
||||
|
||||
if (this.customRender)
|
||||
{
|
||||
this.key.render();
|
||||
}
|
||||
|
||||
if (this.components.PhysicsBody)
|
||||
{
|
||||
Phaser.Component.PhysicsBody.postUpdate.call(this);
|
||||
}
|
||||
|
||||
if (this.components.FixedToCamera)
|
||||
{
|
||||
Phaser.Component.FixedToCamera.postUpdate.call(this);
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
{
|
||||
this.children[i].postUpdate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,127 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Crop component provides the ability to crop a texture based Game Object to a defined rectangle,
|
||||
* which can be updated in real-time.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.Crop = function () {};
|
||||
|
||||
Phaser.Component.Crop.prototype = {
|
||||
|
||||
/**
|
||||
* The Rectangle used to crop the texture this Game Object uses.
|
||||
* Set this property via `crop`.
|
||||
* If you modify this property directly you must call `updateCrop` in order to have the change take effect.
|
||||
* @property {Phaser.Rectangle} cropRect
|
||||
* @default
|
||||
*/
|
||||
cropRect: null,
|
||||
|
||||
/**
|
||||
* @property {Phaser.Rectangle} _crop - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
_crop: null,
|
||||
|
||||
/**
|
||||
* Crop allows you to crop the texture being used to display this Game Object.
|
||||
* Setting a crop rectangle modifies the core texture frame. The Game Object width and height properties will be adjusted accordingly.
|
||||
*
|
||||
* Cropping takes place from the top-left and can be modified in real-time either by providing an updated rectangle object to this method,
|
||||
* or by modifying `cropRect` property directly and then calling `updateCrop`.
|
||||
*
|
||||
* The rectangle object given to this method can be either a `Phaser.Rectangle` or any other object
|
||||
* so long as it has public `x`, `y`, `width`, `height`, `right` and `bottom` properties.
|
||||
*
|
||||
* A reference to the rectangle is stored in `cropRect` unless the `copy` parameter is `true`,
|
||||
* in which case the values are duplicated to a local object.
|
||||
*
|
||||
* @method
|
||||
* @param {Phaser.Rectangle} rect - The Rectangle used during cropping. Pass null or no parameters to clear a previously set crop rectangle.
|
||||
* @param {boolean} [copy=false] - If false `cropRect` will be stored as a reference to the given rect. If true it will copy the rect values into a local Phaser Rectangle object stored in cropRect.
|
||||
*/
|
||||
crop: function (rect, copy) {
|
||||
|
||||
if (copy === undefined) { copy = false; }
|
||||
|
||||
if (rect)
|
||||
{
|
||||
if (copy && this.cropRect !== null)
|
||||
{
|
||||
this.cropRect.setTo(rect.x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
else if (copy && this.cropRect === null)
|
||||
{
|
||||
this.cropRect = new Phaser.Rectangle(rect.x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cropRect = rect;
|
||||
}
|
||||
|
||||
this.updateCrop();
|
||||
}
|
||||
else
|
||||
{
|
||||
this._crop = null;
|
||||
this.cropRect = null;
|
||||
|
||||
this.resetFrame();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* If you have set a crop rectangle on this Game Object via `crop` and since modified the `cropRect` property,
|
||||
* or the rectangle it references, then you need to update the crop frame by calling this method.
|
||||
*
|
||||
* @method
|
||||
*/
|
||||
updateCrop: function () {
|
||||
|
||||
if (!this.cropRect)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var oldX = this.texture.crop.x;
|
||||
var oldY = this.texture.crop.y;
|
||||
var oldW = this.texture.crop.width;
|
||||
var oldH = this.texture.crop.height;
|
||||
|
||||
this._crop = Phaser.Rectangle.clone(this.cropRect, this._crop);
|
||||
this._crop.x += this._frame.x;
|
||||
this._crop.y += this._frame.y;
|
||||
|
||||
var cx = Math.max(this._frame.x, this._crop.x);
|
||||
var cy = Math.max(this._frame.y, this._crop.y);
|
||||
var cw = Math.min(this._frame.right, this._crop.right) - cx;
|
||||
var ch = Math.min(this._frame.bottom, this._crop.bottom) - cy;
|
||||
|
||||
this.texture.crop.x = cx;
|
||||
this.texture.crop.y = cy;
|
||||
this.texture.crop.width = cw;
|
||||
this.texture.crop.height = ch;
|
||||
|
||||
this.texture.frame.width = Math.min(cw, this.cropRect.width);
|
||||
this.texture.frame.height = Math.min(ch, this.cropRect.height);
|
||||
|
||||
this.texture.width = this.texture.frame.width;
|
||||
this.texture.height = this.texture.frame.height;
|
||||
|
||||
this.texture._updateUvs();
|
||||
|
||||
if (this.tint !== 0xffffff && (oldX !== cx || oldY !== cy || oldW !== cw || oldH !== ch))
|
||||
{
|
||||
this.texture.requiresReTint = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,68 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Delta component provides access to delta values between the Game Objects current and previous position.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.Delta = function () {};
|
||||
|
||||
Phaser.Component.Delta.prototype = {
|
||||
|
||||
/**
|
||||
* Returns the delta x value. The difference between world.x now and in the previous frame.
|
||||
*
|
||||
* The value will be positive if the Game Object has moved to the right or negative if to the left.
|
||||
*
|
||||
* @property {number} deltaX
|
||||
* @readonly
|
||||
*/
|
||||
deltaX: {
|
||||
|
||||
get: function() {
|
||||
|
||||
return this.world.x - this.previousPosition.x;
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the delta y value. The difference between world.y now and in the previous frame.
|
||||
*
|
||||
* The value will be positive if the Game Object has moved down or negative if up.
|
||||
*
|
||||
* @property {number} deltaY
|
||||
* @readonly
|
||||
*/
|
||||
deltaY: {
|
||||
|
||||
get: function() {
|
||||
|
||||
return this.world.y - this.previousPosition.y;
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the delta z value. The difference between rotation now and in the previous frame.
|
||||
*
|
||||
* @property {number} deltaZ - The delta value.
|
||||
* @readonly
|
||||
*/
|
||||
deltaZ: {
|
||||
|
||||
get: function() {
|
||||
|
||||
return this.rotation - this.previousRotation;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,165 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Destroy component is responsible for destroying a Game Object.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.Destroy = function () {};
|
||||
|
||||
Phaser.Component.Destroy.prototype = {
|
||||
|
||||
/**
|
||||
* As a Game Object runs through its destroy method this flag is set to true,
|
||||
* and can be checked in any sub-systems or plugins it is being destroyed from.
|
||||
* @property {boolean} destroyPhase
|
||||
* @readOnly
|
||||
*/
|
||||
destroyPhase: false,
|
||||
|
||||
/**
|
||||
* Destroys the Game Object. This removes it from its parent group, destroys the input, event and animation handlers if present
|
||||
* and nulls its reference to `game`, freeing it up for garbage collection.
|
||||
*
|
||||
* If this Game Object has the Events component it will also dispatch the `onDestroy` event.
|
||||
*
|
||||
* You can optionally also destroy the BaseTexture this Game Object is using. Be careful if you've
|
||||
* more than one Game Object sharing the same BaseTexture.
|
||||
*
|
||||
* @method
|
||||
* @param {boolean} [destroyChildren=true] - Should every child of this object have its destroy method called as well?
|
||||
* @param {boolean} [destroyTexture=false] - Destroy the BaseTexture this Game Object is using? Note that if another Game Object is sharing the same BaseTexture it will invalidate it.
|
||||
*/
|
||||
destroy: function (destroyChildren, destroyTexture) {
|
||||
|
||||
if (this.game === null || this.destroyPhase) { return; }
|
||||
|
||||
if (destroyChildren === undefined) { destroyChildren = true; }
|
||||
if (destroyTexture === undefined) { destroyTexture = false; }
|
||||
|
||||
this.destroyPhase = true;
|
||||
|
||||
if (this.events)
|
||||
{
|
||||
this.events.onDestroy$dispatch(this);
|
||||
}
|
||||
|
||||
if (this.parent)
|
||||
{
|
||||
if (this.parent instanceof Phaser.Group)
|
||||
{
|
||||
this.parent.remove(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parent.removeChild(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.input)
|
||||
{
|
||||
this.input.destroy();
|
||||
}
|
||||
|
||||
if (this.animations)
|
||||
{
|
||||
this.animations.destroy();
|
||||
}
|
||||
|
||||
if (this.body)
|
||||
{
|
||||
this.body.destroy();
|
||||
}
|
||||
|
||||
if (this.events)
|
||||
{
|
||||
this.events.destroy();
|
||||
}
|
||||
|
||||
this.game.tweens.removeFrom(this);
|
||||
|
||||
var i = this.children.length;
|
||||
|
||||
if (destroyChildren)
|
||||
{
|
||||
while (i--)
|
||||
{
|
||||
this.children[i].destroy(destroyChildren);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (i--)
|
||||
{
|
||||
this.removeChild(this.children[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (this._crop)
|
||||
{
|
||||
this._crop = null;
|
||||
this.cropRect = null;
|
||||
}
|
||||
|
||||
if (this._frame)
|
||||
{
|
||||
this._frame = null;
|
||||
}
|
||||
|
||||
if (Phaser.Video && this.key instanceof Phaser.Video)
|
||||
{
|
||||
this.key.onChangeSource.remove(this.resizeFrame, this);
|
||||
}
|
||||
|
||||
if (Phaser.BitmapText && this._glyphs)
|
||||
{
|
||||
this._glyphs = [];
|
||||
}
|
||||
|
||||
this.alive = false;
|
||||
this.exists = false;
|
||||
this.visible = false;
|
||||
|
||||
this.filters = null;
|
||||
this.mask = null;
|
||||
this.game = null;
|
||||
|
||||
this.data = {};
|
||||
|
||||
// In case Pixi is still going to try and render it even though destroyed
|
||||
this.renderable = false;
|
||||
|
||||
if (this.transformCallback)
|
||||
{
|
||||
this.transformCallback = null;
|
||||
this.transformCallbackContext = null;
|
||||
}
|
||||
|
||||
// Pixi level DisplayObject destroy
|
||||
this.hitArea = null;
|
||||
this.parent = null;
|
||||
this.stage = null;
|
||||
this.worldTransform = null;
|
||||
this.filterArea = null;
|
||||
this._bounds = null;
|
||||
this._currentBounds = null;
|
||||
this._mask = null;
|
||||
|
||||
this._destroyCachedSprite();
|
||||
|
||||
// Texture?
|
||||
if (destroyTexture)
|
||||
{
|
||||
this.texture.destroy(true);
|
||||
}
|
||||
|
||||
this.destroyPhase = false;
|
||||
this.pendingDestroy = false;
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,295 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Events component is a collection of events fired by the parent Game Object.
|
||||
*
|
||||
* Phaser uses what are known as 'Signals' for all event handling. All of the events in
|
||||
* this class are signals you can subscribe to, much in the same way you'd "listen" for
|
||||
* an event.
|
||||
*
|
||||
* For example to tell when a Sprite has been added to a new group, you can bind a function
|
||||
* to the `onAddedToGroup` signal:
|
||||
*
|
||||
* `sprite.events.onAddedToGroup.add(yourFunction, this);`
|
||||
*
|
||||
* Where `yourFunction` is the function you want called when this event occurs.
|
||||
*
|
||||
* For more details about how signals work please see the Phaser.Signal class.
|
||||
*
|
||||
* The Input-related events will only be dispatched if the Sprite has had `inputEnabled` set to `true`
|
||||
* and the Animation-related events only apply to game objects with animations like {@link Phaser.Sprite}.
|
||||
*
|
||||
* @class Phaser.Events
|
||||
* @constructor
|
||||
* @param {Phaser.Sprite} sprite - A reference to the game object / Sprite that owns this Events object.
|
||||
*/
|
||||
Phaser.Events = function (sprite) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Sprite} parent - The Sprite that owns these events.
|
||||
*/
|
||||
this.parent = sprite;
|
||||
|
||||
// The signals are automatically added by the corresponding proxy properties
|
||||
|
||||
};
|
||||
|
||||
Phaser.Events.prototype = {
|
||||
|
||||
/**
|
||||
* Removes all events.
|
||||
*
|
||||
* @method Phaser.Events#destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
|
||||
this._parent = null;
|
||||
|
||||
if (this._onDestroy) { this._onDestroy.dispose(); }
|
||||
if (this._onAddedToGroup) { this._onAddedToGroup.dispose(); }
|
||||
if (this._onRemovedFromGroup) { this._onRemovedFromGroup.dispose(); }
|
||||
if (this._onRemovedFromWorld) { this._onRemovedFromWorld.dispose(); }
|
||||
if (this._onKilled) { this._onKilled.dispose(); }
|
||||
if (this._onRevived) { this._onRevived.dispose(); }
|
||||
if (this._onEnterBounds) { this._onEnterBounds.dispose(); }
|
||||
if (this._onOutOfBounds) { this._onOutOfBounds.dispose(); }
|
||||
|
||||
if (this._onInputOver) { this._onInputOver.dispose(); }
|
||||
if (this._onInputOut) { this._onInputOut.dispose(); }
|
||||
if (this._onInputDown) { this._onInputDown.dispose(); }
|
||||
if (this._onInputUp) { this._onInputUp.dispose(); }
|
||||
if (this._onDragStart) { this._onDragStart.dispose(); }
|
||||
if (this._onDragUpdate) { this._onDragUpdate.dispose(); }
|
||||
if (this._onDragStop) { this._onDragStop.dispose(); }
|
||||
|
||||
if (this._onAnimationStart) { this._onAnimationStart.dispose(); }
|
||||
if (this._onAnimationComplete) { this._onAnimationComplete.dispose(); }
|
||||
if (this._onAnimationLoop) { this._onAnimationLoop.dispose(); }
|
||||
|
||||
},
|
||||
|
||||
// The following properties are sentinels that will be replaced with getters
|
||||
|
||||
/**
|
||||
* This signal is dispatched when this Game Object is added to a new Group.
|
||||
* It is sent two arguments:
|
||||
* {any} The Game Object that was added to the Group.
|
||||
* {Phaser.Group} The Group it was added to.
|
||||
* @property {Phaser.Signal} onAddedToGroup
|
||||
*/
|
||||
onAddedToGroup: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched when the Game Object is removed from a Group.
|
||||
* It is sent two arguments:
|
||||
* {any} The Game Object that was removed from the Group.
|
||||
* {Phaser.Group} The Group it was removed from.
|
||||
* @property {Phaser.Signal} onRemovedFromGroup
|
||||
*/
|
||||
onRemovedFromGroup: null,
|
||||
|
||||
/**
|
||||
* This Signal is never used internally by Phaser and is now deprecated.
|
||||
* @deprecated
|
||||
* @property {Phaser.Signal} onRemovedFromWorld
|
||||
*/
|
||||
onRemovedFromWorld: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched when the Game Object is destroyed.
|
||||
* This happens when `Sprite.destroy()` is called, or `Group.destroy()` with `destroyChildren` set to true.
|
||||
* It is sent one argument:
|
||||
* {any} The Game Object that was destroyed.
|
||||
* @property {Phaser.Signal} onDestroy
|
||||
*/
|
||||
onDestroy: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched when the Game Object is killed.
|
||||
* This happens when `Sprite.kill()` is called.
|
||||
* Please understand the difference between `kill` and `destroy` by looking at their respective methods.
|
||||
* It is sent one argument:
|
||||
* {any} The Game Object that was killed.
|
||||
* @property {Phaser.Signal} onKilled
|
||||
*/
|
||||
onKilled: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched when the Game Object is revived from a previously killed state.
|
||||
* This happens when `Sprite.revive()` is called.
|
||||
* It is sent one argument:
|
||||
* {any} The Game Object that was revived.
|
||||
* @property {Phaser.Signal} onRevived
|
||||
*/
|
||||
onRevived: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched when the Game Object leaves the Phaser.World bounds.
|
||||
* This signal is only if `Sprite.checkWorldBounds` is set to `true`.
|
||||
* It is sent one argument:
|
||||
* {any} The Game Object that left the World bounds.
|
||||
* @property {Phaser.Signal} onOutOfBounds
|
||||
*/
|
||||
onOutOfBounds: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched when the Game Object returns within the Phaser.World bounds, having previously been outside of them.
|
||||
* This signal is only if `Sprite.checkWorldBounds` is set to `true`.
|
||||
* It is sent one argument:
|
||||
* {any} The Game Object that entered the World bounds.
|
||||
* @property {Phaser.Signal} onEnterBounds
|
||||
*/
|
||||
onEnterBounds: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched if the Game Object has `inputEnabled` set to `true`,
|
||||
* and receives an over event from a Phaser.Pointer.
|
||||
* It is sent two arguments:
|
||||
* {any} The Game Object that received the event.
|
||||
* {Phaser.Pointer} The Phaser.Pointer object that caused the event.
|
||||
* @property {Phaser.Signal} onInputOver
|
||||
*/
|
||||
onInputOver: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched if the Game Object has `inputEnabled` set to `true`,
|
||||
* and receives an out event from a Phaser.Pointer, which was previously over it.
|
||||
* It is sent two arguments:
|
||||
* {any} The Game Object that received the event.
|
||||
* {Phaser.Pointer} The Phaser.Pointer object that caused the event.
|
||||
* @property {Phaser.Signal} onInputOut
|
||||
*/
|
||||
onInputOut: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched if the Game Object has `inputEnabled` set to `true`,
|
||||
* and receives a down event from a Phaser.Pointer. This effectively means the Pointer has been
|
||||
* pressed down (but not yet released) on the Game Object.
|
||||
* It is sent two arguments:
|
||||
* {any} The Game Object that received the event.
|
||||
* {Phaser.Pointer} The Phaser.Pointer object that caused the event.
|
||||
* @property {Phaser.Signal} onInputDown
|
||||
*/
|
||||
onInputDown: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched if the Game Object has `inputEnabled` set to `true`,
|
||||
* and receives an up event from a Phaser.Pointer. This effectively means the Pointer had been
|
||||
* pressed down, and was then released on the Game Object.
|
||||
* It is sent three arguments:
|
||||
* {any} The Game Object that received the event.
|
||||
* {Phaser.Pointer} The Phaser.Pointer object that caused the event.
|
||||
* {boolean} isOver - Is the Pointer still over the Game Object?
|
||||
* @property {Phaser.Signal} onInputUp
|
||||
*/
|
||||
onInputUp: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched if the Game Object has been `inputEnabled` and `enableDrag` has been set.
|
||||
* It is sent when a Phaser.Pointer starts to drag the Game Object, taking into consideration the various
|
||||
* drag limitations that may be set.
|
||||
* It is sent four arguments:
|
||||
* {any} The Game Object that received the event.
|
||||
* {Phaser.Pointer} The Phaser.Pointer object that caused the event.
|
||||
* {number} The x coordinate that the drag started from.
|
||||
* {number} The y coordinate that the drag started from.
|
||||
* @property {Phaser.Signal} onDragStart
|
||||
*/
|
||||
onDragStart: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched if the Game Object has been `inputEnabled` and `enableDrag` has been set.
|
||||
* It is sent when a Phaser.Pointer is actively dragging the Game Object.
|
||||
* Be warned: This is a high volume Signal. Be careful what you bind to it.
|
||||
* It is sent six arguments:
|
||||
* {any} The Game Object that received the event.
|
||||
* {Phaser.Pointer} The Phaser.Pointer object that caused the event.
|
||||
* {number} The new x coordinate of the Game Object.
|
||||
* {number} The new y coordinate of the Game Object.
|
||||
* {Phaser.Point} A Point object that contains the point the Game Object was snapped to, if `snapOnDrag` has been enabled.
|
||||
* {boolean} The `fromStart` boolean, indicates if this is the first update immediately after the drag has started.
|
||||
* @property {Phaser.Signal} onDragUpdate
|
||||
*/
|
||||
onDragUpdate: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched if the Game Object has been `inputEnabled` and `enableDrag` has been set.
|
||||
* It is sent when a Phaser.Pointer stops dragging the Game Object.
|
||||
* It is sent two arguments:
|
||||
* {any} The Game Object that received the event.
|
||||
* {Phaser.Pointer} The Phaser.Pointer object that caused the event.
|
||||
* @property {Phaser.Signal} onDragStop
|
||||
*/
|
||||
onDragStop: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched if the Game Object has the AnimationManager component,
|
||||
* and an Animation has been played.
|
||||
* You can also listen to `Animation.onStart` rather than via the Game Objects events.
|
||||
* It is sent two arguments:
|
||||
* {any} The Game Object that received the event.
|
||||
* {Phaser.Animation} The Phaser.Animation that was started.
|
||||
* @property {Phaser.Signal} onAnimationStart
|
||||
*/
|
||||
onAnimationStart: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched if the Game Object has the AnimationManager component,
|
||||
* and an Animation has been stopped (via `animation.stop()` and the `dispatchComplete` argument has been set.
|
||||
* You can also listen to `Animation.onComplete` rather than via the Game Objects events.
|
||||
* It is sent two arguments:
|
||||
* {any} The Game Object that received the event.
|
||||
* {Phaser.Animation} The Phaser.Animation that was stopped.
|
||||
* @property {Phaser.Signal} onAnimationComplete
|
||||
*/
|
||||
onAnimationComplete: null,
|
||||
|
||||
/**
|
||||
* This signal is dispatched if the Game Object has the AnimationManager component,
|
||||
* and an Animation has looped playback.
|
||||
* You can also listen to `Animation.onLoop` rather than via the Game Objects events.
|
||||
* It is sent two arguments:
|
||||
* {any} The Game Object that received the event.
|
||||
* {Phaser.Animation} The Phaser.Animation that looped.
|
||||
* @property {Phaser.Signal} onAnimationLoop
|
||||
*/
|
||||
onAnimationLoop: null
|
||||
|
||||
};
|
||||
|
||||
Phaser.Events.prototype.constructor = Phaser.Events;
|
||||
|
||||
// Create an auto-create proxy getter and dispatch method for all events.
|
||||
// The backing property is the same as the event name, prefixed with '_'
|
||||
// and the dispatch method is the same as the event name postfixed with '$dispatch'.
|
||||
for (var prop in Phaser.Events.prototype)
|
||||
{
|
||||
if (!Phaser.Events.prototype.hasOwnProperty(prop) ||
|
||||
prop.indexOf('on') !== 0 ||
|
||||
Phaser.Events.prototype[prop] !== null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
(function (prop, backing) {
|
||||
'use strict';
|
||||
|
||||
// The accessor creates a new Signal; and so it should only be used from user-code.
|
||||
Object.defineProperty(Phaser.Events.prototype, prop, {
|
||||
get: function () {
|
||||
return this[backing] || (this[backing] = new Phaser.Signal());
|
||||
}
|
||||
});
|
||||
|
||||
// The dispatcher will only broadcast on an already-created signal; call this internally.
|
||||
Phaser.Events.prototype[prop + '$dispatch'] = function () {
|
||||
return this[backing] ? this[backing].dispatch.apply(this[backing], arguments) : null;
|
||||
};
|
||||
|
||||
})(prop, '_' + prop);
|
||||
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The FixedToCamera component enables a Game Object to be rendered relative to the game camera coordinates, regardless
|
||||
* of where in the world the camera is. This is used for things like sticking game UI to the camera that scrolls as it moves around the world.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.FixedToCamera = function () {};
|
||||
|
||||
/**
|
||||
* The FixedToCamera component postUpdate handler.
|
||||
* Called automatically by the Game Object.
|
||||
*
|
||||
* @method
|
||||
*/
|
||||
Phaser.Component.FixedToCamera.postUpdate = function () {
|
||||
|
||||
if (this.fixedToCamera)
|
||||
{
|
||||
this.position.x = (this.game.camera.view.x + this.cameraOffset.x) / this.game.camera.scale.x;
|
||||
this.position.y = (this.game.camera.view.y + this.cameraOffset.y) / this.game.camera.scale.y;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.Component.FixedToCamera.prototype = {
|
||||
|
||||
/**
|
||||
* @property {boolean} _fixedToCamera
|
||||
* @private
|
||||
*/
|
||||
_fixedToCamera: false,
|
||||
|
||||
/**
|
||||
* A Game Object that is "fixed" to the camera uses its x/y coordinates as offsets from the top left of the camera during rendering.
|
||||
*
|
||||
* The values are adjusted at the rendering stage, overriding the Game Objects actual world position.
|
||||
*
|
||||
* The end result is that the Game Object will appear to be 'fixed' to the camera, regardless of where in the game world
|
||||
* the camera is viewing. This is useful if for example this Game Object is a UI item that you wish to be visible at all times
|
||||
* regardless where in the world the camera is.
|
||||
*
|
||||
* The offsets are stored in the `cameraOffset` property.
|
||||
*
|
||||
* Note that the `cameraOffset` values are in addition to any parent of this Game Object on the display list.
|
||||
*
|
||||
* Be careful not to set `fixedToCamera` on Game Objects which are in Groups that already have `fixedToCamera` enabled on them.
|
||||
*
|
||||
* @property {boolean} fixedToCamera
|
||||
*/
|
||||
fixedToCamera: {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this._fixedToCamera;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value)
|
||||
{
|
||||
this._fixedToCamera = true;
|
||||
this.cameraOffset.set(this.x, this.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._fixedToCamera = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The x/y coordinate offset applied to the top-left of the camera that this Game Object will be drawn at if `fixedToCamera` is true.
|
||||
*
|
||||
* The values are relative to the top-left of the camera view and in addition to any parent of the Game Object on the display list.
|
||||
* @property {Phaser.Point} cameraOffset
|
||||
*/
|
||||
cameraOffset: new Phaser.Point()
|
||||
|
||||
};
|
|
@ -1,106 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Health component provides the ability for Game Objects to have a `health` property
|
||||
* that can be damaged and reset through game code.
|
||||
* Requires the LifeSpan component.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.Health = function () {};
|
||||
|
||||
Phaser.Component.Health.prototype = {
|
||||
|
||||
/**
|
||||
* The Game Objects health value. This is a handy property for setting and manipulating health on a Game Object.
|
||||
*
|
||||
* It can be used in combination with the `damage` method or modified directly.
|
||||
*
|
||||
* @property {number} health
|
||||
* @default
|
||||
*/
|
||||
health: 1,
|
||||
|
||||
/**
|
||||
* The Game Objects maximum health value. This works in combination with the `heal` method to ensure
|
||||
* the health value never exceeds the maximum.
|
||||
*
|
||||
* @property {number} maxHealth
|
||||
* @default
|
||||
*/
|
||||
maxHealth: 100,
|
||||
|
||||
/**
|
||||
* Damages the Game Object. This removes the given amount of health from the `health` property.
|
||||
*
|
||||
* If health is taken below or is equal to zero then the `kill` method is called.
|
||||
*
|
||||
* @member
|
||||
* @param {number} amount - The amount to subtract from the current `health` value.
|
||||
* @return {Phaser.Sprite} This instance.
|
||||
*/
|
||||
damage: function (amount) {
|
||||
|
||||
if (this.alive)
|
||||
{
|
||||
this.health -= amount;
|
||||
|
||||
if (this.health <= 0)
|
||||
{
|
||||
this.kill();
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the health property of the Game Object to the given amount.
|
||||
* Will never exceed the `maxHealth` value.
|
||||
*
|
||||
* @member
|
||||
* @param {number} amount - The amount to set the `health` value to. The total will never exceed `maxHealth`.
|
||||
* @return {Phaser.Sprite} This instance.
|
||||
*/
|
||||
setHealth: function (amount) {
|
||||
|
||||
this.health = amount;
|
||||
|
||||
if (this.health > this.maxHealth)
|
||||
{
|
||||
this.health = this.maxHealth;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Heal the Game Object. This adds the given amount of health to the `health` property.
|
||||
*
|
||||
* @member
|
||||
* @param {number} amount - The amount to add to the current `health` value. The total will never exceed `maxHealth`.
|
||||
* @return {Phaser.Sprite} This instance.
|
||||
*/
|
||||
heal: function (amount) {
|
||||
|
||||
if (this.alive)
|
||||
{
|
||||
this.health += amount;
|
||||
|
||||
if (this.health > this.maxHealth)
|
||||
{
|
||||
this.health = this.maxHealth;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,36 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The InCamera component checks if the Game Object intersects with the Game Camera.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.InCamera = function () {};
|
||||
|
||||
Phaser.Component.InCamera.prototype = {
|
||||
|
||||
/**
|
||||
* Checks if this Game Objects bounds intersects with the Game Cameras bounds.
|
||||
*
|
||||
* It will be `true` if they intersect, or `false` if the Game Object is fully outside of the Cameras bounds.
|
||||
*
|
||||
* An object outside the bounds can be considered for camera culling if it has the AutoCull component.
|
||||
*
|
||||
* @property {boolean} inCamera
|
||||
* @readonly
|
||||
*/
|
||||
inCamera: {
|
||||
|
||||
get: function() {
|
||||
|
||||
return this.game.world.camera.view.intersects(this._bounds);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,139 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The InWorld component checks if a Game Object is within the Game World Bounds.
|
||||
* An object is considered as being "in bounds" so long as its own bounds intersects at any point with the World bounds.
|
||||
* If the AutoCull component is enabled on the Game Object then it will check the Game Object against the Camera bounds as well.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.InWorld = function () {};
|
||||
|
||||
/**
|
||||
* The InWorld component preUpdate handler.
|
||||
* Called automatically by the Game Object.
|
||||
*
|
||||
* @method
|
||||
*/
|
||||
Phaser.Component.InWorld.preUpdate = function () {
|
||||
|
||||
// Cache the bounds if we need it
|
||||
if (this.autoCull || this.checkWorldBounds)
|
||||
{
|
||||
this._bounds.copyFrom(this.getBounds());
|
||||
|
||||
this._bounds.x += this.game.camera.view.x;
|
||||
this._bounds.y += this.game.camera.view.y;
|
||||
|
||||
if (this.autoCull)
|
||||
{
|
||||
// Won't get rendered but will still get its transform updated
|
||||
if (this.game.world.camera.view.intersects(this._bounds))
|
||||
{
|
||||
this.renderable = true;
|
||||
this.game.world.camera.totalInView++;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.renderable = false;
|
||||
|
||||
if (this.outOfCameraBoundsKill)
|
||||
{
|
||||
this.kill();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.checkWorldBounds)
|
||||
{
|
||||
// The Sprite is already out of the world bounds, so let's check to see if it has come back again
|
||||
if (this._outOfBoundsFired && this.game.world.bounds.intersects(this._bounds))
|
||||
{
|
||||
this._outOfBoundsFired = false;
|
||||
this.events.onEnterBounds$dispatch(this);
|
||||
}
|
||||
else if (!this._outOfBoundsFired && !this.game.world.bounds.intersects(this._bounds))
|
||||
{
|
||||
// The Sprite WAS in the screen, but has now left.
|
||||
this._outOfBoundsFired = true;
|
||||
this.events.onOutOfBounds$dispatch(this);
|
||||
|
||||
if (this.outOfBoundsKill)
|
||||
{
|
||||
this.kill();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Component.InWorld.prototype = {
|
||||
|
||||
/**
|
||||
* If this is set to `true` the Game Object checks if it is within the World bounds each frame.
|
||||
*
|
||||
* When it is no longer intersecting the world bounds it dispatches the `onOutOfBounds` event.
|
||||
*
|
||||
* If it was *previously* out of bounds but is now intersecting the world bounds again it dispatches the `onEnterBounds` event.
|
||||
*
|
||||
* It also optionally kills the Game Object if `outOfBoundsKill` is `true`.
|
||||
*
|
||||
* When `checkWorldBounds` is enabled it forces the Game Object to calculate its full bounds every frame.
|
||||
*
|
||||
* This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required,
|
||||
* or you have tested performance and find it acceptable.
|
||||
*
|
||||
* @property {boolean} checkWorldBounds
|
||||
* @default
|
||||
*/
|
||||
checkWorldBounds: false,
|
||||
|
||||
/**
|
||||
* If this and the `checkWorldBounds` property are both set to `true` then the `kill` method is called as soon as `inWorld` returns false.
|
||||
*
|
||||
* @property {boolean} outOfBoundsKill
|
||||
* @default
|
||||
*/
|
||||
outOfBoundsKill: false,
|
||||
|
||||
/**
|
||||
* If this and the `autoCull` property are both set to `true`, then the `kill` method
|
||||
* is called as soon as the Game Object leaves the camera bounds.
|
||||
*
|
||||
* @property {boolean} outOfCameraBoundsKill
|
||||
* @default
|
||||
*/
|
||||
outOfCameraBoundsKill: false,
|
||||
|
||||
/**
|
||||
* @property {boolean} _outOfBoundsFired - Internal state var.
|
||||
* @private
|
||||
*/
|
||||
_outOfBoundsFired: false,
|
||||
|
||||
/**
|
||||
* Checks if the Game Objects bounds are within, or intersect at any point with the Game World bounds.
|
||||
*
|
||||
* @property {boolean} inWorld
|
||||
* @readonly
|
||||
*/
|
||||
inWorld: {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.game.world.bounds.intersects(this.getBounds());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,76 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The InputEnabled component allows a Game Object to have its own InputHandler and process input related events.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.InputEnabled = function () {};
|
||||
|
||||
Phaser.Component.InputEnabled.prototype = {
|
||||
|
||||
/**
|
||||
* The Input Handler for this Game Object.
|
||||
*
|
||||
* By default it is disabled. If you wish this Game Object to process input events you should enable it with: `inputEnabled = true`.
|
||||
*
|
||||
* After you have done this, this property will be a reference to the Phaser InputHandler.
|
||||
* @property {Phaser.InputHandler|null} input
|
||||
*/
|
||||
input: null,
|
||||
|
||||
/**
|
||||
* By default a Game Object won't process any input events. By setting `inputEnabled` to true a Phaser.InputHandler is created
|
||||
* for this Game Object and it will then start to process click / touch events and more.
|
||||
*
|
||||
* You can then access the Input Handler via `this.input`.
|
||||
*
|
||||
* Note that Input related events are dispatched from `this.events`, i.e.: `events.onInputDown`.
|
||||
*
|
||||
* If you set this property to false it will stop the Input Handler from processing any more input events.
|
||||
*
|
||||
* If you want to _temporarily_ disable input for a Game Object, then it's better to set
|
||||
* `input.enabled = false`, as it won't reset any of the Input Handlers internal properties.
|
||||
* You can then toggle this back on as needed.
|
||||
*
|
||||
* @property {boolean} inputEnabled
|
||||
*/
|
||||
inputEnabled: {
|
||||
|
||||
get: function () {
|
||||
|
||||
return (this.input && this.input.enabled);
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value)
|
||||
{
|
||||
if (this.input === null)
|
||||
{
|
||||
this.input = new Phaser.InputHandler(this);
|
||||
this.input.start();
|
||||
}
|
||||
else if (this.input && !this.input.enabled)
|
||||
{
|
||||
this.input.start();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.input && this.input.enabled)
|
||||
{
|
||||
this.input.stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,128 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* LifeSpan Component Features.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.LifeSpan = function () {};
|
||||
|
||||
/**
|
||||
* The LifeSpan component preUpdate handler.
|
||||
* Called automatically by the Game Object.
|
||||
*
|
||||
* @method
|
||||
*/
|
||||
Phaser.Component.LifeSpan.preUpdate = function () {
|
||||
|
||||
if (this.lifespan > 0)
|
||||
{
|
||||
this.lifespan -= this.game.time.physicsElapsedMS;
|
||||
|
||||
if (this.lifespan <= 0)
|
||||
{
|
||||
this.kill();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Component.LifeSpan.prototype = {
|
||||
|
||||
/**
|
||||
* A useful flag to control if the Game Object is alive or dead.
|
||||
*
|
||||
* This is set automatically by the Health components `damage` method should the object run out of health.
|
||||
* Or you can toggle it via your game code.
|
||||
*
|
||||
* This property is mostly just provided to be used by your game - it doesn't effect rendering or logic updates.
|
||||
* However you can use `Group.getFirstAlive` in conjunction with this property for fast object pooling and recycling.
|
||||
* @property {boolean} alive
|
||||
* @default
|
||||
*/
|
||||
alive: true,
|
||||
|
||||
/**
|
||||
* The lifespan allows you to give a Game Object a lifespan in milliseconds.
|
||||
*
|
||||
* Once the Game Object is 'born' you can set this to a positive value.
|
||||
*
|
||||
* It is automatically decremented by the millisecond equivalent of `game.time.physicsElapsed` each frame.
|
||||
* When it reaches zero it will call the `kill` method.
|
||||
*
|
||||
* Very handy for particles, bullets, collectibles, or any other short-lived entity.
|
||||
*
|
||||
* @property {number} lifespan
|
||||
* @default
|
||||
*/
|
||||
lifespan: 0,
|
||||
|
||||
/**
|
||||
* Brings a 'dead' Game Object back to life, optionally resetting its health value in the process.
|
||||
*
|
||||
* A resurrected Game Object has its `alive`, `exists` and `visible` properties all set to true.
|
||||
*
|
||||
* It will dispatch the `onRevived` event. Listen to `events.onRevived` for the signal.
|
||||
*
|
||||
* @method
|
||||
* @param {number} [health=100] - The health to give the Game Object. Only set if the GameObject has the Health component.
|
||||
* @return {PIXI.DisplayObject} This instance.
|
||||
*/
|
||||
revive: function (health) {
|
||||
|
||||
if (health === undefined) { health = 100; }
|
||||
|
||||
this.alive = true;
|
||||
this.exists = true;
|
||||
this.visible = true;
|
||||
|
||||
if (typeof this.setHealth === 'function')
|
||||
{
|
||||
this.setHealth(health);
|
||||
}
|
||||
|
||||
if (this.events)
|
||||
{
|
||||
this.events.onRevived$dispatch(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Kills a Game Object. A killed Game Object has its `alive`, `exists` and `visible` properties all set to false.
|
||||
*
|
||||
* It will dispatch the `onKilled` event. You can listen to `events.onKilled` for the signal.
|
||||
*
|
||||
* Note that killing a Game Object is a way for you to quickly recycle it in an object pool,
|
||||
* it doesn't destroy the object or free it up from memory.
|
||||
*
|
||||
* If you don't need this Game Object any more you should call `destroy` instead.
|
||||
*
|
||||
* @method
|
||||
* @return {PIXI.DisplayObject} This instance.
|
||||
*/
|
||||
kill: function () {
|
||||
|
||||
this.alive = false;
|
||||
this.exists = false;
|
||||
this.visible = false;
|
||||
|
||||
if (this.events)
|
||||
{
|
||||
this.events.onKilled$dispatch(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,296 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The LoadTexture component manages the loading of a texture into the Game Object and the changing of frames.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.LoadTexture = function () {};
|
||||
|
||||
Phaser.Component.LoadTexture.prototype = {
|
||||
|
||||
/**
|
||||
* @property {boolean} customRender - Does this texture require a custom render call? (as set by BitmapData, Video, etc)
|
||||
* @private
|
||||
*/
|
||||
customRender: false,
|
||||
|
||||
/**
|
||||
* @property {Phaser.Rectangle} _frame - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
_frame: null,
|
||||
|
||||
/**
|
||||
* Changes the base texture the Game Object is using. The old texture is removed and the new one is referenced or fetched from the Cache.
|
||||
*
|
||||
* If your Game Object is using a frame from a texture atlas and you just wish to change to another frame, then see the `frame` or `frameName` properties instead.
|
||||
*
|
||||
* You should only use `loadTexture` if you want to replace the base texture entirely.
|
||||
*
|
||||
* Calling this method causes a WebGL texture update, so use sparingly or in low-intensity portions of your game, or if you know the new texture is already on the GPU.
|
||||
*
|
||||
* You can use the new const `Phaser.PENDING_ATLAS` as the texture key for any sprite.
|
||||
* Doing this then sets the key to be the `frame` argument (the frame is set to zero).
|
||||
*
|
||||
* This allows you to create sprites using `load.image` during development, and then change them
|
||||
* to use a Texture Atlas later in development by simply searching your code for 'PENDING_ATLAS'
|
||||
* and swapping it to be the key of the atlas data.
|
||||
*
|
||||
* Note: You cannot use a RenderTexture as a texture for a TileSprite.
|
||||
*
|
||||
* @method
|
||||
* @param {string|Phaser.RenderTexture|Phaser.BitmapData|Phaser.Video|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
|
||||
* @param {string|number} [frame] - If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
|
||||
* @param {boolean} [stopAnimation=true] - If an animation is already playing on this Sprite you can choose to stop it or let it carry on playing.
|
||||
*/
|
||||
loadTexture: function (key, frame, stopAnimation) {
|
||||
|
||||
if (key === Phaser.PENDING_ATLAS)
|
||||
{
|
||||
key = frame;
|
||||
frame = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
frame = frame || 0;
|
||||
}
|
||||
|
||||
if ((stopAnimation || stopAnimation === undefined) && this.animations)
|
||||
{
|
||||
this.animations.stop();
|
||||
}
|
||||
|
||||
this.key = key;
|
||||
this.customRender = false;
|
||||
var cache = this.game.cache;
|
||||
|
||||
var setFrame = true;
|
||||
var smoothed = !this.texture.baseTexture.scaleMode;
|
||||
|
||||
if (Phaser.RenderTexture && key instanceof Phaser.RenderTexture)
|
||||
{
|
||||
this.key = key.key;
|
||||
this.setTexture(key);
|
||||
}
|
||||
else if (Phaser.BitmapData && key instanceof Phaser.BitmapData)
|
||||
{
|
||||
this.customRender = true;
|
||||
|
||||
this.setTexture(key.texture);
|
||||
|
||||
if (cache.hasFrameData(key.key, Phaser.Cache.BITMAPDATA))
|
||||
{
|
||||
setFrame = !this.animations.loadFrameData(cache.getFrameData(key.key, Phaser.Cache.BITMAPDATA), frame);
|
||||
}
|
||||
else
|
||||
{
|
||||
setFrame = !this.animations.loadFrameData(key.frameData, 0);
|
||||
}
|
||||
}
|
||||
else if (Phaser.Video && key instanceof Phaser.Video)
|
||||
{
|
||||
this.customRender = true;
|
||||
|
||||
// This works from a reference, which probably isn't what we need here
|
||||
var valid = key.texture.valid;
|
||||
this.setTexture(key.texture);
|
||||
this.setFrame(key.texture.frame.clone());
|
||||
key.onChangeSource.add(this.resizeFrame, this);
|
||||
this.texture.valid = valid;
|
||||
}
|
||||
else if (Phaser.Tilemap && key instanceof Phaser.TilemapLayer)
|
||||
{
|
||||
// this.customRender = true;
|
||||
|
||||
this.setTexture(PIXI.Texture.fromCanvas(key.canvas));
|
||||
}
|
||||
else if (key instanceof PIXI.Texture)
|
||||
{
|
||||
this.setTexture(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
var img = cache.getImage(key, true);
|
||||
|
||||
this.key = img.key;
|
||||
this.setTexture(new PIXI.Texture(img.base));
|
||||
|
||||
if (key === '__default')
|
||||
{
|
||||
this.texture.baseTexture.skipRender = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.texture.baseTexture.skipRender = false;
|
||||
}
|
||||
|
||||
setFrame = !this.animations.loadFrameData(img.frameData, frame);
|
||||
}
|
||||
|
||||
if (setFrame)
|
||||
{
|
||||
this._frame = Phaser.Rectangle.clone(this.texture.frame);
|
||||
}
|
||||
|
||||
if (!smoothed)
|
||||
{
|
||||
this.texture.baseTexture.scaleMode = 1;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the texture frame the Game Object uses for rendering.
|
||||
*
|
||||
* This is primarily an internal method used by `loadTexture`, but is exposed for the use of plugins and custom classes.
|
||||
*
|
||||
* @method
|
||||
* @param {Phaser.Frame} frame - The Frame to be used by the texture.
|
||||
*/
|
||||
setFrame: function (frame) {
|
||||
|
||||
this._frame = frame;
|
||||
|
||||
this.texture.frame.x = frame.x;
|
||||
this.texture.frame.y = frame.y;
|
||||
this.texture.frame.width = frame.width;
|
||||
this.texture.frame.height = frame.height;
|
||||
|
||||
this.texture.crop.x = frame.x;
|
||||
this.texture.crop.y = frame.y;
|
||||
this.texture.crop.width = frame.width;
|
||||
this.texture.crop.height = frame.height;
|
||||
|
||||
if (frame.trimmed)
|
||||
{
|
||||
if (this.texture.trim)
|
||||
{
|
||||
this.texture.trim.x = frame.spriteSourceSizeX;
|
||||
this.texture.trim.y = frame.spriteSourceSizeY;
|
||||
this.texture.trim.width = frame.sourceSizeW;
|
||||
this.texture.trim.height = frame.sourceSizeH;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.texture.trim = { x: frame.spriteSourceSizeX, y: frame.spriteSourceSizeY, width: frame.sourceSizeW, height: frame.sourceSizeH };
|
||||
}
|
||||
|
||||
this.texture.width = frame.sourceSizeW;
|
||||
this.texture.height = frame.sourceSizeH;
|
||||
this.texture.frame.width = frame.sourceSizeW;
|
||||
this.texture.frame.height = frame.sourceSizeH;
|
||||
}
|
||||
else if (!frame.trimmed && this.texture.trim)
|
||||
{
|
||||
this.texture.trim = null;
|
||||
}
|
||||
|
||||
if (frame.rotated)
|
||||
{
|
||||
this.texture.rotated = true;
|
||||
}
|
||||
|
||||
if (this.cropRect)
|
||||
{
|
||||
this.updateCrop();
|
||||
}
|
||||
|
||||
this.texture.requiresReTint = true;
|
||||
|
||||
this.texture._updateUvs();
|
||||
|
||||
if (this.tilingTexture)
|
||||
{
|
||||
this.refreshTexture = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Resizes the Frame dimensions that the Game Object uses for rendering.
|
||||
*
|
||||
* You shouldn't normally need to ever call this, but in the case of special texture types such as Video or BitmapData
|
||||
* it can be useful to adjust the dimensions directly in this way.
|
||||
*
|
||||
* @method
|
||||
* @param {object} parent - The parent texture object that caused the resize, i.e. a Phaser.Video object.
|
||||
* @param {integer} width - The new width of the texture.
|
||||
* @param {integer} height - The new height of the texture.
|
||||
*/
|
||||
resizeFrame: function (parent, width, height) {
|
||||
|
||||
this.texture.frame.resize(width, height);
|
||||
this.texture.setFrame(this.texture.frame);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Resets the texture frame dimensions that the Game Object uses for rendering.
|
||||
*
|
||||
* @method
|
||||
*/
|
||||
resetFrame: function () {
|
||||
|
||||
if (this._frame)
|
||||
{
|
||||
this.setFrame(this._frame);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets or sets the current frame index of the texture being used to render this Game Object.
|
||||
*
|
||||
* To change the frame set `frame` to the index of the new frame in the sprite sheet you wish this Game Object to use,
|
||||
* for example: `player.frame = 4`.
|
||||
*
|
||||
* If the frame index given doesn't exist it will revert to the first frame found in the texture.
|
||||
*
|
||||
* If you are using a texture atlas then you should use the `frameName` property instead.
|
||||
*
|
||||
* If you wish to fully replace the texture being used see `loadTexture`.
|
||||
* @property {integer} frame
|
||||
*/
|
||||
frame: {
|
||||
|
||||
get: function () {
|
||||
return this.animations.frame;
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
this.animations.frame = value;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets or sets the current frame name of the texture being used to render this Game Object.
|
||||
*
|
||||
* To change the frame set `frameName` to the name of the new frame in the texture atlas you wish this Game Object to use,
|
||||
* for example: `player.frameName = "idle"`.
|
||||
*
|
||||
* If the frame name given doesn't exist it will revert to the first frame found in the texture and throw a console warning.
|
||||
*
|
||||
* If you are using a sprite sheet then you should use the `frame` property instead.
|
||||
*
|
||||
* If you wish to fully replace the texture being used see `loadTexture`.
|
||||
* @property {string} frameName
|
||||
*/
|
||||
frameName: {
|
||||
|
||||
get: function () {
|
||||
return this.animations.frameName;
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
this.animations.frameName = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,35 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Overlap component allows a Game Object to check if it overlaps with the bounds of another Game Object.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.Overlap = function () {};
|
||||
|
||||
Phaser.Component.Overlap.prototype = {
|
||||
|
||||
/**
|
||||
* Checks to see if the bounds of this Game Object overlaps with the bounds of the given Display Object,
|
||||
* which can be a Sprite, Image, TileSprite or anything that extends those such as Button or provides a `getBounds` method and result.
|
||||
*
|
||||
* This check ignores the `hitArea` property if set and runs a `getBounds` comparison on both objects to determine the result.
|
||||
*
|
||||
* Therefore it's relatively expensive to use in large quantities, i.e. with lots of Sprites at a high frequency.
|
||||
* It should be fine for low-volume testing where physics isn't required.
|
||||
*
|
||||
* @method
|
||||
* @param {Phaser.Sprite|Phaser.Image|Phaser.TileSprite|Phaser.Button|PIXI.DisplayObject} displayObject - The display object to check against.
|
||||
* @return {boolean} True if the bounds of this Game Object intersects at any point with the bounds of the given display object.
|
||||
*/
|
||||
overlap: function (displayObject) {
|
||||
|
||||
return Phaser.Rectangle.intersects(this.getBounds(), displayObject.getBounds());
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,145 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The PhysicsBody component manages the Game Objects physics body and physics enabling.
|
||||
* It also overrides the x and y properties, ensuring that any manual adjustment of them is reflected in the physics body itself.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.PhysicsBody = function () {};
|
||||
|
||||
/**
|
||||
* The PhysicsBody component preUpdate handler.
|
||||
* Called automatically by the Game Object.
|
||||
*
|
||||
* @method
|
||||
*/
|
||||
Phaser.Component.PhysicsBody.preUpdate = function () {
|
||||
|
||||
if (this.fresh && this.exists)
|
||||
{
|
||||
this.world.setTo(this.parent.position.x + this.position.x, this.parent.position.y + this.position.y);
|
||||
this.worldTransform.tx = this.world.x;
|
||||
this.worldTransform.ty = this.world.y;
|
||||
|
||||
this.previousPosition.set(this.world.x, this.world.y);
|
||||
this.previousRotation = this.rotation;
|
||||
|
||||
if (this.body)
|
||||
{
|
||||
this.body.preUpdate();
|
||||
}
|
||||
|
||||
this.fresh = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
this.previousPosition.set(this.world.x, this.world.y);
|
||||
this.previousRotation = this.rotation;
|
||||
|
||||
if (!this._exists || !this.parent.exists)
|
||||
{
|
||||
this.renderOrderID = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The PhysicsBody component postUpdate handler.
|
||||
* Called automatically by the Game Object.
|
||||
*
|
||||
* @method
|
||||
*/
|
||||
Phaser.Component.PhysicsBody.postUpdate = function () {
|
||||
|
||||
if (this.exists && this.body)
|
||||
{
|
||||
this.body.postUpdate();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.Component.PhysicsBody.prototype = {
|
||||
|
||||
/**
|
||||
* `body` is the Game Objects physics body. Once a Game Object is enabled for physics you access all associated
|
||||
* properties and methods via it.
|
||||
*
|
||||
* By default Game Objects won't add themselves to any physics system and their `body` property will be `null`.
|
||||
*
|
||||
* To enable this Game Object for physics you need to call `game.physics.enable(object, system)` where `object` is this object
|
||||
* and `system` is the Physics system you are using. If none is given it defaults to `Phaser.Physics.Arcade`.
|
||||
*
|
||||
* You can alternatively call `game.physics.arcade.enable(object)`, or add this Game Object to a physics enabled Group.
|
||||
*
|
||||
* Important: Enabling a Game Object for P2 or Ninja physics will automatically set its `anchor` property to 0.5,
|
||||
* so the physics body is centered on the Game Object.
|
||||
*
|
||||
* If you need a different result then adjust or re-create the Body shape offsets manually or reset the anchor after enabling physics.
|
||||
*
|
||||
* @property {Phaser.Physics.Arcade.Body|Phaser.Physics.P2.Body|Phaser.Physics.Ninja.Body|null} body
|
||||
* @default
|
||||
*/
|
||||
body: null,
|
||||
|
||||
/**
|
||||
* The position of the Game Object on the x axis relative to the local coordinates of the parent.
|
||||
*
|
||||
* @property {number} x
|
||||
*/
|
||||
x: {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.position.x;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.position.x = value;
|
||||
|
||||
if (this.body && !this.body.dirty)
|
||||
{
|
||||
this.body._reset = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The position of the Game Object on the y axis relative to the local coordinates of the parent.
|
||||
*
|
||||
* @property {number} y
|
||||
*/
|
||||
y: {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.position.y;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.position.y = value;
|
||||
|
||||
if (this.body && !this.body.dirty)
|
||||
{
|
||||
this.body._reset = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,63 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Reset component allows a Game Object to be reset and repositioned to a new location.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.Reset = function () {};
|
||||
|
||||
/**
|
||||
* Resets the Game Object.
|
||||
*
|
||||
* This moves the Game Object to the given x/y world coordinates and sets `fresh`, `exists`,
|
||||
* `visible` and `renderable` to true.
|
||||
*
|
||||
* If this Game Object has the LifeSpan component it will also set `alive` to true and `health` to the given value.
|
||||
*
|
||||
* If this Game Object has a Physics Body it will reset the Body.
|
||||
*
|
||||
* @method
|
||||
* @param {number} x - The x coordinate (in world space) to position the Game Object at.
|
||||
* @param {number} y - The y coordinate (in world space) to position the Game Object at.
|
||||
* @param {number} [health=1] - The health to give the Game Object if it has the Health component.
|
||||
* @return {PIXI.DisplayObject} This instance.
|
||||
*/
|
||||
Phaser.Component.Reset.prototype.reset = function (x, y, health) {
|
||||
|
||||
if (health === undefined) { health = 1; }
|
||||
|
||||
this.world.set(x, y);
|
||||
this.position.set(x, y);
|
||||
|
||||
this.fresh = true;
|
||||
this.exists = true;
|
||||
this.visible = true;
|
||||
this.renderable = true;
|
||||
|
||||
if (this.components.InWorld)
|
||||
{
|
||||
this._outOfBoundsFired = false;
|
||||
}
|
||||
|
||||
if (this.components.LifeSpan)
|
||||
{
|
||||
this.alive = true;
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
if (this.components.PhysicsBody)
|
||||
{
|
||||
if (this.body)
|
||||
{
|
||||
this.body.reset(x, y, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
};
|
|
@ -1,168 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The ScaleMinMax component allows a Game Object to limit how far it can be scaled by its parent.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.ScaleMinMax = function () {};
|
||||
|
||||
Phaser.Component.ScaleMinMax.prototype = {
|
||||
|
||||
/**
|
||||
* The callback that will apply any scale limiting to the worldTransform.
|
||||
* @property {function} transformCallback
|
||||
*/
|
||||
transformCallback: null,
|
||||
|
||||
/**
|
||||
* The context under which `transformCallback` is called.
|
||||
* @property {object} transformCallbackContext
|
||||
*/
|
||||
transformCallbackContext: this,
|
||||
|
||||
/**
|
||||
* The minimum scale this Game Object will scale down to.
|
||||
*
|
||||
* It allows you to prevent a parent from scaling this Game Object lower than the given value.
|
||||
*
|
||||
* Set it to `null` to remove the limit.
|
||||
* @property {Phaser.Point} scaleMin
|
||||
*/
|
||||
scaleMin: null,
|
||||
|
||||
/**
|
||||
* The maximum scale this Game Object will scale up to.
|
||||
*
|
||||
* It allows you to prevent a parent from scaling this Game Object higher than the given value.
|
||||
*
|
||||
* Set it to `null` to remove the limit.
|
||||
* @property {Phaser.Point} scaleMax
|
||||
*/
|
||||
scaleMax: null,
|
||||
|
||||
/**
|
||||
* Adjust scaling limits, if set, to this Game Object.
|
||||
*
|
||||
* @method
|
||||
* @private
|
||||
* @param {Phaser.Matrix} wt - The updated worldTransform matrix.
|
||||
*/
|
||||
checkTransform: function (wt) {
|
||||
|
||||
if (this.scaleMin)
|
||||
{
|
||||
if (wt.a < this.scaleMin.x)
|
||||
{
|
||||
wt.a = this.scaleMin.x;
|
||||
}
|
||||
|
||||
if (wt.d < this.scaleMin.y)
|
||||
{
|
||||
wt.d = this.scaleMin.y;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.scaleMax)
|
||||
{
|
||||
if (wt.a > this.scaleMax.x)
|
||||
{
|
||||
wt.a = this.scaleMax.x;
|
||||
}
|
||||
|
||||
if (wt.d > this.scaleMax.y)
|
||||
{
|
||||
wt.d = this.scaleMax.y;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the scaleMin and scaleMax values. These values are used to limit how far this Game Object will scale based on its parent.
|
||||
*
|
||||
* For example if this Game Object has a `minScale` value of 1 and its parent has a `scale` value of 0.5, the 0.5 will be ignored
|
||||
* and the scale value of 1 will be used, as the parents scale is lower than the minimum scale this Game Object should adhere to.
|
||||
*
|
||||
* By setting these values you can carefully control how Game Objects deal with responsive scaling.
|
||||
*
|
||||
* If only one parameter is given then that value will be used for both scaleMin and scaleMax:
|
||||
* `setScaleMinMax(1)` = scaleMin.x, scaleMin.y, scaleMax.x and scaleMax.y all = 1
|
||||
*
|
||||
* If only two parameters are given the first is set as scaleMin.x and y and the second as scaleMax.x and y:
|
||||
* `setScaleMinMax(0.5, 2)` = scaleMin.x and y = 0.5 and scaleMax.x and y = 2
|
||||
*
|
||||
* If you wish to set `scaleMin` with different values for x and y then either modify Game Object.scaleMin directly,
|
||||
* or pass `null` for the `maxX` and `maxY` parameters.
|
||||
*
|
||||
* Call `setScaleMinMax(null)` to clear all previously set values.
|
||||
*
|
||||
* @method
|
||||
* @param {number|null} minX - The minimum horizontal scale value this Game Object can scale down to.
|
||||
* @param {number|null} minY - The minimum vertical scale value this Game Object can scale down to.
|
||||
* @param {number|null} maxX - The maximum horizontal scale value this Game Object can scale up to.
|
||||
* @param {number|null} maxY - The maximum vertical scale value this Game Object can scale up to.
|
||||
*/
|
||||
setScaleMinMax: function (minX, minY, maxX, maxY) {
|
||||
|
||||
if (minY === undefined)
|
||||
{
|
||||
// 1 parameter, set all to it
|
||||
minY = maxX = maxY = minX;
|
||||
}
|
||||
else if (maxX === undefined)
|
||||
{
|
||||
// 2 parameters, the first is min, the second max
|
||||
maxX = maxY = minY;
|
||||
minY = minX;
|
||||
}
|
||||
|
||||
if (minX === null)
|
||||
{
|
||||
this.scaleMin = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.scaleMin)
|
||||
{
|
||||
this.scaleMin.set(minX, minY);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scaleMin = new Phaser.Point(minX, minY);
|
||||
}
|
||||
}
|
||||
|
||||
if (maxX === null)
|
||||
{
|
||||
this.scaleMax = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.scaleMax)
|
||||
{
|
||||
this.scaleMax.set(maxX, maxY);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scaleMax = new Phaser.Point(maxX, maxY);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.scaleMin === null)
|
||||
{
|
||||
this.transformCallback = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.transformCallback = this.checkTransform;
|
||||
this.transformCallbackContext = this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,53 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Smoothed component allows a Game Object to control anti-aliasing of an image based texture.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
Phaser.Component.Smoothed = function () {};
|
||||
|
||||
Phaser.Component.Smoothed.prototype = {
|
||||
|
||||
/**
|
||||
* Enable or disable texture smoothing for this Game Object.
|
||||
*
|
||||
* It only takes effect if the Game Object is using an image based texture.
|
||||
*
|
||||
* Smoothing is enabled by default.
|
||||
*
|
||||
* @property {boolean} smoothed
|
||||
*/
|
||||
smoothed: {
|
||||
|
||||
get: function () {
|
||||
|
||||
return !this.texture.baseTexture.scaleMode;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value)
|
||||
{
|
||||
if (this.texture)
|
||||
{
|
||||
this.texture.baseTexture.scaleMode = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.texture)
|
||||
{
|
||||
this.texture.baseTexture.scaleMode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
Phaser.GameObject.Container = function (state, parent, x, y, name)
|
||||
{
|
||||
Phaser.GameObject.call(this, state, x, y, null, null, parent);
|
||||
|
||||
/**
|
||||
* @property {number} type - The const type of this object.
|
||||
* @readonly
|
||||
*/
|
||||
this.type = Phaser.CONTAINER;
|
||||
|
||||
this.name = name;
|
||||
|
||||
this.children = new Phaser.Component.Children(this);
|
||||
};
|
||||
|
||||
Phaser.GameObject.Container.prototype = Object.create(Phaser.GameObject.prototype);
|
||||
Phaser.GameObject.Container.prototype.constructor = Phaser.GameObject.Container;
|
||||
|
||||
Phaser.GameObject.Container.prototype.preUpdate = function ()
|
||||
{
|
||||
if (this.parent)
|
||||
{
|
||||
this.color.worldAlpha = this.parent.color.worldAlpha;
|
||||
}
|
||||
|
||||
this.children.preUpdate();
|
||||
};
|
|
@ -1,81 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @author Mat Groves (@Doormat23)
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
|
||||
Phaser.Renderer.Canvas.GameObjects.Container = {
|
||||
|
||||
TYPES: [
|
||||
Phaser.GameObject.Container.prototype
|
||||
],
|
||||
|
||||
render: function (renderer, src)
|
||||
{
|
||||
// Skip rendering?
|
||||
|
||||
if (src.visible === false || src.alpha === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Blend Mode
|
||||
|
||||
if (src.blendMode !== renderer.currentBlendMode)
|
||||
{
|
||||
renderer.currentBlendMode = src.blendMode;
|
||||
renderer.context.globalCompositeOperation = renderer.blendModes[renderer.currentBlendMode];
|
||||
}
|
||||
|
||||
// Alpha (World Alpha?)
|
||||
|
||||
if (src.alpha !== renderer.context.globalAlpha)
|
||||
{
|
||||
renderer.context.globalAlpha = src.alpha;
|
||||
}
|
||||
|
||||
// Smoothing (should this be a Game Object, or Frame / Texture level property?)
|
||||
|
||||
if (src.scaleMode !== renderer.currentScaleMode)
|
||||
{
|
||||
renderer.currentScaleMode = src.scaleMode;
|
||||
renderer.context[renderer.smoothProperty] = (src.scaleMode === Phaser.scaleModes.LINEAR);
|
||||
}
|
||||
|
||||
/*
|
||||
if (src._cacheAsBitmap)
|
||||
{
|
||||
return this.renderCachedSprite(renderer, src);
|
||||
}
|
||||
|
||||
if (src._mask)
|
||||
{
|
||||
renderer.pushMask(src._mask);
|
||||
}
|
||||
*/
|
||||
|
||||
for (var i = 0; i < src.children.list.length; i++)
|
||||
{
|
||||
var child = src.children.list[i];
|
||||
|
||||
child.render(renderer, child);
|
||||
}
|
||||
|
||||
/*
|
||||
if (src._mask)
|
||||
{
|
||||
renderer.popMask();
|
||||
}
|
||||
*/
|
||||
|
||||
},
|
||||
|
||||
renderCachedSprite: function (renderer, src)
|
||||
{
|
||||
// TODO
|
||||
return src;
|
||||
}
|
||||
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.GameObject.Container.FACTORY_KEY = 'container';
|
||||
|
||||
Phaser.GameObject.Container.FACTORY_ADD = function (parent, x, y, name)
|
||||
{
|
||||
return parent.children.add(new Phaser.GameObject.Container(this.state, null, x, y, name));
|
||||
};
|
||||
|
||||
Phaser.GameObject.Container.FACTORY_MAKE = function (parent, x, y)
|
||||
{
|
||||
return new Phaser.GameObject.Container(this.state, parent, x, y);
|
||||
};
|
|
@ -1,38 +0,0 @@
|
|||
Phaser.Renderer.WebGL.GameObjects.Container = {
|
||||
|
||||
TYPES: [
|
||||
Phaser.GameObject.Container.prototype
|
||||
],
|
||||
|
||||
render: function (renderer, src)
|
||||
{
|
||||
var alpha = src.color.worldAlpha * 255 << 24;
|
||||
|
||||
// Skip rendering?
|
||||
if (src.skipRender || !src.visible || alpha === 0 || src.children.list.length === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// if (src._cacheAsBitmap)
|
||||
// {
|
||||
// return Phaser.Renderer.WebGL.GameObjects.Container.renderCachedSprite(renderer, src);
|
||||
// }
|
||||
|
||||
// Render children
|
||||
for (var i = 0; i < src.children.list.length; i++)
|
||||
{
|
||||
var child = src.children.list[i];
|
||||
|
||||
child.render(renderer, child);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
renderCachedSprite: function (renderer, src)
|
||||
{
|
||||
// TODO
|
||||
return renderer;
|
||||
}
|
||||
|
||||
};
|
|
@ -1,481 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @author Kestrel Moon Studios <creature@kestrelmoon.com>
|
||||
* @copyright 2016 Photon Storm Ltd and Kestrel Moon Studios
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creature is a custom Game Object used in conjunction with the Creature Runtime libraries by Kestrel Moon Studios.
|
||||
*
|
||||
* It allows you to display animated Game Objects that were created with the [Creature Automated Animation Tool](http://www.kestrelmoon.com/creature/).
|
||||
*
|
||||
* Note 1: You can only use Phaser.GameObject.Creature objects in WebGL enabled games. They do not work in Canvas mode games.
|
||||
*
|
||||
* Note 2: You must use a build of Phaser that includes the CreatureMeshBone.js runtime and gl-matrix.js, or have them
|
||||
* loaded before your Phaser game boots.
|
||||
*
|
||||
* See the Phaser custom build process for more details.
|
||||
*
|
||||
* By default the Creature runtimes are NOT included in any pre-configured version of Phaser.
|
||||
*
|
||||
* So you'll need to do `grunt custom` to create a build that includes them.
|
||||
*
|
||||
* @class Phaser.GameObject.Creature
|
||||
* @extends PIXI.DisplayObjectContainer
|
||||
* @extends Phaser.Component.Core
|
||||
* @extends Phaser.Component.Angle
|
||||
* @extends Phaser.Component.AutoCull
|
||||
* @extends Phaser.Component.BringToTop
|
||||
* @extends Phaser.Component.Destroy
|
||||
* @extends Phaser.Component.FixedToCamera
|
||||
* @extends Phaser.Component.LifeSpan
|
||||
* @extends Phaser.Component.Reset
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {number} x - The x coordinate of the Game Object. The coordinate is relative to any parent container this Game Object may be in.
|
||||
* @param {number} y - The y coordinate of the Game Object. The coordinate is relative to any parent container this Game Object may be in.
|
||||
* @param {string|PIXI.Texture} key - The texture used by the Creature Object during rendering. It can be a string which is a reference to the Cache entry, or an instance of a PIXI.Texture.
|
||||
* @param {string} mesh - The mesh data for the Creature Object. It should be a string which is a reference to the Cache JSON entry.
|
||||
* @param {string} [animation='default'] - The animation within the mesh data to play.
|
||||
*/
|
||||
Phaser.GameObject.Creature = function (game, x, y, key, mesh, animation) {
|
||||
|
||||
if (animation === undefined) { animation = 'default'; }
|
||||
|
||||
/**
|
||||
* @property {number} type - The const type of this object.
|
||||
* @readonly
|
||||
*/
|
||||
this.type = Phaser.CREATURE;
|
||||
|
||||
if (!game.cache.checkJSONKey(mesh))
|
||||
{
|
||||
console.warn('Phaser.GameObject.Creature: Invalid mesh key given. Not found in Phaser.Cache');
|
||||
return;
|
||||
}
|
||||
|
||||
var meshData = game.cache.getJSON(mesh);
|
||||
|
||||
/**
|
||||
* @property {Creature} _creature - The Creature instance.
|
||||
* @private
|
||||
*/
|
||||
this._creature = new Creature(meshData);
|
||||
|
||||
/**
|
||||
* @property {CreatureAnimation} animation - The CreatureAnimation instance.
|
||||
*/
|
||||
this.animation = new CreatureAnimation(meshData, animation, this._creature);
|
||||
|
||||
/**
|
||||
* @property {CreatureManager} manager - The CreatureManager instance for this object.
|
||||
*/
|
||||
this.manager = new CreatureManager(this._creature);
|
||||
|
||||
/**
|
||||
* @property {number} timeDelta - How quickly the animation advances.
|
||||
* @default
|
||||
*/
|
||||
this.timeDelta = 0.05;
|
||||
|
||||
if (typeof key === 'string')
|
||||
{
|
||||
var texture = new PIXI.Texture(game.cache.getBaseTexture(key));
|
||||
}
|
||||
else
|
||||
{
|
||||
var texture = key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {PIXI.Texture} texture - The texture the animation is using.
|
||||
*/
|
||||
this.texture = texture;
|
||||
|
||||
PIXI.DisplayObjectContainer.call(this);
|
||||
|
||||
this.dirty = true;
|
||||
this.blendMode = Phaser.blendModes.NORMAL;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} creatureBoundsMin - The minimum bounds point.
|
||||
* @protected
|
||||
*/
|
||||
this.creatureBoundsMin = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} creatureBoundsMax - The maximum bounds point.
|
||||
* @protected
|
||||
*/
|
||||
this.creatureBoundsMax = new Phaser.Point();
|
||||
|
||||
var target = this.manager.target_creature;
|
||||
|
||||
/**
|
||||
* @property {Float32Array} vertices - The vertices data.
|
||||
* @protected
|
||||
*/
|
||||
this.vertices = new Float32Array(target.total_num_pts * 2);
|
||||
|
||||
/**
|
||||
* @property {Float32Array} uvs - The UV data.
|
||||
* @protected
|
||||
*/
|
||||
this.uvs = new Float32Array(target.total_num_pts * 2);
|
||||
|
||||
/**
|
||||
* @property {Uint16Array} indices
|
||||
* @protected
|
||||
*/
|
||||
this.indices = new Uint16Array(target.global_indices.length);
|
||||
|
||||
for (var i = 0; i < this.indices.length; i++)
|
||||
{
|
||||
this.indices[i] = target.global_indices[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {Uint16Array} colors - The vertices colors
|
||||
* @protected
|
||||
*/
|
||||
this.colors = new Float32Array([1, 1, 1, 1]);
|
||||
|
||||
this.updateRenderData(target.global_pts, target.global_uvs);
|
||||
|
||||
this.manager.AddAnimation(this.animation);
|
||||
this.manager.SetActiveAnimationName(animation, false);
|
||||
|
||||
Phaser.Component.Core.init.call(this, game, x, y);
|
||||
|
||||
};
|
||||
|
||||
Phaser.GameObject.Creature.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
|
||||
Phaser.GameObject.Creature.prototype.constructor = Phaser.GameObject.Creature;
|
||||
|
||||
Phaser.Component.Core.install.call(Phaser.GameObject.Creature.prototype, [
|
||||
'Angle',
|
||||
'AutoCull',
|
||||
'BringToTop',
|
||||
'Destroy',
|
||||
'FixedToCamera',
|
||||
'LifeSpan',
|
||||
'Reset'
|
||||
]);
|
||||
|
||||
Phaser.GameObject.Creature.prototype.preUpdateInWorld = Phaser.Component.InWorld.preUpdate;
|
||||
Phaser.GameObject.Creature.prototype.preUpdateCore = Phaser.Component.Core.preUpdate;
|
||||
|
||||
/**
|
||||
* Automatically called by World.preUpdate.
|
||||
*
|
||||
* @method Phaser.GameObject.Creature#preUpdate
|
||||
* @memberof Phaser.GameObject.Creature
|
||||
*/
|
||||
Phaser.GameObject.Creature.prototype.preUpdate = function () {
|
||||
|
||||
if (!this.preUpdateInWorld())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.manager.Update(this.timeDelta);
|
||||
|
||||
this.updateData();
|
||||
|
||||
return this.preUpdateCore();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @method Phaser.GameObject.Creature#_initWebGL
|
||||
* @memberof Phaser.GameObject.Creature
|
||||
* @private
|
||||
*/
|
||||
Phaser.GameObject.Creature.prototype._initWebGL = function (renderSession) {
|
||||
|
||||
// build the strip!
|
||||
var gl = renderSession.gl;
|
||||
|
||||
this._vertexBuffer = gl.createBuffer();
|
||||
this._indexBuffer = gl.createBuffer();
|
||||
this._uvBuffer = gl.createBuffer();
|
||||
this._colorBuffer = gl.createBuffer();
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.vertices, gl.DYNAMIC_DRAW);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._uvBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.uvs, gl.DYNAMIC_DRAW);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._colorBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.colors, gl.STATIC_DRAW);
|
||||
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @method Phaser.GameObject.Creature#_renderWebGL
|
||||
* @memberof Phaser.GameObject.Creature
|
||||
* @private
|
||||
*/
|
||||
Phaser.GameObject.Creature.prototype._renderWebGL = function (renderSession) {
|
||||
|
||||
// If the sprite is not visible or the alpha is 0 then no need to render this element
|
||||
if (!this.visible || this.alpha <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
renderSession.spriteBatch.stop();
|
||||
|
||||
// init! init!
|
||||
if (!this._vertexBuffer)
|
||||
{
|
||||
this._initWebGL(renderSession);
|
||||
}
|
||||
|
||||
renderSession.shaderManager.setShader(renderSession.shaderManager.stripShader);
|
||||
|
||||
this._renderCreature(renderSession);
|
||||
|
||||
renderSession.spriteBatch.start();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @method Phaser.GameObject.Creature#_renderCreature
|
||||
* @memberof Phaser.GameObject.Creature
|
||||
* @private
|
||||
*/
|
||||
Phaser.GameObject.Creature.prototype._renderCreature = function (renderSession) {
|
||||
|
||||
var gl = renderSession.gl;
|
||||
|
||||
var projection = renderSession.projection;
|
||||
var offset = renderSession.offset;
|
||||
var shader = renderSession.shaderManager.stripShader;
|
||||
|
||||
renderSession.blendModeManager.setBlendMode(this.blendMode);
|
||||
|
||||
// Set uniforms
|
||||
gl.uniformMatrix3fv(shader.translationMatrix, false, this.worldTransform.toArray(true));
|
||||
gl.uniform2f(shader.projectionVector, projection.x, -projection.y);
|
||||
gl.uniform2f(shader.offsetVector, -offset.x, -offset.y);
|
||||
gl.uniform1f(shader.alpha, this.worldAlpha);
|
||||
|
||||
if (!this.dirty)
|
||||
{
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer);
|
||||
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.vertices);
|
||||
gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
// Update the uvs
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._uvBuffer);
|
||||
gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
|
||||
// Check if a texture is dirty..
|
||||
if (this.texture.baseTexture._dirty[gl.id])
|
||||
{
|
||||
renderSession.renderer.updateTexture(this.texture.baseTexture);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Bind the current texture
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id]);
|
||||
}
|
||||
|
||||
// Don't need to upload!
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dirty = false;
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.vertices, gl.DYNAMIC_DRAW);
|
||||
gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
// Update the uvs
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._uvBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.uvs, gl.DYNAMIC_DRAW);
|
||||
gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
|
||||
// Check if a texture is dirty
|
||||
if (this.texture.baseTexture._dirty[gl.id])
|
||||
{
|
||||
renderSession.renderer.updateTexture(this.texture.baseTexture);
|
||||
}
|
||||
else
|
||||
{
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id]);
|
||||
}
|
||||
|
||||
// Don't need to upload!
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW);
|
||||
}
|
||||
|
||||
gl.drawElements(gl.TRIANGLES, this.indices.length, gl.UNSIGNED_SHORT, 0);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @method Phaser.GameObject.Creature#updateCreatureBounds
|
||||
* @memberof Phaser.GameObject.Creature
|
||||
* @private
|
||||
*/
|
||||
Phaser.GameObject.Creature.prototype.updateCreatureBounds = function () {
|
||||
|
||||
// Update bounds based off world transform matrix
|
||||
var target = this.manager.target_creature;
|
||||
|
||||
target.ComputeBoundaryMinMax();
|
||||
|
||||
this.creatureBoundsMin.set(target.boundary_min[0], -target.boundary_min[1]);
|
||||
this.creatureBoundsMax.set(target.boundary_max[0], -target.boundary_max[1]);
|
||||
|
||||
this.worldTransform.apply(this.creatureBoundsMin, this.creatureBoundsMin);
|
||||
this.worldTransform.apply(this.creatureBoundsMax, this.creatureBoundsMax);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @method Phaser.GameObject.Creature#updateData
|
||||
* @memberof Phaser.GameObject.Creature
|
||||
* @private
|
||||
*/
|
||||
Phaser.GameObject.Creature.prototype.updateData = function () {
|
||||
|
||||
var target = this.manager.target_creature;
|
||||
|
||||
var read_pts = target.render_pts;
|
||||
var read_uvs = target.global_uvs;
|
||||
|
||||
this.updateRenderData(read_pts, read_uvs);
|
||||
this.updateCreatureBounds();
|
||||
|
||||
this.dirty = true;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @method Phaser.GameObject.Creature#updateRenderData
|
||||
* @memberof Phaser.GameObject.Creature
|
||||
* @private
|
||||
*/
|
||||
Phaser.GameObject.Creature.prototype.updateRenderData = function (verts, uvs) {
|
||||
|
||||
var target = this.manager.target_creature;
|
||||
|
||||
var pt_index = 0;
|
||||
var uv_index = 0;
|
||||
|
||||
var write_pt_index = 0;
|
||||
|
||||
for (var i = 0; i < target.total_num_pts; i++)
|
||||
{
|
||||
this.vertices[write_pt_index] = verts[pt_index];
|
||||
this.vertices[write_pt_index + 1] = -verts[pt_index + 1];
|
||||
|
||||
this.uvs[uv_index] = uvs[uv_index];
|
||||
this.uvs[uv_index + 1] = uvs[uv_index + 1];
|
||||
|
||||
pt_index += 3;
|
||||
uv_index += 2;
|
||||
|
||||
write_pt_index += 2;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the Animation this Creature object will play, as defined in the mesh data.
|
||||
*
|
||||
* @method Phaser.GameObject.Creature#setAnimation
|
||||
* @memberof Phaser.GameObject.Creature
|
||||
* @param {string} key - The key of the animation to set, as defined in the mesh data.
|
||||
*/
|
||||
Phaser.GameObject.Creature.prototype.setAnimation = function (key) {
|
||||
|
||||
this.manager.SetActiveAnimationName(key, true);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Plays the currently set animation.
|
||||
*
|
||||
* @method Phaser.GameObject.Creature#play
|
||||
* @memberof Phaser.GameObject.Creature
|
||||
* @param {boolean} [loop=false] - Should the animation loop?
|
||||
*/
|
||||
Phaser.GameObject.Creature.prototype.play = function (loop) {
|
||||
|
||||
if (loop === undefined) { loop = false; }
|
||||
|
||||
this.loop = loop;
|
||||
|
||||
this.manager.SetIsPlaying(true);
|
||||
this.manager.RunAtTime(0);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Stops the currently playing animation.
|
||||
*
|
||||
* @method Phaser.GameObject.Creature#stop
|
||||
* @memberof Phaser.GameObject.Creature
|
||||
*/
|
||||
Phaser.GameObject.Creature.prototype.stop = function () {
|
||||
|
||||
this.manager.SetIsPlaying(false);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @name Phaser.GameObject.Creature#isPlaying
|
||||
* @property {boolean} isPlaying - Is the _current_ animation playing?
|
||||
*/
|
||||
Object.defineProperty(Phaser.GameObject.Creature.prototype, 'isPlaying', {
|
||||
|
||||
get: function() {
|
||||
|
||||
return this.manager.GetIsPlaying();
|
||||
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
this.manager.SetIsPlaying(value);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.GameObject.Creature#loop
|
||||
* @property {boolean} loop - Should the _current_ animation loop or not?
|
||||
*/
|
||||
Object.defineProperty(Phaser.GameObject.Creature.prototype, 'loop', {
|
||||
|
||||
get: function() {
|
||||
|
||||
return this.manager.should_loop;
|
||||
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
this.manager.SetShouldLoop(value);
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -1,64 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.GameObject.Creature.FACTORY_KEY = 'creature';
|
||||
|
||||
/**
|
||||
* Create a new Creature Animation object.
|
||||
*
|
||||
* Creature is a custom Game Object used in conjunction with the Creature Runtime libraries by Kestrel Moon Studios.
|
||||
*
|
||||
* It allows you to display animated Game Objects that were created with the [Creature Automated Animation Tool](http://www.kestrelmoon.com/creature/).
|
||||
*
|
||||
* Note 1: You can only use Phaser.Creature objects in WebGL enabled games. They do not work in Canvas mode games.
|
||||
*
|
||||
* Note 2: You must use a build of Phaser that includes the CreatureMeshBone.js runtime and gl-matrix.js, or have them
|
||||
* loaded before your Phaser game boots.
|
||||
*
|
||||
* See the Phaser custom build process for more details.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#creature
|
||||
* @param {number} [x=0] - The x coordinate of the creature. The coordinate is relative to any parent container this creature may be in.
|
||||
* @param {number} [y=0] - The y coordinate of the creature. The coordinate is relative to any parent container this creature may be in.
|
||||
* @param {string|PIXI.Texture} [key] - The image used as a texture by this creature object during rendering. If a string Phaser will get for an entry in the Image Cache. Or it can be an instance of a PIXI.Texture.
|
||||
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
|
||||
* @return {Phaser.Creature} The newly created Sprite object.
|
||||
*/
|
||||
Phaser.GameObject.Creature.FACTORY_ADD = function (x, y, key, mesh, group)
|
||||
{
|
||||
if (group === undefined) { group = this.world; }
|
||||
|
||||
var obj = new Phaser.GameObject.Creature(this.game, x, y, key, mesh);
|
||||
|
||||
group.add(obj);
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new Creature Animation object.
|
||||
*
|
||||
* Creature is a custom Game Object used in conjunction with the Creature Runtime libraries by Kestrel Moon Studios.
|
||||
*
|
||||
* It allows you to display animated Game Objects that were created with the [Creature Automated Animation Tool](http://www.kestrelmoon.com/creature/).
|
||||
*
|
||||
* Note 1: You can only use Phaser.Creature objects in WebGL enabled games. They do not work in Canvas mode games.
|
||||
*
|
||||
* Note 2: You must use a build of Phaser that includes the CreatureMeshBone.js runtime and gl-matrix.js, or have them
|
||||
* loaded before your Phaser game boots.
|
||||
*
|
||||
* See the Phaser custom build process for more details.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#creature
|
||||
* @param {number} [x=0] - The x coordinate of the creature. The coordinate is relative to any parent container this creature may be in.
|
||||
* @param {number} [y=0] - The y coordinate of the creature. The coordinate is relative to any parent container this creature may be in.
|
||||
* @param {string|PIXI.Texture} [key] - The image used as a texture by this creature object during rendering. If a string Phaser will get for an entry in the Image Cache. Or it can be an instance of a PIXI.Texture.
|
||||
* @return {Phaser.Creature} The newly created Sprite object.
|
||||
*/
|
||||
Phaser.GameObject.Creature.FACTORY_MAKE = function (x, y, key, mesh)
|
||||
{
|
||||
return new Phaser.GameObject.Creature(this.game, x, y, key, mesh);
|
||||
};
|
File diff suppressed because it is too large
Load diff
|
@ -1,229 +0,0 @@
|
|||
|
||||
/**
|
||||
* Note that 'this' in all functions here refer to the owning object.
|
||||
* For example the Group, Stage, Sprite, etc. because the render function
|
||||
* here is mapped to the prototype for the game object.
|
||||
*/
|
||||
Phaser.Renderer.Canvas.GameObjects.Graphics = {
|
||||
|
||||
TYPES: [
|
||||
Phaser.GameObject.Graphics.prototype
|
||||
],
|
||||
|
||||
render: function (renderer, src)
|
||||
{
|
||||
var context = renderer.context;
|
||||
|
||||
if (this.dirty)
|
||||
{
|
||||
this.updateGraphicsTint();
|
||||
|
||||
this.dirty = false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.graphicsData.length; i++)
|
||||
{
|
||||
var data = this.graphicsData[i];
|
||||
|
||||
context.lineWidth = data.lineWidth;
|
||||
|
||||
switch (data.type)
|
||||
{
|
||||
case Phaser.RECTANGLE:
|
||||
Phaser.Renderer.Canvas.GameObjects.Graphics.drawRectangle(data, context);
|
||||
break;
|
||||
|
||||
case Phaser.CIRCLE:
|
||||
Phaser.Renderer.Canvas.GameObjects.Graphics.drawCircle(data, context);
|
||||
break;
|
||||
|
||||
case Phaser.POLYGON:
|
||||
Phaser.Renderer.Canvas.GameObjects.Graphics.drawPolygon(data, context);
|
||||
break;
|
||||
|
||||
case Phaser.ELLIPSE:
|
||||
Phaser.Renderer.Canvas.GameObjects.Graphics.drawEllipse(data, context);
|
||||
break;
|
||||
|
||||
case Phaser.ROUNDEDRECTANGLE:
|
||||
Phaser.Renderer.Canvas.GameObjects.Graphics.drawRoundedRectangle(data, context);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
drawRectangle: function (data, context)
|
||||
{
|
||||
var shape = data.shape;
|
||||
|
||||
if (data.fillColor || data.fillColor === 0)
|
||||
{
|
||||
context.globalAlpha = data.fillAlpha * this.worldAlpha;
|
||||
context.fillStyle = '#' + ('00000' + (data._fillTint | 0).toString(16)).substr(-6);
|
||||
context.fillRect(shape.x, shape.y, shape.width, shape.height);
|
||||
}
|
||||
|
||||
if (data.lineWidth)
|
||||
{
|
||||
context.globalAlpha = data.lineAlpha * this.worldAlpha;
|
||||
context.strokeStyle = '#' + ('00000' + (data._lineTint | 0).toString(16)).substr(-6);
|
||||
context.strokeRect(shape.x, shape.y, shape.width, shape.height);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
drawRoundedRectangle: function (data, context)
|
||||
{
|
||||
var shape = data.shape;
|
||||
|
||||
var rx = shape.x;
|
||||
var ry = shape.y;
|
||||
var width = shape.width;
|
||||
var height = shape.height;
|
||||
var radius = shape.radius;
|
||||
|
||||
var maxRadius = Math.min(width, height) / 2 | 0;
|
||||
radius = radius > maxRadius ? maxRadius : radius;
|
||||
|
||||
context.beginPath();
|
||||
context.moveTo(rx, ry + radius);
|
||||
context.lineTo(rx, ry + height - radius);
|
||||
context.quadraticCurveTo(rx, ry + height, rx + radius, ry + height);
|
||||
context.lineTo(rx + width - radius, ry + height);
|
||||
context.quadraticCurveTo(rx + width, ry + height, rx + width, ry + height - radius);
|
||||
context.lineTo(rx + width, ry + radius);
|
||||
context.quadraticCurveTo(rx + width, ry, rx + width - radius, ry);
|
||||
context.lineTo(rx + radius, ry);
|
||||
context.quadraticCurveTo(rx, ry, rx, ry + radius);
|
||||
context.closePath();
|
||||
|
||||
if (data.fillColor || data.fillColor === 0)
|
||||
{
|
||||
context.globalAlpha = data.fillAlpha * this.worldAlpha;
|
||||
context.fillStyle = '#' + ('00000' + (data._fillTint | 0).toString(16)).substr(-6);
|
||||
context.fill();
|
||||
}
|
||||
|
||||
if (data.lineWidth)
|
||||
{
|
||||
context.globalAlpha = data.lineAlpha * this.worldAlpha;
|
||||
context.strokeStyle = '#' + ('00000' + (data._lineTint | 0).toString(16)).substr(-6);
|
||||
context.stroke();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
drawEllipse: function (data, context)
|
||||
{
|
||||
var shape = data.shape;
|
||||
|
||||
// ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
|
||||
|
||||
var w = shape.width * 2;
|
||||
var h = shape.height * 2;
|
||||
|
||||
var x = shape.x - (w / 2);
|
||||
var y = shape.y - (h / 2);
|
||||
|
||||
context.beginPath();
|
||||
|
||||
var kappa = 0.5522848;
|
||||
var ox = (w / 2) * kappa; // control point offset horizontal
|
||||
var oy = (h / 2) * kappa; // control point offset vertical
|
||||
var xe = x + w; // x-end
|
||||
var ye = y + h; // y-end
|
||||
var xm = x + (w / 2); // x-middle
|
||||
var ym = y + (h / 2); // y-middle
|
||||
|
||||
context.moveTo(x, ym);
|
||||
context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
|
||||
context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
|
||||
context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
|
||||
context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
|
||||
|
||||
context.closePath();
|
||||
|
||||
if (data.fill)
|
||||
{
|
||||
context.globalAlpha = data.fillAlpha * this.worldAlpha;
|
||||
context.fillStyle = '#' + ('00000' + (data._fillTint | 0).toString(16)).substr(-6);
|
||||
context.fill();
|
||||
}
|
||||
|
||||
if (data.lineWidth)
|
||||
{
|
||||
context.globalAlpha = data.lineAlpha * this.worldAlpha;
|
||||
context.strokeStyle = '#' + ('00000' + (data._lineTint | 0).toString(16)).substr(-6);
|
||||
context.stroke();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
drawCircle: function (data, context)
|
||||
{
|
||||
var shape = data.shape;
|
||||
|
||||
context.beginPath();
|
||||
context.arc(shape.x, shape.y, shape.radius, 0, 2 * Math.PI);
|
||||
context.closePath();
|
||||
|
||||
if (data.fill)
|
||||
{
|
||||
context.globalAlpha = data.fillAlpha * this.worldAlpha;
|
||||
context.fillStyle = '#' + ('00000' + (data._fillTint | 0).toString(16)).substr(-6);
|
||||
context.fill();
|
||||
}
|
||||
|
||||
if (data.lineWidth)
|
||||
{
|
||||
context.globalAlpha = data.lineAlpha * this.worldAlpha;
|
||||
context.strokeStyle = '#' + ('00000' + (data._lineTint | 0).toString(16)).substr(-6);
|
||||
context.stroke();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
drawPolygon: function (data, context)
|
||||
{
|
||||
var shape = data.shape;
|
||||
|
||||
context.beginPath();
|
||||
|
||||
var points = shape.points;
|
||||
|
||||
context.moveTo(points[0], points[1]);
|
||||
|
||||
for (var j = 1; j < points.length / 2; j++)
|
||||
{
|
||||
context.lineTo(points[j * 2], points[j * 2 + 1]);
|
||||
}
|
||||
|
||||
if (shape.closed)
|
||||
{
|
||||
context.lineTo(points[0], points[1]);
|
||||
}
|
||||
|
||||
// if the first and last point are the same close the path - much neater :)
|
||||
if (points[0] === points[points.length - 2] && points[1] === points[points.length - 1])
|
||||
{
|
||||
context.closePath();
|
||||
}
|
||||
|
||||
if (data.fill)
|
||||
{
|
||||
context.globalAlpha = data.fillAlpha * this.worldAlpha;
|
||||
context.fillStyle = '#' + ('00000' + (data._fillTint | 0).toString(16)).substr(-6);
|
||||
context.fill();
|
||||
}
|
||||
|
||||
if (data.lineWidth)
|
||||
{
|
||||
context.globalAlpha = data.lineAlpha * this.worldAlpha;
|
||||
context.strokeStyle = '#' + ('00000' + (data._lineTint | 0).toString(16)).substr(-6);
|
||||
context.stroke();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,88 +0,0 @@
|
|||
/**
|
||||
* A GraphicsData object.
|
||||
*
|
||||
* @class
|
||||
* @memberof PIXI
|
||||
* @param lineWidth {number} the width of the line to draw
|
||||
* @param lineColor {number} the color of the line to draw
|
||||
* @param lineAlpha {number} the alpha of the line to draw
|
||||
* @param fillColor {number} the color of the fill
|
||||
* @param fillAlpha {number} the alpha of the fill
|
||||
* @param fill {boolean} whether or not the shape is filled with a colour
|
||||
* @param shape {Circle|Rectangle|Ellipse|Line|Polygon} The shape object to draw.
|
||||
*/
|
||||
|
||||
Phaser.GraphicsData = function (lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) {
|
||||
|
||||
/*
|
||||
* @member {number} the width of the line to draw
|
||||
*/
|
||||
this.lineWidth = lineWidth;
|
||||
|
||||
/*
|
||||
* @member {number} the color of the line to draw
|
||||
*/
|
||||
this.lineColor = lineColor;
|
||||
|
||||
/*
|
||||
* @member {number} the alpha of the line to draw
|
||||
*/
|
||||
this.lineAlpha = lineAlpha;
|
||||
|
||||
/*
|
||||
* @member {number} cached tint of the line to draw
|
||||
*/
|
||||
this._lineTint = lineColor;
|
||||
|
||||
/*
|
||||
* @member {number} the color of the fill
|
||||
*/
|
||||
this.fillColor = fillColor;
|
||||
|
||||
/*
|
||||
* @member {number} the alpha of the fill
|
||||
*/
|
||||
this.fillAlpha = fillAlpha;
|
||||
|
||||
/*
|
||||
* @member {number} cached tint of the fill
|
||||
*/
|
||||
this._fillTint = fillColor;
|
||||
|
||||
/*
|
||||
* @member {boolean} whether or not the shape is filled with a color
|
||||
*/
|
||||
this.fill = fill;
|
||||
|
||||
/*
|
||||
* @member {Circle|Rectangle|Ellipse|Line|Polygon} The shape object to draw.
|
||||
*/
|
||||
this.shape = shape;
|
||||
|
||||
/*
|
||||
* @member {number} The type of the shape, see the Const.Shapes file for all the existing types,
|
||||
*/
|
||||
this.type = shape.type;
|
||||
|
||||
};
|
||||
|
||||
Phaser.GraphicsData.prototype.constructor = Phaser.GraphicsData;
|
||||
|
||||
/**
|
||||
* Creates a new GraphicsData object with the same values as this one.
|
||||
*
|
||||
* @return {GraphicsData}
|
||||
*/
|
||||
Phaser.GraphicsData.prototype.clone = function () {
|
||||
|
||||
return new Phaser.GraphicsData(
|
||||
this.lineWidth,
|
||||
this.lineColor,
|
||||
this.lineAlpha,
|
||||
this.fillColor,
|
||||
this.fillAlpha,
|
||||
this.fill,
|
||||
this.shape
|
||||
);
|
||||
|
||||
};
|
|
@ -1,37 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.GameObject.Graphics.FACTORY_KEY = 'graphics';
|
||||
|
||||
/**
|
||||
* Creates a new Graphics object.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#graphics
|
||||
* @param {number} [x=0] - The x coordinate of the Graphic. The coordinate is relative to any parent container this object may be in.
|
||||
* @param {number} [y=0] - The y coordinate of the Graphic. The coordinate is relative to any parent container this object may be in.
|
||||
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
|
||||
* @return {Phaser.Graphics} The newly created graphics object.
|
||||
*/
|
||||
Phaser.GameObject.Graphics.FACTORY_ADD = function (x, y, group)
|
||||
{
|
||||
if (group === undefined) { group = this.world; }
|
||||
|
||||
return group.add(new Phaser.GameObject.Graphics(this.game, x, y));
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new Graphics object.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#graphics
|
||||
* @param {number} [x=0] - The x coordinate of the Graphic. The coordinate is relative to any parent container this object may be in.
|
||||
* @param {number} [y=0] - The y coordinate of the Graphic. The coordinate is relative to any parent container this object may be in.
|
||||
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
|
||||
* @return {Phaser.Graphics} The newly created graphics object.
|
||||
*/
|
||||
Phaser.GameObject.Graphics.FACTORY_MAKE = function (x, y)
|
||||
{
|
||||
return new Phaser.GameObject.Graphics(this.game, x, y);
|
||||
};
|
|
@ -1,52 +0,0 @@
|
|||
Phaser.Renderer.WebGL.GameObjects.GraphicsData = function (gl)
|
||||
{
|
||||
this.gl = gl;
|
||||
|
||||
this.color = [0, 0, 0];
|
||||
this.points = [];
|
||||
this.indices = [];
|
||||
this.buffer = gl.createBuffer();
|
||||
this.indexBuffer = gl.createBuffer();
|
||||
this.mode = 1;
|
||||
this.alpha = 1;
|
||||
this.dirty = true;
|
||||
};
|
||||
|
||||
Phaser.Renderer.WebGL.GameObjects.GraphicsData.prototype.constructor = Phaser.Renderer.WebGL.GameObjects.GraphicsData;
|
||||
|
||||
Phaser.Renderer.WebGL.GameObjects.GraphicsData.prototype = {
|
||||
|
||||
reset: function ()
|
||||
{
|
||||
this.points = [];
|
||||
this.indices = [];
|
||||
},
|
||||
|
||||
upload: function ()
|
||||
{
|
||||
var gl = this.gl;
|
||||
|
||||
this.glPoints = new Float32Array(this.points);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.glPoints, gl.STATIC_DRAW);
|
||||
|
||||
this.glIndicies = new Uint16Array(this.indices);
|
||||
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.glIndicies, gl.STATIC_DRAW);
|
||||
|
||||
this.dirty = false;
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
this.gl = null;
|
||||
this.color = null;
|
||||
this.points = null;
|
||||
this.indices = null;
|
||||
this.buffer = null;
|
||||
this.indexBuffer = null;
|
||||
}
|
||||
|
||||
};
|
|
@ -1,857 +0,0 @@
|
|||
// Graphics
|
||||
|
||||
Phaser.Renderer.WebGL.GameObjects.Graphics = {
|
||||
|
||||
TYPES: [
|
||||
Phaser.GameObject.Graphics.prototype
|
||||
],
|
||||
|
||||
circleSegments: 40,
|
||||
|
||||
graphicsDataPool: [],
|
||||
|
||||
render: function (renderer, src)
|
||||
{
|
||||
if (src.visible === false || src.alpha === 0 || src.isMask === true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (src._cacheAsBitmap)
|
||||
{
|
||||
if (src.dirty || src.cachedSpriteDirty)
|
||||
{
|
||||
src._generateCachedSprite();
|
||||
|
||||
// we will also need to update the texture on the gpu too!
|
||||
src.updateCachedSpriteTexture();
|
||||
|
||||
src.cachedSpriteDirty = false;
|
||||
src.dirty = false;
|
||||
}
|
||||
|
||||
src._cachedSprite.worldAlpha = src.worldAlpha;
|
||||
|
||||
// PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
renderer.spriteBatch.stop();
|
||||
renderer.setBlendMode(src.blendMode);
|
||||
|
||||
if (src._mask)
|
||||
{
|
||||
renderer.pushMask(src._mask);
|
||||
}
|
||||
|
||||
if (src._filters)
|
||||
{
|
||||
renderer.filterManager.pushFilter(src._filterBlock);
|
||||
}
|
||||
|
||||
// check blend mode
|
||||
if (src.blendMode !== renderer.spriteBatch.currentBlendMode)
|
||||
{
|
||||
renderer.spriteBatch.currentBlendMode = src.blendMode;
|
||||
|
||||
var blendModeWebGL = renderer.blendModes[renderer.spriteBatch.currentBlendMode];
|
||||
|
||||
renderer.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]);
|
||||
}
|
||||
|
||||
// check if the webgl graphic needs to be updated
|
||||
if (src.webGLDirty)
|
||||
{
|
||||
src.dirty = true;
|
||||
src.webGLDirty = false;
|
||||
}
|
||||
|
||||
var gl = renderer.gl;
|
||||
var offset = renderer.offset;
|
||||
var projection = renderer.projection;
|
||||
var shader = renderer.shaderManager.primitiveShader;
|
||||
var webGLData;
|
||||
|
||||
if (src.dirty)
|
||||
{
|
||||
Phaser.Renderer.WebGL.GameObjects.Graphics.updateGraphics(renderer, src);
|
||||
}
|
||||
|
||||
for (var i = 0; i < src._webGL.data.length; i++)
|
||||
{
|
||||
webGLData = src._webGL.data[i];
|
||||
|
||||
if (webGLData.mode === 1)
|
||||
{
|
||||
renderer.stencilManager.pushStencil(src, webGLData);
|
||||
|
||||
gl.drawElements(gl.TRIANGLE_FAN, 4, gl.UNSIGNED_SHORT, (webGLData.indices.length - 4) * 2);
|
||||
|
||||
renderer.stencilManager.popStencil(src, webGLData);
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer.shaderManager.setShader(shader);
|
||||
|
||||
// shader = renderSession.shaderManager.primitiveShader;
|
||||
|
||||
gl.uniformMatrix3fv(shader.translationMatrix, false, src.worldTransform.toArray(true));
|
||||
|
||||
gl.uniform1f(shader.flipY, 1);
|
||||
|
||||
gl.uniform2f(shader.projectionVector, projection.x, -projection.y);
|
||||
gl.uniform2f(shader.offsetVector, -offset.x, -offset.y);
|
||||
|
||||
gl.uniform3fv(shader.tintColor, Phaser.Color.hexToRGBArray(src.tint));
|
||||
|
||||
gl.uniform1f(shader.alpha, src.worldAlpha);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, webGLData.buffer);
|
||||
|
||||
gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, 4 * 6, 0);
|
||||
|
||||
gl.vertexAttribPointer(shader.colorAttribute, 4, gl.FLOAT, false,4 * 6, 2 * 4);
|
||||
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, webGLData.indexBuffer);
|
||||
|
||||
gl.drawElements(gl.TRIANGLE_STRIP, webGLData.indices.length, gl.UNSIGNED_SHORT, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Only render if it has children!
|
||||
if (src.children.length)
|
||||
{
|
||||
renderer.spriteBatch.start();
|
||||
|
||||
for (var i = 0; i < src.children.length; i++)
|
||||
{
|
||||
var child = src.children[i];
|
||||
child.render(renderer, child);
|
||||
}
|
||||
|
||||
renderer.spriteBatch.stop();
|
||||
}
|
||||
|
||||
if (src._filters)
|
||||
{
|
||||
renderer.filterManager.popFilter();
|
||||
}
|
||||
|
||||
if (src._mask)
|
||||
{
|
||||
renderer.popMask(src.mask);
|
||||
}
|
||||
|
||||
renderer.drawCount++;
|
||||
|
||||
renderer.spriteBatch.start();
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates the graphics object
|
||||
*
|
||||
* @static
|
||||
* @private
|
||||
* @method updateGraphics
|
||||
* @param graphicsData {Graphics} The graphics object to update
|
||||
* @param gl {WebGLContext} the current WebGL drawing context
|
||||
*/
|
||||
updateGraphics: function (renderer, graphics)
|
||||
{
|
||||
var gl = renderer.gl;
|
||||
var webGL = graphics._webGL;
|
||||
|
||||
// If the graphics object does not exist in the webGL context time to create it!
|
||||
if (!webGL)
|
||||
{
|
||||
webGL = graphics._webGL = { lastIndex: 0, data: [], gl: gl };
|
||||
}
|
||||
|
||||
// Flag the graphics as not dirty as we are about to update it
|
||||
graphics.dirty = false;
|
||||
|
||||
var i;
|
||||
|
||||
// If the user cleared the graphics object we will need to clear every object
|
||||
if (graphics.clearDirty)
|
||||
{
|
||||
graphics.clearDirty = false;
|
||||
|
||||
// loop through and return all the webGLDatas to the object pool so than can be reused later on
|
||||
for (i = 0; i < webGL.data.length; i++)
|
||||
{
|
||||
var graphicsData = webGL.data[i];
|
||||
|
||||
graphicsData.reset();
|
||||
|
||||
Phaser.Renderer.WebGL.GameObjects.Graphics.graphicsDataPool.push(graphicsData);
|
||||
}
|
||||
|
||||
// Clear the array and reset the index
|
||||
webGL.data = [];
|
||||
webGL.lastIndex = 0;
|
||||
}
|
||||
|
||||
var webGLData;
|
||||
|
||||
// Loop through the Graphics data.
|
||||
// If the object is complex, use the Stencil Buffer.
|
||||
// Otherwise add the object into the batch.
|
||||
|
||||
for (i = webGL.lastIndex; i < graphics.graphicsData.length; i++)
|
||||
{
|
||||
var data = graphics.graphicsData[i];
|
||||
|
||||
switch (data.type)
|
||||
{
|
||||
case Phaser.RECTANGLE:
|
||||
|
||||
webGLData = Phaser.Renderer.WebGL.GameObjects.Graphics.switchMode(webGL, 0);
|
||||
Phaser.Renderer.WebGL.GameObjects.Graphics.buildRectangle(data, webGLData);
|
||||
|
||||
break;
|
||||
|
||||
case Phaser.CIRCLE:
|
||||
case Phaser.ELLIPSE:
|
||||
|
||||
webGLData = Phaser.Renderer.WebGL.GameObjects.Graphics.switchMode(webGL, 0);
|
||||
Phaser.Renderer.WebGL.GameObjects.Graphics.buildCircle(data, webGLData);
|
||||
|
||||
break;
|
||||
|
||||
case Phaser.ROUNDEDRECTANGLE:
|
||||
|
||||
webGLData = Phaser.Renderer.WebGL.GameObjects.Graphics.switchMode(webGL, 0);
|
||||
Phaser.Renderer.WebGL.GameObjects.Graphics.buildRoundedRectangle(data, webGLData);
|
||||
|
||||
break;
|
||||
|
||||
case Phaser.POLYGON:
|
||||
|
||||
// Need to add the points the the graphics object
|
||||
data.points = data.shape.points.slice();
|
||||
|
||||
if (data.shape.closed)
|
||||
{
|
||||
// Close the poly if the value is true!
|
||||
if (data.points[0] !== data.points[data.points.length - 2] || data.points[1] !== data.points[data.points.length - 1])
|
||||
{
|
||||
data.points.push(data.points[0], data.points[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// Check the type
|
||||
if (data.fill)
|
||||
{
|
||||
if (data.points.length >= renderer.stencilBufferLimit)
|
||||
{
|
||||
if (data.points.length < renderer.stencilBufferLimit * 2)
|
||||
{
|
||||
webGLData = Phaser.Renderer.WebGL.GameObjects.Graphics.switchMode(webGL, 0);
|
||||
|
||||
var canDrawUsingSimple = Phaser.Renderer.WebGL.GameObjects.Graphics.buildPoly(data, webGLData);
|
||||
|
||||
if (!canDrawUsingSimple)
|
||||
{
|
||||
webGLData = Phaser.Renderer.WebGL.GameObjects.Graphics.switchMode(webGL, 1);
|
||||
Phaser.Renderer.WebGL.GameObjects.Graphics.buildComplexPoly(data, webGLData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
webGLData = Phaser.Renderer.WebGL.GameObjects.Graphics.switchMode(webGL, 1);
|
||||
Phaser.Renderer.WebGL.GameObjects.Graphics.buildComplexPoly(data, webGLData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.lineWidth > 0)
|
||||
{
|
||||
webGLData = Phaser.Renderer.WebGL.GameObjects.Graphics.switchMode(webGL, 0);
|
||||
Phaser.Renderer.WebGL.GameObjects.Graphics.buildLine(data, webGLData);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
webGL.lastIndex++;
|
||||
}
|
||||
|
||||
// Upload all the dirty data
|
||||
for (i = 0; i < webGL.data.length; i++)
|
||||
{
|
||||
webGLData = webGL.data[i];
|
||||
|
||||
if (webGLData.dirty)
|
||||
{
|
||||
webGLData.upload();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
switchMode: function (webGL, type)
|
||||
{
|
||||
var webGLData;
|
||||
|
||||
if (!webGL.data.length)
|
||||
{
|
||||
webGLData = Phaser.Renderer.WebGL.GameObjects.Graphics.graphicsDataPool.pop() || new Phaser.Renderer.WebGL.GameObjects.GraphicsData(webGL.gl);
|
||||
webGLData.mode = type;
|
||||
webGL.data.push(webGLData);
|
||||
}
|
||||
else
|
||||
{
|
||||
webGLData = webGL.data[webGL.data.length - 1];
|
||||
|
||||
if (webGLData.mode !== type || type === 1)
|
||||
{
|
||||
webGLData = Phaser.Renderer.WebGL.GameObjects.Graphics.graphicsDataPool.pop() || new Phaser.Renderer.WebGL.GameObjects.GraphicsData(webGL.gl);
|
||||
webGLData.mode = type;
|
||||
webGL.data.push(webGLData);
|
||||
}
|
||||
}
|
||||
|
||||
webGLData.dirty = true;
|
||||
|
||||
return webGLData;
|
||||
},
|
||||
|
||||
buildRectangle: function (graphicsData, webGLData)
|
||||
{
|
||||
var rectData = graphicsData.shape;
|
||||
var x = rectData.x;
|
||||
var y = rectData.y;
|
||||
var width = rectData.width;
|
||||
var height = rectData.height;
|
||||
|
||||
if (graphicsData.fill)
|
||||
{
|
||||
var color = Phaser.Color.hexToRGBArray(graphicsData.fillColor);
|
||||
var alpha = graphicsData.fillAlpha;
|
||||
|
||||
var r = color[0] * alpha;
|
||||
var g = color[1] * alpha;
|
||||
var b = color[2] * alpha;
|
||||
|
||||
var verts = webGLData.points;
|
||||
var indices = webGLData.indices;
|
||||
|
||||
var vertPos = verts.length / 6;
|
||||
|
||||
// start
|
||||
verts.push(x, y);
|
||||
verts.push(r, g, b, alpha);
|
||||
|
||||
verts.push(x + width, y);
|
||||
verts.push(r, g, b, alpha);
|
||||
|
||||
verts.push(x , y + height);
|
||||
verts.push(r, g, b, alpha);
|
||||
|
||||
verts.push(x + width, y + height);
|
||||
verts.push(r, g, b, alpha);
|
||||
|
||||
// insert 2 dead triangles..
|
||||
indices.push(vertPos, vertPos, vertPos + 1, vertPos + 2, vertPos + 3, vertPos + 3);
|
||||
}
|
||||
|
||||
if (graphicsData.lineWidth)
|
||||
{
|
||||
var tempPoints = graphicsData.points;
|
||||
|
||||
graphicsData.points = [
|
||||
x, y,
|
||||
x + width, y,
|
||||
x + width, y + height,
|
||||
x, y + height,
|
||||
x, y
|
||||
];
|
||||
|
||||
Phaser.Renderer.WebGL.GameObjects.Graphics.buildLine(graphicsData, webGLData);
|
||||
|
||||
graphicsData.points = tempPoints;
|
||||
}
|
||||
},
|
||||
|
||||
buildRoundedRectangle: function (graphicsData, webGLData)
|
||||
{
|
||||
var rrectData = graphicsData.shape;
|
||||
var x = rrectData.x;
|
||||
var y = rrectData.y;
|
||||
var width = rrectData.width;
|
||||
var height = rrectData.height;
|
||||
|
||||
var radius = rrectData.radius;
|
||||
|
||||
var recPoints = [];
|
||||
|
||||
recPoints.push(x, y + radius);
|
||||
|
||||
recPoints = recPoints.concat(Phaser.Renderer.WebGL.GameObjects.Graphics.quadraticBezierCurve(x, y + height - radius, x, y + height, x + radius, y + height));
|
||||
recPoints = recPoints.concat(Phaser.Renderer.WebGL.GameObjects.Graphics.quadraticBezierCurve(x + width - radius, y + height, x + width, y + height, x + width, y + height - radius));
|
||||
recPoints = recPoints.concat(Phaser.Renderer.WebGL.GameObjects.Graphics.quadraticBezierCurve(x + width, y + radius, x + width, y, x + width - radius, y));
|
||||
recPoints = recPoints.concat(Phaser.Renderer.WebGL.GameObjects.Graphics.quadraticBezierCurve(x + radius, y, x, y, x, y + radius));
|
||||
|
||||
if (graphicsData.fill)
|
||||
{
|
||||
var color = Phaser.Color.hexToRGBArray(graphicsData.fillColor);
|
||||
var alpha = graphicsData.fillAlpha;
|
||||
|
||||
var r = color[0] * alpha;
|
||||
var g = color[1] * alpha;
|
||||
var b = color[2] * alpha;
|
||||
|
||||
var verts = webGLData.points;
|
||||
var indices = webGLData.indices;
|
||||
|
||||
var vecPos = verts.length / 6;
|
||||
|
||||
var triangles = Phaser.EarCut.Triangulate(recPoints, null, 2);
|
||||
|
||||
var i = 0;
|
||||
|
||||
for (i = 0; i < triangles.length; i += 3)
|
||||
{
|
||||
indices.push(triangles[i] + vecPos);
|
||||
indices.push(triangles[i] + vecPos);
|
||||
indices.push(triangles[i + 1] + vecPos);
|
||||
indices.push(triangles[i + 2] + vecPos);
|
||||
indices.push(triangles[i + 2] + vecPos);
|
||||
}
|
||||
|
||||
for (i = 0; i < recPoints.length; i++)
|
||||
{
|
||||
verts.push(recPoints[i], recPoints[++i], r, g, b, alpha);
|
||||
}
|
||||
}
|
||||
|
||||
if (graphicsData.lineWidth)
|
||||
{
|
||||
var tempPoints = graphicsData.points;
|
||||
|
||||
graphicsData.points = recPoints;
|
||||
|
||||
Phaser.Renderer.WebGL.GameObjects.Graphics.buildLine(graphicsData, webGLData);
|
||||
|
||||
graphicsData.points = tempPoints;
|
||||
}
|
||||
},
|
||||
|
||||
quadraticBezierCurve: function (fromX, fromY, cpX, cpY, toX, toY)
|
||||
{
|
||||
var xa;
|
||||
var ya;
|
||||
var xb;
|
||||
var yb;
|
||||
var x;
|
||||
var y;
|
||||
var n = 20;
|
||||
var points = [];
|
||||
|
||||
function getPt (n1, n2, perc)
|
||||
{
|
||||
var diff = n2 - n1;
|
||||
|
||||
return n1 + (diff * perc);
|
||||
};
|
||||
|
||||
var j = 0;
|
||||
|
||||
for (var i = 0; i <= n; i++)
|
||||
{
|
||||
j = i / n;
|
||||
|
||||
// The Green Line
|
||||
xa = getPt(fromX, cpX, j);
|
||||
ya = getPt(fromY, cpY, j);
|
||||
xb = getPt(cpX, toX, j);
|
||||
yb = getPt(cpY, toY, j);
|
||||
|
||||
// The Black Dot
|
||||
x = getPt(xa, xb, j);
|
||||
y = getPt(ya, yb, j);
|
||||
|
||||
points.push(x, y);
|
||||
}
|
||||
|
||||
return points;
|
||||
},
|
||||
|
||||
buildCircle: function (graphicsData, webGLData)
|
||||
{
|
||||
// Need to convert points to a nice regular data
|
||||
var circleData = graphicsData.shape;
|
||||
var x = circleData.x;
|
||||
var y = circleData.y;
|
||||
var width;
|
||||
var height;
|
||||
|
||||
if (graphicsData.type === Phaser.CIRCLE)
|
||||
{
|
||||
width = circleData.radius;
|
||||
height = circleData.radius;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = circleData.width;
|
||||
height = circleData.height;
|
||||
}
|
||||
|
||||
var totalSegs = Phaser.Renderer.WebGL.GameObjects.Graphics.circleSegments;
|
||||
var seg = (Math.PI * 2) / totalSegs;
|
||||
|
||||
var i = 0;
|
||||
|
||||
if (graphicsData.fill)
|
||||
{
|
||||
var color = Phaser.Color.hexToRGBArray(graphicsData.fillColor);
|
||||
var alpha = graphicsData.fillAlpha;
|
||||
|
||||
var r = color[0] * alpha;
|
||||
var g = color[1] * alpha;
|
||||
var b = color[2] * alpha;
|
||||
|
||||
var verts = webGLData.points;
|
||||
var indices = webGLData.indices;
|
||||
|
||||
var vecPos = verts.length / 6;
|
||||
|
||||
indices.push(vecPos);
|
||||
|
||||
for (i = 0; i < totalSegs + 1 ; i++)
|
||||
{
|
||||
verts.push(x, y, r, g, b, alpha);
|
||||
|
||||
verts.push(
|
||||
x + Math.sin(seg * i) * width,
|
||||
y + Math.cos(seg * i) * height,
|
||||
r, g, b, alpha
|
||||
);
|
||||
|
||||
indices.push(vecPos++, vecPos++);
|
||||
}
|
||||
|
||||
indices.push(vecPos - 1);
|
||||
}
|
||||
|
||||
if (graphicsData.lineWidth)
|
||||
{
|
||||
var tempPoints = graphicsData.points;
|
||||
|
||||
graphicsData.points = [];
|
||||
|
||||
for (i = 0; i < totalSegs + 1; i++)
|
||||
{
|
||||
graphicsData.points.push(
|
||||
x + Math.sin(seg * i) * width,
|
||||
y + Math.cos(seg * i) * height
|
||||
);
|
||||
}
|
||||
|
||||
Phaser.Renderer.WebGL.GameObjects.Graphics.buildLine(graphicsData, webGLData);
|
||||
|
||||
graphicsData.points = tempPoints;
|
||||
}
|
||||
},
|
||||
|
||||
buildLine: function (graphicsData, webGLData)
|
||||
{
|
||||
var i = 0;
|
||||
var points = graphicsData.points;
|
||||
|
||||
if (points.length === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If the line width is an odd number add 0.5 to align to a whole pixel
|
||||
if (graphicsData.lineWidth % 2)
|
||||
{
|
||||
for (i = 0; i < points.length; i++)
|
||||
{
|
||||
points[i] += 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
// Get first and last point. Figure out the middle!
|
||||
var firstPoint = new Phaser.Point(points[0], points[1]);
|
||||
var lastPoint = new Phaser.Point(points[points.length - 2], points[points.length - 1]);
|
||||
|
||||
// If the first point is the last point we're gonna have issues :)
|
||||
if (firstPoint.x === lastPoint.x && firstPoint.y === lastPoint.y)
|
||||
{
|
||||
// Need to clone as we are going to slightly modify the shape
|
||||
points = points.slice();
|
||||
|
||||
points.pop();
|
||||
points.pop();
|
||||
|
||||
lastPoint = new Phaser.Point(points[points.length - 2], points[points.length - 1]);
|
||||
|
||||
var midPointX = lastPoint.x + (firstPoint.x - lastPoint.x) * 0.5;
|
||||
var midPointY = lastPoint.y + (firstPoint.y - lastPoint.y) * 0.5;
|
||||
|
||||
points.unshift(midPointX, midPointY);
|
||||
points.push(midPointX, midPointY);
|
||||
}
|
||||
|
||||
var verts = webGLData.points;
|
||||
var indices = webGLData.indices;
|
||||
var length = points.length / 2;
|
||||
var indexCount = points.length;
|
||||
var indexStart = verts.length / 6;
|
||||
|
||||
// Draw the Line
|
||||
var width = graphicsData.lineWidth / 2;
|
||||
|
||||
// Sort the color
|
||||
var color = Phaser.Color.hexToRGBArray(graphicsData.lineColor);
|
||||
var alpha = graphicsData.lineAlpha;
|
||||
var r = color[0] * alpha;
|
||||
var g = color[1] * alpha;
|
||||
var b = color[2] * alpha;
|
||||
|
||||
var px, py, p1x, p1y, p2x, p2y, p3x, p3y;
|
||||
var perpx, perpy, perp2x, perp2y, perp3x, perp3y;
|
||||
var a1, b1, c1, a2, b2, c2;
|
||||
var denom, pdist, dist;
|
||||
|
||||
p1x = points[0];
|
||||
p1y = points[1];
|
||||
|
||||
p2x = points[2];
|
||||
p2y = points[3];
|
||||
|
||||
perpx = -(p1y - p2y);
|
||||
perpy = p1x - p2x;
|
||||
|
||||
dist = Math.sqrt(perpx * perpx + perpy * perpy);
|
||||
|
||||
perpx /= dist;
|
||||
perpy /= dist;
|
||||
perpx *= width;
|
||||
perpy *= width;
|
||||
|
||||
// Start
|
||||
verts.push(p1x - perpx , p1y - perpy, r, g, b, alpha);
|
||||
|
||||
verts.push(p1x + perpx , p1y + perpy, r, g, b, alpha);
|
||||
|
||||
for (i = 1; i < length - 1; i++)
|
||||
{
|
||||
p1x = points[(i - 1) * 2];
|
||||
p1y = points[(i - 1) * 2 + 1];
|
||||
|
||||
p2x = points[(i) * 2];
|
||||
p2y = points[(i) * 2 + 1];
|
||||
|
||||
p3x = points[(i + 1) * 2];
|
||||
p3y = points[(i + 1) * 2 + 1];
|
||||
|
||||
perpx = -(p1y - p2y);
|
||||
perpy = p1x - p2x;
|
||||
|
||||
dist = Math.sqrt(perpx * perpx + perpy * perpy);
|
||||
|
||||
perpx /= dist;
|
||||
perpy /= dist;
|
||||
perpx *= width;
|
||||
perpy *= width;
|
||||
|
||||
perp2x = -(p2y - p3y);
|
||||
perp2y = p2x - p3x;
|
||||
|
||||
dist = Math.sqrt(perp2x * perp2x + perp2y * perp2y);
|
||||
|
||||
perp2x /= dist;
|
||||
perp2y /= dist;
|
||||
perp2x *= width;
|
||||
perp2y *= width;
|
||||
|
||||
a1 = (-perpy + p1y) - (-perpy + p2y);
|
||||
b1 = (-perpx + p2x) - (-perpx + p1x);
|
||||
c1 = (-perpx + p1x) * (-perpy + p2y) - (-perpx + p2x) * (-perpy + p1y);
|
||||
a2 = (-perp2y + p3y) - (-perp2y + p2y);
|
||||
b2 = (-perp2x + p2x) - (-perp2x + p3x);
|
||||
c2 = (-perp2x + p3x) * (-perp2y + p2y) - (-perp2x + p2x) * (-perp2y + p3y);
|
||||
|
||||
denom = a1 * b2 - a2 * b1;
|
||||
|
||||
if (Math.abs(denom) < 0.1)
|
||||
{
|
||||
denom += 10.1;
|
||||
verts.push(p2x - perpx, p2y - perpy, r, g, b, alpha);
|
||||
verts.push(p2x + perpx, p2y + perpy, r, g, b, alpha);
|
||||
continue;
|
||||
}
|
||||
|
||||
px = (b1 * c2 - b2 * c1) / denom;
|
||||
py = (a2 * c1 - a1 * c2) / denom;
|
||||
|
||||
pdist = (px -p2x) * (px -p2x) + (py -p2y) + (py -p2y);
|
||||
|
||||
if (pdist > 140 * 140)
|
||||
{
|
||||
perp3x = perpx - perp2x;
|
||||
perp3y = perpy - perp2y;
|
||||
|
||||
dist = Math.sqrt(perp3x * perp3x + perp3y * perp3y);
|
||||
|
||||
perp3x /= dist;
|
||||
perp3y /= dist;
|
||||
perp3x *= width;
|
||||
perp3y *= width;
|
||||
|
||||
verts.push(p2x - perp3x, p2y -perp3y, r, g, b, alpha);
|
||||
verts.push(p2x + perp3x, p2y +perp3y, r, g, b, alpha);
|
||||
verts.push(p2x - perp3x, p2y -perp3y, r, g, b, alpha);
|
||||
|
||||
indexCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
verts.push(px, py, r, g, b, alpha);
|
||||
verts.push(p2x - (px-p2x), p2y - (py - p2y), r, g, b, alpha);
|
||||
}
|
||||
}
|
||||
|
||||
p1x = points[(length - 2) * 2];
|
||||
p1y = points[(length - 2) * 2 + 1];
|
||||
|
||||
p2x = points[(length - 1) * 2];
|
||||
p2y = points[(length - 1) * 2 + 1];
|
||||
|
||||
perpx = -(p1y - p2y);
|
||||
perpy = p1x - p2x;
|
||||
|
||||
dist = Math.sqrt(perpx * perpx + perpy * perpy);
|
||||
|
||||
perpx /= dist;
|
||||
perpy /= dist;
|
||||
perpx *= width;
|
||||
perpy *= width;
|
||||
|
||||
verts.push(p2x - perpx , p2y - perpy, r, g, b, alpha);
|
||||
verts.push(p2x + perpx , p2y + perpy, r, g, b, alpha);
|
||||
|
||||
indices.push(indexStart);
|
||||
|
||||
for (i = 0; i < indexCount; i++)
|
||||
{
|
||||
indices.push(indexStart++);
|
||||
}
|
||||
|
||||
indices.push(indexStart - 1);
|
||||
},
|
||||
|
||||
buildComplexPoly: function(graphicsData, webGLData)
|
||||
{
|
||||
var points = graphicsData.points.slice();
|
||||
|
||||
if (points.length < 6)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get first and last point.. figure out the middle!
|
||||
var indices = webGLData.indices;
|
||||
webGLData.points = points;
|
||||
webGLData.alpha = graphicsData.fillAlpha;
|
||||
webGLData.color = Phaser.Color.hexToRGBArray(graphicsData.fillColor);
|
||||
|
||||
// Calculate the bounds
|
||||
var minX = Infinity;
|
||||
var maxX = -Infinity;
|
||||
|
||||
var minY = Infinity;
|
||||
var maxY = -Infinity;
|
||||
|
||||
var x;
|
||||
var y;
|
||||
|
||||
// Get the size
|
||||
for (var i = 0; i < points.length; i += 2)
|
||||
{
|
||||
x = points[i];
|
||||
y = points[i + 1];
|
||||
|
||||
minX = (x < minX) ? x : minX;
|
||||
maxX = (x > maxX) ? x : maxX;
|
||||
|
||||
minY = (y < minY) ? y : minY;
|
||||
maxY = (y > maxY) ? y : maxY;
|
||||
}
|
||||
|
||||
// Add a quad to the end because there is no point making another buffer!
|
||||
points.push(
|
||||
minX, minY,
|
||||
maxX, minY,
|
||||
maxX, maxY,
|
||||
minX, maxY
|
||||
);
|
||||
|
||||
// TODO: Is this even needed?
|
||||
var length = points.length / 2;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
indices.push(i);
|
||||
}
|
||||
},
|
||||
|
||||
buildPoly: function (graphicsData, webGLData)
|
||||
{
|
||||
var points = graphicsData.points;
|
||||
|
||||
if (points.length < 6)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get first and last point.. figure out the middle!
|
||||
var verts = webGLData.points;
|
||||
var indices = webGLData.indices;
|
||||
|
||||
var length = points.length / 2;
|
||||
|
||||
// Sort the color
|
||||
var color = Phaser.Color.hexToRGBArray(graphicsData.fillColor);
|
||||
var alpha = graphicsData.fillAlpha;
|
||||
var r = color[0] * alpha;
|
||||
var g = color[1] * alpha;
|
||||
var b = color[2] * alpha;
|
||||
|
||||
var triangles = Phaser.EarCut.Triangulate(points, null, 2);
|
||||
|
||||
if (!triangles)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var vertPos = verts.length / 6;
|
||||
|
||||
var i = 0;
|
||||
|
||||
for (i = 0; i < triangles.length; i += 3)
|
||||
{
|
||||
indices.push(triangles[i] + vertPos);
|
||||
indices.push(triangles[i] + vertPos);
|
||||
indices.push(triangles[i + 1] + vertPos);
|
||||
indices.push(triangles[i + 2] +vertPos);
|
||||
indices.push(triangles[i + 2] + vertPos);
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
verts.push(
|
||||
points[i * 2],
|
||||
points[i * 2 + 1],
|
||||
r, g, b, alpha
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
|
@ -1,96 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* An Image is a light-weight object you can use to display anything that doesn't need physics or animation.
|
||||
* It can still rotate, scale, crop and receive input events. This makes it perfect for logos, backgrounds, simple buttons and other non-Sprite graphics.
|
||||
*
|
||||
* @class Phaser.GameObject.Image
|
||||
* @extends Phaser.GameObject
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {number} [x=0] - The x coordinate of the Image. The coordinate is relative to any parent container this Image may be in.
|
||||
* @param {number} [y=0] - The y coordinate of the Image. The coordinate is relative to any parent container this Image may be in.
|
||||
* @param {string} [key] - The texture used by the Image during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture.
|
||||
* @param {string|number} [frame] - If this Image is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
|
||||
*/
|
||||
Phaser.GameObject.Image = function (state, x, y, key, frame, name)
|
||||
{
|
||||
var _texture = state.game.textures.get(key);
|
||||
var _frame = _texture.get(frame);
|
||||
|
||||
Phaser.GameObject.call(this, state, x, y, _texture, _frame);
|
||||
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* @property {number} type - The const type of this object.
|
||||
* @readonly
|
||||
*/
|
||||
this.type = Phaser.IMAGE;
|
||||
};
|
||||
|
||||
Phaser.GameObject.Image.prototype = Object.create(Phaser.GameObject.prototype);
|
||||
Phaser.GameObject.Image.prototype.constructor = Phaser.GameObject.Image;
|
||||
|
||||
/**
|
||||
* Automatically called by World.preUpdate.
|
||||
*
|
||||
* @method Phaser.Image#preUpdate
|
||||
* @memberof Phaser.Image
|
||||
*/
|
||||
Phaser.GameObject.Image.prototype.preUpdate = function ()
|
||||
{
|
||||
// Would like to get rid of this somehow ...
|
||||
if (this.parent)
|
||||
{
|
||||
this.color.worldAlpha = this.parent.color.worldAlpha;
|
||||
}
|
||||
};
|
||||
|
||||
// Phaser.GameObject.Image.prototype.update = function ()
|
||||
// {
|
||||
// };
|
||||
|
||||
// Phaser.GameObject.Image.prototype.postUpdate = function ()
|
||||
// {
|
||||
// };
|
||||
|
||||
Object.defineProperties(Phaser.GameObject.Image.prototype, {
|
||||
|
||||
width: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleX * this.frame.realWidth;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.scaleX = value / this.frame.realWidth;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
height: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleY * this.frame.realHeight;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.scaleY = value / this.frame.realHeight;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -1,162 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @author Mat Groves (@Doormat23)
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.Renderer.Canvas.GameObjects.Image = {
|
||||
|
||||
TYPES: [
|
||||
Phaser.GameObject.Image.prototype
|
||||
],
|
||||
|
||||
render: function (renderer, src)
|
||||
{
|
||||
var frame = src.frame;
|
||||
var source = frame.source;
|
||||
|
||||
// Skip rendering?
|
||||
|
||||
if (src.skipRender || !src.visible || src.worldAlpha <= 0 || !frame.cutWidth || !frame.cutHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Blend Mode
|
||||
|
||||
if (renderer.currentBlendMode !== src.blendMode)
|
||||
{
|
||||
renderer.currentBlendMode = src.blendMode;
|
||||
renderer.context.globalCompositeOperation = renderer.blendModes[renderer.currentBlendMode];
|
||||
}
|
||||
|
||||
// Alpha
|
||||
|
||||
if (renderer.currentAlpha !== src.worldAlpha)
|
||||
{
|
||||
renderer.currentAlpha = src.worldAlpha;
|
||||
renderer.context.globalAlpha = src.worldAlpha;
|
||||
}
|
||||
|
||||
// Smoothing (should this be a Game Object, or Frame / Texture level property?)
|
||||
|
||||
if (renderer.currentScaleMode !== source.scaleMode)
|
||||
{
|
||||
renderer.currentScaleMode = source.scaleMode;
|
||||
renderer.context[renderer.smoothProperty] = (source.scaleMode === Phaser.scaleModes.LINEAR);
|
||||
}
|
||||
|
||||
var wt = src.transform.world;
|
||||
|
||||
var resolution = source.resolution / renderer.game.resolution;
|
||||
|
||||
var dx = frame.x - (src.anchorX * frame.width);
|
||||
var dy = frame.y - (src.anchorY * frame.height);
|
||||
|
||||
var tx = (wt.tx * renderer.game.resolution) + renderer.game.camera._shake.x;
|
||||
var ty = (wt.ty * renderer.game.resolution) + renderer.game.camera._shake.y;
|
||||
|
||||
// Round Pixels
|
||||
|
||||
if (renderer.roundPixels)
|
||||
{
|
||||
tx |= 0;
|
||||
ty |= 0;
|
||||
dx |= 0;
|
||||
dy |= 0;
|
||||
}
|
||||
|
||||
var cw = frame.cutWidth;
|
||||
var ch = frame.cutHeight;
|
||||
var cwr = cw / resolution;
|
||||
var chr = ch / resolution;
|
||||
|
||||
renderer.context.setTransform(wt.a, wt.b, wt.c, wt.d, tx, ty);
|
||||
|
||||
// Color Component
|
||||
|
||||
if (src.color._hasBackground)
|
||||
{
|
||||
// context save?
|
||||
renderer.context.fillStyle = src.color._rgba;
|
||||
renderer.context.fillRect(dx, dy, cwr, chr);
|
||||
}
|
||||
|
||||
// renderer.context.drawImage(source.image, frame.cutX, frame.cutY, cw, ch, dx, dy, cw / resolution, ch / resolution);
|
||||
|
||||
// Test drawing over the top
|
||||
// renderer.currentBlendMode = src.blendMode;
|
||||
|
||||
// TESTS Works fine :)
|
||||
if (src.texture.key === 'bunny')
|
||||
{
|
||||
renderer.context.drawImage(source.image, frame.cutX, frame.cutY, cw, ch, dx, dy, cw / resolution, ch / resolution);
|
||||
renderer.context.save();
|
||||
// renderer.context.globalCompositeOperation = 'source-in';
|
||||
renderer.context.globalCompositeOperation = 'xor';
|
||||
renderer.context.beginPath();
|
||||
renderer.context.fillStyle = 'rgba(255,0,255,0.5)';
|
||||
renderer.context.fillRect(dx, dy, cwr, chr);
|
||||
renderer.context.closePath();
|
||||
// renderer.context.drawImage(source.image, frame.cutX, frame.cutY, cw, ch, dx, dy, cw / resolution, ch / resolution);
|
||||
renderer.context.restore();
|
||||
renderer.context.globalCompositeOperation = 'source-over';
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer.context.drawImage(source.image, frame.cutX, frame.cutY, cw, ch, dx, dy, cw / resolution, ch / resolution);
|
||||
}
|
||||
|
||||
/*
|
||||
// Move this to either the Renderer, or the Texture Manager, but not here (as it's repeated all over the place)
|
||||
if (src.texture.rotated)
|
||||
{
|
||||
var a = wt.a;
|
||||
var b = wt.b;
|
||||
var c = wt.c;
|
||||
var d = wt.d;
|
||||
var e = cw;
|
||||
|
||||
// Offset before rotating
|
||||
tx = wt.c * ch + tx;
|
||||
ty = wt.d * ch + ty;
|
||||
|
||||
// Rotate matrix by 90 degrees
|
||||
// We use precalculated values for sine and cosine of rad(90)
|
||||
wt.a = a * 6.123233995736766e-17 + -c;
|
||||
wt.b = b * 6.123233995736766e-17 + -d;
|
||||
wt.c = a + c * 6.123233995736766e-17;
|
||||
wt.d = b + d * 6.123233995736766e-17;
|
||||
|
||||
// Update cropping dimensions.
|
||||
cw = ch;
|
||||
ch = e;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
if (src.tint !== 0xFFFFFF)
|
||||
{
|
||||
if (src.texture.requiresReTint || src.cachedTint !== src.tint)
|
||||
{
|
||||
src.tintedTexture = PIXI.CanvasTinter.getTintedTexture(src, src.tint);
|
||||
|
||||
src.cachedTint = src.tint;
|
||||
src.texture.requiresReTint = false;
|
||||
}
|
||||
|
||||
renderer.context.drawImage(src.tintedTexture, 0, 0, cw, ch, dx, dy, cw / resolution, ch / resolution);
|
||||
}
|
||||
else
|
||||
{
|
||||
var cx = src.texture.crop.x;
|
||||
var cy = src.texture.crop.y;
|
||||
|
||||
renderer.context.drawImage(src.texture.baseTexture.source, cx, cy, cw, ch, dx, dy, cw / resolution, ch / resolution);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,48 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.GameObject.Image.FACTORY_KEY = 'image';
|
||||
|
||||
/**
|
||||
* Create a new `Image` object.
|
||||
*
|
||||
* An Image is a light-weight object you can use to display anything that doesn't need physics or animation.
|
||||
*
|
||||
* It can still rotate, scale, crop and receive input events.
|
||||
* This makes it perfect for logos, backgrounds, simple buttons and other non-Sprite graphics.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#image
|
||||
* @param {number} [x=0] - The x coordinate of the Image. The coordinate is relative to any parent container this Image may be in.
|
||||
* @param {number} [y=0] - The y coordinate of the Image. The coordinate is relative to any parent container this Image may be in.
|
||||
* @param {string|Phaser.RenderTexture|Phaser.BitmapData|Phaser.Video|PIXI.Texture} [key] - The image used as a texture by this display object during rendering. If a string Phaser will get for an entry in the Image Cache. Or it can be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
|
||||
* @param {string|number} [frame] - If a Texture Atlas or Sprite Sheet is used this allows you to specify the frame to be used. Use either an integer for a Frame ID or a string for a frame name.
|
||||
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
|
||||
* @return {Phaser.Image} The newly created Image object.
|
||||
*/
|
||||
Phaser.GameObject.Image.FACTORY_ADD = function (x, y, key, frame, group, name)
|
||||
{
|
||||
if (group === undefined) { group = this.state; }
|
||||
|
||||
return group.children.add(new Phaser.GameObject.Image(this.state, x, y, key, frame, name));
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new Image object.
|
||||
*
|
||||
* An Image is a light-weight object you can use to display anything that doesn't need physics or animation.
|
||||
* It can still rotate, scale, crop and receive input events. This makes it perfect for logos, backgrounds, simple buttons and other non-Sprite graphics.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#image
|
||||
* @param {number} x - X position of the image.
|
||||
* @param {number} y - Y position of the image.
|
||||
* @param {string|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
|
||||
* @param {string|number} [frame] - If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
|
||||
* @return {Phaser.Image} the newly created sprite object.
|
||||
*/
|
||||
Phaser.GameObject.Image.FACTORY_MAKE = function (x, y, key, frame)
|
||||
{
|
||||
return new Phaser.GameObject.Image(this.state, x, y, key, frame);
|
||||
};
|
|
@ -1,27 +0,0 @@
|
|||
Phaser.Renderer.WebGL.GameObjects.Image = {
|
||||
|
||||
TYPES: [
|
||||
Phaser.GameObject.Image.prototype
|
||||
],
|
||||
|
||||
render: function (renderer, src, interpolationPercentage)
|
||||
{
|
||||
var frame = src.frame;
|
||||
var alpha = src.color.worldAlpha * 255 << 24;
|
||||
|
||||
// Skip rendering?
|
||||
|
||||
if (src.skipRender || !src.visible || alpha === 0 || !frame.cutWidth || !frame.cutHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var verts = src.transform.getVertexData(interpolationPercentage);
|
||||
var index = src.frame.source.glTextureIndex;
|
||||
var tint = src.color._glTint;
|
||||
var bg = src.color._glBg;
|
||||
|
||||
renderer.batch.add(frame.source, src.blendMode, verts, frame.uvs, index, alpha, tint, bg);
|
||||
}
|
||||
|
||||
};
|
|
@ -1,165 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a new `Particle` object. Particles are extended Sprites that are emitted by a particle emitter such as Phaser.Particles.Arcade.Emitter.
|
||||
*
|
||||
* @class Phaser.GameObject.Particle
|
||||
* @constructor
|
||||
* @extends Phaser.Sprite
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {number} x - The x coordinate (in world space) to position the Particle at.
|
||||
* @param {number} y - The y coordinate (in world space) to position the Particle at.
|
||||
* @param {string|Phaser.RenderTexture|Phaser.BitmapData|PIXI.Texture} key - This is the image or texture used by the Particle during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
|
||||
* @param {string|number} frame - If this Particle is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
|
||||
*/
|
||||
Phaser.GameObject.Particle = function (game, x, y, key, frame) {
|
||||
|
||||
Phaser.GameObject.Sprite.call(this, game, x, y, key, frame);
|
||||
|
||||
/**
|
||||
* @property {boolean} autoScale - If this Particle automatically scales this is set to true by Particle.setScaleData.
|
||||
* @protected
|
||||
*/
|
||||
this.autoScale = false;
|
||||
|
||||
/**
|
||||
* @property {array} scaleData - A reference to the scaleData array owned by the Emitter that emitted this Particle.
|
||||
* @protected
|
||||
*/
|
||||
this.scaleData = null;
|
||||
|
||||
/**
|
||||
* @property {number} _s - Internal cache var for tracking auto scale.
|
||||
* @private
|
||||
*/
|
||||
this._s = 0;
|
||||
|
||||
/**
|
||||
* @property {boolean} autoAlpha - If this Particle automatically changes alpha this is set to true by Particle.setAlphaData.
|
||||
* @protected
|
||||
*/
|
||||
this.autoAlpha = false;
|
||||
|
||||
/**
|
||||
* @property {array} alphaData - A reference to the alphaData array owned by the Emitter that emitted this Particle.
|
||||
* @protected
|
||||
*/
|
||||
this.alphaData = null;
|
||||
|
||||
/**
|
||||
* @property {number} _a - Internal cache var for tracking auto alpha.
|
||||
* @private
|
||||
*/
|
||||
this._a = 0;
|
||||
|
||||
};
|
||||
|
||||
Phaser.GameObject.Particle.prototype = Object.create(Phaser.GameObject.Sprite.prototype);
|
||||
Phaser.GameObject.Particle.prototype.constructor = Phaser.GameObject.Particle;
|
||||
|
||||
/**
|
||||
* Updates the Particle scale or alpha if autoScale and autoAlpha are set.
|
||||
*
|
||||
* @method Phaser.Particle#update
|
||||
* @memberof Phaser.Particle
|
||||
*/
|
||||
Phaser.GameObject.Particle.prototype.update = function() {
|
||||
|
||||
if (this.autoScale)
|
||||
{
|
||||
this._s--;
|
||||
|
||||
if (this._s)
|
||||
{
|
||||
this.scale.set(this.scaleData[this._s].x, this.scaleData[this._s].y);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.autoScale = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.autoAlpha)
|
||||
{
|
||||
this._a--;
|
||||
|
||||
if (this._a)
|
||||
{
|
||||
this.alpha = this.alphaData[this._a].v;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.autoAlpha = false;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Called by the Emitter when this particle is emitted. Left empty for you to over-ride as required.
|
||||
*
|
||||
* @method Phaser.Particle#onEmit
|
||||
* @memberof Phaser.Particle
|
||||
*/
|
||||
Phaser.GameObject.Particle.prototype.onEmit = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Called by the Emitter if autoAlpha has been enabled. Passes over the alpha ease data and resets the alpha counter.
|
||||
*
|
||||
* @method Phaser.Particle#setAlphaData
|
||||
* @memberof Phaser.Particle
|
||||
*/
|
||||
Phaser.GameObject.Particle.prototype.setAlphaData = function(data) {
|
||||
|
||||
this.alphaData = data;
|
||||
this._a = data.length - 1;
|
||||
this.alpha = this.alphaData[this._a].v;
|
||||
this.autoAlpha = true;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Called by the Emitter if autoScale has been enabled. Passes over the scale ease data and resets the scale counter.
|
||||
*
|
||||
* @method Phaser.Particle#setScaleData
|
||||
* @memberof Phaser.Particle
|
||||
*/
|
||||
Phaser.GameObject.Particle.prototype.setScaleData = function(data) {
|
||||
|
||||
this.scaleData = data;
|
||||
this._s = data.length - 1;
|
||||
this.scale.set(this.scaleData[this._s].x, this.scaleData[this._s].y);
|
||||
this.autoScale = true;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Resets the Particle. This places the Particle at the given x/y world coordinates and then
|
||||
* sets alive, exists, visible and renderable all to true. Also resets the outOfBounds state and health values.
|
||||
* If the Particle has a physics body that too is reset.
|
||||
*
|
||||
* @method Phaser.Particle#reset
|
||||
* @memberof Phaser.Particle
|
||||
* @param {number} x - The x coordinate (in world space) to position the Particle at.
|
||||
* @param {number} y - The y coordinate (in world space) to position the Particle at.
|
||||
* @param {number} [health=1] - The health to give the Particle.
|
||||
* @return {Phaser.Particle} This instance.
|
||||
*/
|
||||
Phaser.GameObject.Particle.prototype.reset = function(x, y, health) {
|
||||
|
||||
Phaser.Component.Reset.prototype.reset.call(this, x, y, health);
|
||||
|
||||
this.alpha = 1;
|
||||
this.scale.set(1);
|
||||
|
||||
this.autoScale = false;
|
||||
this.autoAlpha = false;
|
||||
|
||||
return this;
|
||||
|
||||
};
|
|
@ -1,120 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A PixelField is a container, with a position, rotation and scale, that renders pixels.
|
||||
* So it maintains a list of pixels (just coordinates + a color), and renders with a custom batch shader.
|
||||
*
|
||||
* @class Phaser.GameObject.PixelField
|
||||
* @extends Phaser.GameObject
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {number} [x=0] - The x coordinate of the Image. The coordinate is relative to any parent container this Image may be in.
|
||||
* @param {number} [y=0] - The y coordinate of the Image. The coordinate is relative to any parent container this Image may be in.
|
||||
*/
|
||||
Phaser.GameObject.PixelField = function (state, x, y, pixelSize)
|
||||
{
|
||||
if (pixelSize === undefined) { pixelSize = 1; }
|
||||
|
||||
var _texture = state.game.textures.get('__DEFAULT');
|
||||
var _frame = new Phaser.TextureFrame(_texture, 'pixel', 0, 0, 0, pixelSize, pixelSize);
|
||||
|
||||
Phaser.GameObject.call(this, state, x, y, _texture, _frame);
|
||||
|
||||
/**
|
||||
* @property {number} type - The const type of this object.
|
||||
* @readonly
|
||||
*/
|
||||
this.type = Phaser.PIXELFIELD;
|
||||
|
||||
this.list = [];
|
||||
|
||||
this.getColor32 = function (r, g, b, a)
|
||||
{
|
||||
a *= 255;
|
||||
|
||||
return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
Phaser.GameObject.PixelField.prototype = Object.create(Phaser.GameObject.prototype);
|
||||
Phaser.GameObject.PixelField.prototype.constructor = Phaser.GameObject.PixelField;
|
||||
|
||||
/**
|
||||
* Automatically called by World.preUpdate.
|
||||
*
|
||||
* @method Phaser.Image#preUpdate
|
||||
* @memberof Phaser.Image
|
||||
*/
|
||||
Phaser.GameObject.PixelField.prototype.preUpdate = function ()
|
||||
{
|
||||
if (this.parent)
|
||||
{
|
||||
this.color.worldAlpha = this.parent.color.worldAlpha;
|
||||
}
|
||||
};
|
||||
|
||||
// Ideas:
|
||||
//
|
||||
// Pixel velocity?
|
||||
// Pixel fade (alpha out) duration?
|
||||
// Kill pixel
|
||||
// Remove pixel
|
||||
|
||||
Phaser.GameObject.PixelField.prototype.add = function (x, y, r, g, b, a)
|
||||
{
|
||||
this.list.push({
|
||||
x: x,
|
||||
y: y,
|
||||
a: a,
|
||||
color: this.getColor32(r, g, b, a)
|
||||
});
|
||||
};
|
||||
|
||||
// Phaser.GameObject.Image.prototype.update = function ()
|
||||
// {
|
||||
// };
|
||||
|
||||
// Phaser.GameObject.Image.prototype.postUpdate = function ()
|
||||
// {
|
||||
// };
|
||||
|
||||
Object.defineProperties(Phaser.GameObject.PixelField.prototype, {
|
||||
|
||||
width: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleX * this.frame.realWidth;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.scaleX = value / this.frame.realWidth;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
height: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleY * this.frame.realHeight;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.scaleY = value / this.frame.realHeight;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -1,44 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.GameObject.PixelField.FACTORY_KEY = 'pixelField';
|
||||
|
||||
/**
|
||||
* Create a new `Image` object.
|
||||
*
|
||||
* An Image is a light-weight object you can use to display anything that doesn't need physics or animation.
|
||||
*
|
||||
* It can still rotate, scale, crop and receive input events.
|
||||
* This makes it perfect for logos, backgrounds, simple buttons and other non-Sprite graphics.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#image
|
||||
* @param {number} [x=0] - The x coordinate of the Image. The coordinate is relative to any parent container this Image may be in.
|
||||
* @param {number} [y=0] - The y coordinate of the Image. The coordinate is relative to any parent container this Image may be in.
|
||||
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
|
||||
* @return {Phaser.Image} The newly created Image object.
|
||||
*/
|
||||
Phaser.GameObject.PixelField.FACTORY_ADD = function (x, y, pixelSize, group)
|
||||
{
|
||||
if (group === undefined) { group = this.state; }
|
||||
|
||||
return group.children.add(new Phaser.GameObject.PixelField(this.state, x, y, pixelSize));
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new Image object.
|
||||
*
|
||||
* An Image is a light-weight object you can use to display anything that doesn't need physics or animation.
|
||||
* It can still rotate, scale, crop and receive input events. This makes it perfect for logos, backgrounds, simple buttons and other non-Sprite graphics.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#image
|
||||
* @param {number} x - X position of the image.
|
||||
* @param {number} y - Y position of the image.
|
||||
* @return {Phaser.Image} the newly created sprite object.
|
||||
*/
|
||||
Phaser.GameObject.PixelField.FACTORY_MAKE = function (x, y, pixelSize)
|
||||
{
|
||||
return new Phaser.GameObject.PixelField(this.state, x, y, pixelSize);
|
||||
};
|
|
@ -1,33 +0,0 @@
|
|||
Phaser.Renderer.WebGL.GameObjects.PixelField = {
|
||||
|
||||
TYPES: [
|
||||
Phaser.GameObject.PixelField.prototype
|
||||
],
|
||||
|
||||
render: function (renderer, src, interpolationPercentage)
|
||||
{
|
||||
var pixel;
|
||||
var verts = src.transform.getVertexData(interpolationPercentage);
|
||||
|
||||
for (var i = 0; i < src.list.length; i++)
|
||||
{
|
||||
pixel = src.list[i];
|
||||
|
||||
if (pixel.a > 0)
|
||||
{
|
||||
renderer.batch.addPixel(
|
||||
verts.x0 + pixel.x,
|
||||
verts.y0 + pixel.y,
|
||||
verts.x1 + pixel.x,
|
||||
verts.y1 + pixel.y,
|
||||
verts.x2 + pixel.x,
|
||||
verts.y2 + pixel.y,
|
||||
verts.x3 + pixel.x,
|
||||
verts.y3 + pixel.y,
|
||||
pixel.color
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
|
@ -1,604 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Retro Font is similar to a BitmapFont, in that it uses a texture to render the text. However unlike a BitmapFont every character in a RetroFont
|
||||
* is the same size. This makes it similar to a sprite sheet. You typically find font sheets like this from old 8/16-bit games and demos.
|
||||
*
|
||||
* @class Phaser.GameObject.RetroFont
|
||||
* @extends Phaser.RenderTexture
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - Current game instance.
|
||||
* @param {string} key - The font set graphic set as stored in the Game.Cache.
|
||||
* @param {number} characterWidth - The width of each character in the font set.
|
||||
* @param {number} characterHeight - The height of each character in the font set.
|
||||
* @param {string} chars - The characters used in the font set, in display order. You can use the TEXT_SET consts for common font set arrangements.
|
||||
* @param {number} [charsPerRow] - The number of characters per row in the font set. If not given charsPerRow will be the image width / characterWidth.
|
||||
* @param {number} [xSpacing=0] - If the characters in the font set have horizontal spacing between them set the required amount here.
|
||||
* @param {number} [ySpacing=0] - If the characters in the font set have vertical spacing between them set the required amount here.
|
||||
* @param {number} [xOffset=0] - If the font set doesn't start at the top left of the given image, specify the X coordinate offset here.
|
||||
* @param {number} [yOffset=0] - If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here.
|
||||
*/
|
||||
Phaser.GameObject.RetroFont = function (game, key, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset) {
|
||||
|
||||
if (!game.cache.checkImageKey(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (charsPerRow === undefined || charsPerRow === null)
|
||||
{
|
||||
charsPerRow = game.cache.getImage(key).width / characterWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {number} characterWidth - The width of each character in the font set.
|
||||
*/
|
||||
this.characterWidth = characterWidth;
|
||||
|
||||
/**
|
||||
* @property {number} characterHeight - The height of each character in the font set.
|
||||
*/
|
||||
this.characterHeight = characterHeight;
|
||||
|
||||
/**
|
||||
* @property {number} characterSpacingX - If the characters in the font set have horizontal spacing between them set the required amount here.
|
||||
*/
|
||||
this.characterSpacingX = xSpacing || 0;
|
||||
|
||||
/**
|
||||
* @property {number} characterSpacingY - If the characters in the font set have vertical spacing between them set the required amount here.
|
||||
*/
|
||||
this.characterSpacingY = ySpacing || 0;
|
||||
|
||||
/**
|
||||
* @property {number} characterPerRow - The number of characters per row in the font set.
|
||||
*/
|
||||
this.characterPerRow = charsPerRow;
|
||||
|
||||
/**
|
||||
* @property {number} offsetX - If the font set doesn't start at the top left of the given image, specify the X coordinate offset here.
|
||||
* @readonly
|
||||
*/
|
||||
this.offsetX = xOffset || 0;
|
||||
|
||||
/**
|
||||
* @property {number} offsetY - If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here.
|
||||
* @readonly
|
||||
*/
|
||||
this.offsetY = yOffset || 0;
|
||||
|
||||
/**
|
||||
* @property {string} align - Alignment of the text when multiLine = true or a fixedWidth is set. Set to RetroFont.ALIGN_LEFT (default), RetroFont.ALIGN_RIGHT or RetroFont.ALIGN_CENTER.
|
||||
*/
|
||||
this.align = "left";
|
||||
|
||||
/**
|
||||
* @property {boolean} multiLine - If set to true all carriage-returns in text will form new lines (see align). If false the font will only contain one single line of text (the default)
|
||||
* @default
|
||||
*/
|
||||
this.multiLine = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} autoUpperCase - Automatically convert any text to upper case. Lots of old bitmap fonts only contain upper-case characters, so the default is true.
|
||||
* @default
|
||||
*/
|
||||
this.autoUpperCase = true;
|
||||
|
||||
/**
|
||||
* @property {number} customSpacingX - Adds horizontal spacing between each character of the font, in pixels.
|
||||
* @default
|
||||
*/
|
||||
this.customSpacingX = 0;
|
||||
|
||||
/**
|
||||
* @property {number} customSpacingY - Adds vertical spacing between each line of multi-line text, set in pixels.
|
||||
* @default
|
||||
*/
|
||||
this.customSpacingY = 0;
|
||||
|
||||
/**
|
||||
* If you need this RetroFont image to have a fixed width you can set the width in this value.
|
||||
* If text is wider than the width specified it will be cropped off.
|
||||
* @property {number} fixedWidth
|
||||
*/
|
||||
this.fixedWidth = 0;
|
||||
|
||||
/**
|
||||
* @property {Image} fontSet - A reference to the image stored in the Game.Cache that contains the font.
|
||||
*/
|
||||
this.fontSet = game.cache.getImage(key);
|
||||
|
||||
/**
|
||||
* @property {string} _text - The text of the font image.
|
||||
* @private
|
||||
*/
|
||||
this._text = '';
|
||||
|
||||
/**
|
||||
* @property {array} grabData - An array of rects for faster character pasting.
|
||||
* @private
|
||||
*/
|
||||
this.grabData = [];
|
||||
|
||||
/**
|
||||
* @property {Phaser.FrameData} frameData - The FrameData representing this Retro Font.
|
||||
*/
|
||||
this.frameData = new Phaser.FrameData();
|
||||
|
||||
// Now generate our rects for faster copying later on
|
||||
var currentX = this.offsetX;
|
||||
var currentY = this.offsetY;
|
||||
var r = 0;
|
||||
|
||||
for (var c = 0; c < chars.length; c++)
|
||||
{
|
||||
var frame = this.frameData.addFrame(new Phaser.Frame(c, currentX, currentY, this.characterWidth, this.characterHeight));
|
||||
|
||||
this.grabData[chars.charCodeAt(c)] = frame.index;
|
||||
|
||||
r++;
|
||||
|
||||
if (r === this.characterPerRow)
|
||||
{
|
||||
r = 0;
|
||||
currentX = this.offsetX;
|
||||
currentY += this.characterHeight + this.characterSpacingY;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentX += this.characterWidth + this.characterSpacingX;
|
||||
}
|
||||
}
|
||||
|
||||
game.cache.updateFrameData(key, this.frameData);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Image} stamp - The image that is stamped to the RenderTexture for each character in the font.
|
||||
* @readonly
|
||||
*/
|
||||
this.stamp = new Phaser.Image(game, 0, 0, key, 0);
|
||||
|
||||
Phaser.RenderTexture.call(this, game, 100, 100, '', Phaser.scaleModes.NEAREST);
|
||||
|
||||
/**
|
||||
* @property {number} type - Base Phaser object type.
|
||||
*/
|
||||
this.type = Phaser.RETROFONT;
|
||||
|
||||
};
|
||||
|
||||
Phaser.GameObject.RetroFont.prototype = Object.create(Phaser.RenderTexture.prototype);
|
||||
Phaser.GameObject.RetroFont.prototype.constructor = Phaser.GameObject.RetroFont;
|
||||
|
||||
/**
|
||||
* Align each line of multi-line text to the left.
|
||||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.ALIGN_LEFT = "left";
|
||||
|
||||
/**
|
||||
* Align each line of multi-line text to the right.
|
||||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.ALIGN_RIGHT = "right";
|
||||
|
||||
/**
|
||||
* Align each line of multi-line text in the center.
|
||||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.ALIGN_CENTER = "center";
|
||||
|
||||
/**
|
||||
* Text Set 1 = !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
|
||||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.TEXT_SET1 = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
|
||||
|
||||
/**
|
||||
* Text Set 2 = !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.TEXT_SET2 = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
/**
|
||||
* Text Set 3 = ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
|
||||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.TEXT_SET3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
|
||||
|
||||
/**
|
||||
* Text Set 4 = ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789
|
||||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.TEXT_SET4 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789";
|
||||
|
||||
/**
|
||||
* Text Set 5 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() '!?-*:0123456789
|
||||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.TEXT_SET5 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() '!?-*:0123456789";
|
||||
|
||||
/**
|
||||
* Text Set 6 = ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789"(),-.'
|
||||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.TEXT_SET6 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789\"(),-.' ";
|
||||
|
||||
/**
|
||||
* Text Set 7 = AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW")28FLRX-'39
|
||||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.TEXT_SET7 = "AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW\")28FLRX-'39";
|
||||
|
||||
/**
|
||||
* Text Set 8 = 0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.TEXT_SET8 = "0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
/**
|
||||
* Text Set 9 = ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,'"?!
|
||||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.TEXT_SET9 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,'\"?!";
|
||||
|
||||
/**
|
||||
* Text Set 10 = ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.TEXT_SET10 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
/**
|
||||
* Text Set 11 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,"-+!?()':;0123456789
|
||||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.TEXT_SET11 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.,\"-+!?()':;0123456789";
|
||||
|
||||
/**
|
||||
* If you need this RetroFont to have a fixed width and custom alignment you can set the width here.
|
||||
* If text is wider than the width specified it will be cropped off.
|
||||
*
|
||||
* @method Phaser.GameObject.RetroFont#setFixedWidth
|
||||
* @memberof Phaser.GameObject.RetroFont
|
||||
* @param {number} width - Width in pixels of this RetroFont. Set to zero to disable and re-enable automatic resizing.
|
||||
* @param {string} [lineAlignment='left'] - Align the text within this width. Set to RetroFont.ALIGN_LEFT (default), RetroFont.ALIGN_RIGHT or RetroFont.ALIGN_CENTER.
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.prototype.setFixedWidth = function (width, lineAlignment) {
|
||||
|
||||
if (lineAlignment === undefined) { lineAlignment = 'left'; }
|
||||
|
||||
this.fixedWidth = width;
|
||||
this.align = lineAlignment;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* A helper function that quickly sets lots of variables at once, and then updates the text.
|
||||
*
|
||||
* @method Phaser.GameObject.RetroFont#setText
|
||||
* @memberof Phaser.GameObject.RetroFont
|
||||
* @param {string} content - The text of this sprite.
|
||||
* @param {boolean} [multiLine=false] - Set to true if you want to support carriage-returns in the text and create a multi-line sprite instead of a single line.
|
||||
* @param {number} [characterSpacing=0] - To add horizontal spacing between each character specify the amount in pixels.
|
||||
* @param {number} [lineSpacing=0] - To add vertical spacing between each line of text, set the amount in pixels.
|
||||
* @param {string} [lineAlignment='left'] - Align each line of multi-line text. Set to RetroFont.ALIGN_LEFT, RetroFont.ALIGN_RIGHT or RetroFont.ALIGN_CENTER.
|
||||
* @param {boolean} [allowLowerCase=false] - Lots of bitmap font sets only include upper-case characters, if yours needs to support lower case then set this to true.
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.prototype.setText = function (content, multiLine, characterSpacing, lineSpacing, lineAlignment, allowLowerCase) {
|
||||
|
||||
this.multiLine = multiLine || false;
|
||||
this.customSpacingX = characterSpacing || 0;
|
||||
this.customSpacingY = lineSpacing || 0;
|
||||
this.align = lineAlignment || 'left';
|
||||
|
||||
if (allowLowerCase)
|
||||
{
|
||||
this.autoUpperCase = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.autoUpperCase = true;
|
||||
}
|
||||
|
||||
if (content.length > 0)
|
||||
{
|
||||
this.text = content;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the texture with the new text.
|
||||
*
|
||||
* @method Phaser.GameObject.RetroFont#buildRetroFontText
|
||||
* @memberof Phaser.GameObject.RetroFont
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.prototype.buildRetroFontText = function () {
|
||||
|
||||
var cx = 0;
|
||||
var cy = 0;
|
||||
|
||||
// Clears the textureBuffer
|
||||
this.clear();
|
||||
|
||||
if (this.multiLine)
|
||||
{
|
||||
var lines = this._text.split("\n");
|
||||
|
||||
if (this.fixedWidth > 0)
|
||||
{
|
||||
this.resize(this.fixedWidth, (lines.length * (this.characterHeight + this.customSpacingY)) - this.customSpacingY, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.resize(this.getLongestLine() * (this.characterWidth + this.customSpacingX), (lines.length * (this.characterHeight + this.customSpacingY)) - this.customSpacingY, true);
|
||||
}
|
||||
|
||||
// Loop through each line of text
|
||||
for (var i = 0; i < lines.length; i++)
|
||||
{
|
||||
// Phaser.GameObject.RetroFont.ALIGN_LEFT
|
||||
cx = 0;
|
||||
|
||||
// This line of text is held in lines[i] - need to work out the alignment
|
||||
if (this.align === Phaser.GameObject.RetroFont.ALIGN_RIGHT)
|
||||
{
|
||||
cx = this.width - (lines[i].length * (this.characterWidth + this.customSpacingX));
|
||||
}
|
||||
else if (this.align === Phaser.GameObject.RetroFont.ALIGN_CENTER)
|
||||
{
|
||||
cx = (this.width / 2) - ((lines[i].length * (this.characterWidth + this.customSpacingX)) / 2);
|
||||
cx += this.customSpacingX / 2;
|
||||
}
|
||||
|
||||
// Sanity checks
|
||||
if (cx < 0)
|
||||
{
|
||||
cx = 0;
|
||||
}
|
||||
|
||||
this.pasteLine(lines[i], cx, cy, this.customSpacingX);
|
||||
|
||||
cy += this.characterHeight + this.customSpacingY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.fixedWidth > 0)
|
||||
{
|
||||
this.resize(this.fixedWidth, this.characterHeight, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.resize(this._text.length * (this.characterWidth + this.customSpacingX), this.characterHeight, true);
|
||||
}
|
||||
|
||||
// Phaser.GameObject.RetroFont.ALIGN_LEFT
|
||||
cx = 0;
|
||||
|
||||
if (this.align === Phaser.GameObject.RetroFont.ALIGN_RIGHT)
|
||||
{
|
||||
cx = this.width - (this._text.length * (this.characterWidth + this.customSpacingX));
|
||||
}
|
||||
else if (this.align === Phaser.GameObject.RetroFont.ALIGN_CENTER)
|
||||
{
|
||||
cx = (this.width / 2) - ((this._text.length * (this.characterWidth + this.customSpacingX)) / 2);
|
||||
cx += this.customSpacingX / 2;
|
||||
}
|
||||
|
||||
// Sanity checks
|
||||
if (cx < 0)
|
||||
{
|
||||
cx = 0;
|
||||
}
|
||||
|
||||
this.pasteLine(this._text, cx, 0, this.customSpacingX);
|
||||
}
|
||||
|
||||
this.requiresReTint = true;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Internal function that takes a single line of text (2nd parameter) and pastes it into the BitmapData at the given coordinates.
|
||||
* Used by getLine and getMultiLine
|
||||
*
|
||||
* @method Phaser.GameObject.RetroFont#pasteLine
|
||||
* @memberof Phaser.GameObject.RetroFont
|
||||
* @param {string} line - The single line of text to paste.
|
||||
* @param {number} x - The x coordinate.
|
||||
* @param {number} y - The y coordinate.
|
||||
* @param {number} customSpacingX - Custom X spacing.
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.prototype.pasteLine = function (line, x, y, customSpacingX) {
|
||||
|
||||
for (var c = 0; c < line.length; c++)
|
||||
{
|
||||
// If it's a space then there is no point copying, so leave a blank space
|
||||
if (line.charAt(c) === " ")
|
||||
{
|
||||
x += this.characterWidth + customSpacingX;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the character doesn't exist in the font then we don't want a blank space, we just want to skip it
|
||||
if (this.grabData[line.charCodeAt(c)] >= 0)
|
||||
{
|
||||
this.stamp.frame = this.grabData[line.charCodeAt(c)];
|
||||
this.renderXY(this.stamp, x, y, false);
|
||||
|
||||
x += this.characterWidth + customSpacingX;
|
||||
|
||||
if (x > this.width)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Works out the longest line of text in _text and returns its length
|
||||
*
|
||||
* @method Phaser.GameObject.RetroFont#getLongestLine
|
||||
* @memberof Phaser.GameObject.RetroFont
|
||||
* @return {number} The length of the longest line of text.
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.prototype.getLongestLine = function () {
|
||||
|
||||
var longestLine = 0;
|
||||
|
||||
if (this._text.length > 0)
|
||||
{
|
||||
var lines = this._text.split("\n");
|
||||
|
||||
for (var i = 0; i < lines.length; i++)
|
||||
{
|
||||
if (lines[i].length > longestLine)
|
||||
{
|
||||
longestLine = lines[i].length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return longestLine;
|
||||
};
|
||||
|
||||
/**
|
||||
* Internal helper function that removes all unsupported characters from the _text String, leaving only characters contained in the font set.
|
||||
*
|
||||
* @method Phaser.GameObject.RetroFont#removeUnsupportedCharacters
|
||||
* @memberof Phaser.GameObject.RetroFont
|
||||
* @protected
|
||||
* @param {boolean} [stripCR=true] - Should it strip carriage returns as well?
|
||||
* @return {string} A clean version of the string.
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.prototype.removeUnsupportedCharacters = function (stripCR) {
|
||||
|
||||
var newString = "";
|
||||
|
||||
for (var c = 0; c < this._text.length; c++)
|
||||
{
|
||||
var aChar = this._text[c];
|
||||
var code = aChar.charCodeAt(0);
|
||||
|
||||
if (this.grabData[code] >= 0 || (!stripCR && aChar === "\n"))
|
||||
{
|
||||
newString = newString.concat(aChar);
|
||||
}
|
||||
}
|
||||
|
||||
return newString;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the x and/or y offset that the font is rendered from. This updates all of the texture frames, so be careful how often it is called.
|
||||
* Note that the values given for the x and y properties are either ADDED to or SUBTRACTED from (if negative) the existing offsetX/Y values of the characters.
|
||||
* So if the current offsetY is 8 and you want it to start rendering from y16 you would call updateOffset(0, 8) to add 8 to the current y offset.
|
||||
*
|
||||
* @method Phaser.GameObject.RetroFont#updateOffset
|
||||
* @memberof Phaser.GameObject.RetroFont
|
||||
* @param {number} [xOffset=0] - If the font set doesn't start at the top left of the given image, specify the X coordinate offset here.
|
||||
* @param {number} [yOffset=0] - If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here.
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.prototype.updateOffset = function (x, y) {
|
||||
|
||||
if (this.offsetX === x && this.offsetY === y)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var diffX = x - this.offsetX;
|
||||
var diffY = y - this.offsetY;
|
||||
|
||||
var frames = this.game.cache.getFrameData(this.stamp.key).getFrames();
|
||||
var i = frames.length;
|
||||
|
||||
while (i--)
|
||||
{
|
||||
frames[i].x += diffX;
|
||||
frames[i].y += diffY;
|
||||
}
|
||||
|
||||
this.buildRetroFontText();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @name Phaser.GameObject.RetroFont#text
|
||||
* @property {string} text - Set this value to update the text in this sprite. Carriage returns are automatically stripped out if multiLine is false. Text is converted to upper case if autoUpperCase is true.
|
||||
*/
|
||||
Object.defineProperty(Phaser.GameObject.RetroFont.prototype, "text", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this._text;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
var newText;
|
||||
|
||||
if (this.autoUpperCase)
|
||||
{
|
||||
newText = value.toUpperCase();
|
||||
}
|
||||
else
|
||||
{
|
||||
newText = value;
|
||||
}
|
||||
|
||||
if (newText !== this._text)
|
||||
{
|
||||
this._text = newText;
|
||||
|
||||
this.removeUnsupportedCharacters(this.multiLine);
|
||||
|
||||
this.buildRetroFontText();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.GameObject.RetroFont#smoothed
|
||||
* @property {boolean} smoothed - Sets if the stamp is smoothed or not.
|
||||
*/
|
||||
Object.defineProperty(Phaser.GameObject.RetroFont.prototype, "smoothed", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.stamp.smoothed;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.stamp.smoothed = value;
|
||||
this.buildRetroFontText();
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -1,61 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.GameObject.RetroFont.FACTORY_KEY = 'retroFont';
|
||||
|
||||
/**
|
||||
* Create a new RetroFont object.
|
||||
*
|
||||
* A RetroFont can be used as a texture for an Image or Sprite and optionally add it to the Cache.
|
||||
* A RetroFont uses a bitmap which contains fixed with characters for the font set. You use character spacing to define the set.
|
||||
* If you need variable width character support then use a BitmapText object instead. The main difference between a RetroFont and a BitmapText
|
||||
* is that a RetroFont creates a single texture that you can apply to a game object, where-as a BitmapText creates one Sprite object per letter of text.
|
||||
* The texture can be asssigned or one or multiple images/sprites, but note that the text the RetroFont uses will be shared across them all,
|
||||
* i.e. if you need each Image to have different text in it, then you need to create multiple RetroFont objects.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#retroFont
|
||||
* @param {string} font - The key of the image in the Game.Cache that the RetroFont will use.
|
||||
* @param {number} characterWidth - The width of each character in the font set.
|
||||
* @param {number} characterHeight - The height of each character in the font set.
|
||||
* @param {string} chars - The characters used in the font set, in display order. You can use the TEXT_SET consts for common font set arrangements.
|
||||
* @param {number} charsPerRow - The number of characters per row in the font set.
|
||||
* @param {number} [xSpacing=0] - If the characters in the font set have horizontal spacing between them set the required amount here.
|
||||
* @param {number} [ySpacing=0] - If the characters in the font set have vertical spacing between them set the required amount here.
|
||||
* @param {number} [xOffset=0] - If the font set doesn't start at the top left of the given image, specify the X coordinate offset here.
|
||||
* @param {number} [yOffset=0] - If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here.
|
||||
* @return {Phaser.RetroFont} The newly created RetroFont texture which can be applied to an Image or Sprite.
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.FACTORY_ADD = function (font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset)
|
||||
{
|
||||
return new Phaser.GameObject.RetroFont(this.game, font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new RetroFont object.
|
||||
*
|
||||
* A RetroFont can be used as a texture for an Image or Sprite and optionally add it to the Cache.
|
||||
* A RetroFont uses a bitmap which contains fixed with characters for the font set. You use character spacing to define the set.
|
||||
* If you need variable width character support then use a BitmapText object instead. The main difference between a RetroFont and a BitmapText
|
||||
* is that a RetroFont creates a single texture that you can apply to a game object, where-as a BitmapText creates one Sprite object per letter of text.
|
||||
* The texture can be asssigned or one or multiple images/sprites, but note that the text the RetroFont uses will be shared across them all,
|
||||
* i.e. if you need each Image to have different text in it, then you need to create multiple RetroFont objects.
|
||||
*
|
||||
* @method Phaser.GameObjectCreator#retroFont
|
||||
* @param {string} font - The key of the image in the Game.Cache that the RetroFont will use.
|
||||
* @param {number} characterWidth - The width of each character in the font set.
|
||||
* @param {number} characterHeight - The height of each character in the font set.
|
||||
* @param {string} chars - The characters used in the font set, in display order. You can use the TEXT_SET consts for common font set arrangements.
|
||||
* @param {number} charsPerRow - The number of characters per row in the font set.
|
||||
* @param {number} [xSpacing=0] - If the characters in the font set have horizontal spacing between them set the required amount here.
|
||||
* @param {number} [ySpacing=0] - If the characters in the font set have vertical spacing between them set the required amount here.
|
||||
* @param {number} [xOffset=0] - If the font set doesn't start at the top left of the given image, specify the X coordinate offset here.
|
||||
* @param {number} [yOffset=0] - If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here.
|
||||
* @return {Phaser.RetroFont} The newly created RetroFont texture which can be applied to an Image or Sprite.
|
||||
*/
|
||||
Phaser.GameObject.RetroFont.FACTORY_MAKE = function (font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset)
|
||||
{
|
||||
return new Phaser.GameObject.RetroFont(this.game, font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset);
|
||||
};
|
|
@ -1,840 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @author Mat Groves (@Doormat23)
|
||||
* @author Rovanion Luckey
|
||||
* @copyright 2016 Photon Storm Ltd, Richard Davey
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Rope is a Sprite that has a repeating texture.
|
||||
*
|
||||
* The texture will automatically wrap on the edges as it moves.
|
||||
*
|
||||
* Please note that Ropes cannot have an input handler.
|
||||
*
|
||||
* @class Phaser.GameObject.Rope
|
||||
* @constructor
|
||||
* @extends PIXI.DisplayObjectContainer
|
||||
* @extends Phaser.Component.Core
|
||||
* @extends Phaser.Component.Angle
|
||||
* @extends Phaser.Component.Animation
|
||||
* @extends Phaser.Component.AutoCull
|
||||
* @extends Phaser.Component.Bounds
|
||||
* @extends Phaser.Component.BringToTop
|
||||
* @extends Phaser.Component.Crop
|
||||
* @extends Phaser.Component.Delta
|
||||
* @extends Phaser.Component.Destroy
|
||||
* @extends Phaser.Component.FixedToCamera
|
||||
* @extends Phaser.Component.InWorld
|
||||
* @extends Phaser.Component.LifeSpan
|
||||
* @extends Phaser.Component.LoadTexture
|
||||
* @extends Phaser.Component.Overlap
|
||||
* @extends Phaser.Component.PhysicsBody
|
||||
* @extends Phaser.Component.Reset
|
||||
* @extends Phaser.Component.ScaleMinMax
|
||||
* @extends Phaser.Component.Smoothed
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {number} x - The x coordinate (in world space) to position the Rope at.
|
||||
* @param {number} y - The y coordinate (in world space) to position the Rope at.
|
||||
* @param {string|Phaser.RenderTexture|Phaser.BitmapData|PIXI.Texture} key - This is the image or texture used by the Rope during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
|
||||
* @param {string|number} frame - If this Rope is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
|
||||
* @param {Array} points - An array of {Phaser.Point}.
|
||||
*/
|
||||
Phaser.GameObject.Rope = function (game, x, y, key, frame, points) {
|
||||
|
||||
this.points = [];
|
||||
this.points = points;
|
||||
this._hasUpdateAnimation = false;
|
||||
this._updateAnimationCallback = null;
|
||||
x = x || 0;
|
||||
y = y || 0;
|
||||
key = key || null;
|
||||
frame = frame || null;
|
||||
|
||||
/**
|
||||
* @property {number} type - The const type of this object.
|
||||
* @readonly
|
||||
*/
|
||||
this.type = Phaser.ROPE;
|
||||
|
||||
this.points = points;
|
||||
|
||||
PIXI.DisplayObjectContainer.call(this);
|
||||
|
||||
this.texture = Phaser.Cache.DEFAULT;
|
||||
|
||||
// set up the main bits..
|
||||
this.uvs = new Float32Array([0, 1,
|
||||
1, 1,
|
||||
1, 0,
|
||||
0, 1]);
|
||||
|
||||
this.vertices = new Float32Array([0, 0,
|
||||
100, 0,
|
||||
100, 100,
|
||||
0, 100]);
|
||||
|
||||
this.colors = new Float32Array([1, 1, 1, 1]);
|
||||
|
||||
this.indices = new Uint16Array([0, 1, 2, 3]);
|
||||
|
||||
if (points)
|
||||
{
|
||||
this.vertices = new Float32Array(points.length * 4);
|
||||
this.uvs = new Float32Array(points.length * 4);
|
||||
this.colors = new Float32Array(points.length * 2);
|
||||
this.indices = new Uint16Array(points.length * 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the strip is dirty or not
|
||||
*
|
||||
* @property dirty
|
||||
* @type Boolean
|
||||
*/
|
||||
this.dirty = true;
|
||||
|
||||
/**
|
||||
* Triangles in canvas mode are automatically antialiased, use this value to force triangles to overlap a bit with each other.
|
||||
*
|
||||
* @property canvasPadding
|
||||
* @type Number
|
||||
*/
|
||||
this.canvasPadding = 0;
|
||||
|
||||
this.drawMode = Phaser.GameObject.Rope.TRIANGLE_STRIP;
|
||||
|
||||
Phaser.Component.Core.init.call(this, game, x, y, key, frame);
|
||||
|
||||
this.refresh();
|
||||
|
||||
};
|
||||
|
||||
Phaser.GameObject.Rope.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
|
||||
Phaser.GameObject.Rope.prototype.constructor = Phaser.GameObject.Rope;
|
||||
|
||||
Phaser.Component.Core.install.call(Phaser.GameObject.Rope.prototype, [
|
||||
'Angle',
|
||||
'Animation',
|
||||
'AutoCull',
|
||||
'Bounds',
|
||||
'BringToTop',
|
||||
'Crop',
|
||||
'Delta',
|
||||
'Destroy',
|
||||
'FixedToCamera',
|
||||
'InWorld',
|
||||
'LifeSpan',
|
||||
'LoadTexture',
|
||||
'Overlap',
|
||||
'PhysicsBody',
|
||||
'Reset',
|
||||
'ScaleMinMax',
|
||||
'Smoothed'
|
||||
]);
|
||||
|
||||
Phaser.GameObject.Rope.prototype.preUpdatePhysics = Phaser.Component.PhysicsBody.preUpdate;
|
||||
Phaser.GameObject.Rope.prototype.preUpdateLifeSpan = Phaser.Component.LifeSpan.preUpdate;
|
||||
Phaser.GameObject.Rope.prototype.preUpdateInWorld = Phaser.Component.InWorld.preUpdate;
|
||||
Phaser.GameObject.Rope.prototype.preUpdateCore = Phaser.Component.Core.preUpdate;
|
||||
|
||||
Phaser.GameObject.Rope.TRIANGLE_STRIP = 0;
|
||||
Phaser.GameObject.Rope.TRIANGLES = 1;
|
||||
|
||||
/**
|
||||
* Automatically called by World.preUpdate.
|
||||
*
|
||||
* @method Phaser.GameObject.Rope#preUpdate
|
||||
* @memberof Phaser.GameObject.Rope
|
||||
*/
|
||||
Phaser.GameObject.Rope.prototype.preUpdate = function () {
|
||||
|
||||
if (!this.preUpdatePhysics() || !this.preUpdateLifeSpan() || !this.preUpdateInWorld())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.preUpdateCore();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Override and use this function in your own custom objects to handle any update requirements you may have.
|
||||
*
|
||||
* @method Phaser.GameObject.Rope#update
|
||||
* @memberof Phaser.GameObject.Rope
|
||||
*/
|
||||
Phaser.GameObject.Rope.prototype.update = function() {
|
||||
|
||||
if (this._hasUpdateAnimation)
|
||||
{
|
||||
this.updateAnimation.call(this);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Resets the Rope. This places the Rope at the given x/y world coordinates and then
|
||||
* sets alive, exists, visible and renderable all to true. Also resets the outOfBounds state.
|
||||
* If the Rope has a physics body that too is reset.
|
||||
*
|
||||
* @method Phaser.GameObject.Rope#reset
|
||||
* @memberof Phaser.GameObject.Rope
|
||||
* @param {number} x - The x coordinate (in world space) to position the Sprite at.
|
||||
* @param {number} y - The y coordinate (in world space) to position the Sprite at.
|
||||
* @return {Phaser.GameObject.Rope} This instance.
|
||||
*/
|
||||
Phaser.GameObject.Rope.prototype.reset = function (x, y) {
|
||||
|
||||
Phaser.Component.Reset.prototype.reset.call(this, x, y);
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Refreshes the rope texture and UV coordinates.
|
||||
*
|
||||
* @method Phaser.GameObject.Rope#refresh
|
||||
* @memberof Phaser.GameObject.Rope
|
||||
*/
|
||||
Phaser.GameObject.Rope.prototype.refresh = function () {
|
||||
|
||||
var points = this.points;
|
||||
|
||||
if (points.length < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var uvs = this.uvs;
|
||||
|
||||
var indices = this.indices;
|
||||
var colors = this.colors;
|
||||
|
||||
this.count -= 0.2;
|
||||
|
||||
uvs[0] = 0;
|
||||
uvs[1] = 0;
|
||||
uvs[2] = 0;
|
||||
uvs[3] = 1;
|
||||
|
||||
colors[0] = 1;
|
||||
colors[1] = 1;
|
||||
|
||||
indices[0] = 0;
|
||||
indices[1] = 1;
|
||||
|
||||
var total = points.length;
|
||||
var index;
|
||||
var amount;
|
||||
|
||||
for (var i = 1; i < total; i++)
|
||||
{
|
||||
index = i * 4;
|
||||
|
||||
// time to do some smart drawing!
|
||||
amount = i / (total - 1);
|
||||
|
||||
if (i % 2)
|
||||
{
|
||||
uvs[index] = amount;
|
||||
uvs[index + 1] = 0;
|
||||
|
||||
uvs[index + 2] = amount;
|
||||
uvs[index + 3] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
uvs[index] = amount;
|
||||
uvs[index + 1] = 0;
|
||||
|
||||
uvs[index + 2] = amount;
|
||||
uvs[index + 3] = 1;
|
||||
}
|
||||
|
||||
index = i * 2;
|
||||
colors[index] = 1;
|
||||
colors[index + 1] = 1;
|
||||
|
||||
index = i * 2;
|
||||
indices[index] = index;
|
||||
indices[index + 1] = index + 1;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Updates the Ropes transform ready for rendering.
|
||||
*
|
||||
* @method Phaser.GameObject.Rope#updateTransform
|
||||
* @memberof Phaser.GameObject.Rope
|
||||
*/
|
||||
Phaser.GameObject.Rope.prototype.updateTransform = function () {
|
||||
|
||||
var points = this.points;
|
||||
|
||||
if (points.length < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var lastPoint = points[0];
|
||||
var nextPoint;
|
||||
var perp = { x:0, y:0 };
|
||||
|
||||
this.count -= 0.2;
|
||||
|
||||
var vertices = this.vertices;
|
||||
var total = points.length;
|
||||
var point;
|
||||
var index;
|
||||
var ratio;
|
||||
var perpLength;
|
||||
var num;
|
||||
|
||||
for (var i = 0; i < total; i++)
|
||||
{
|
||||
point = points[i];
|
||||
index = i * 4;
|
||||
|
||||
if(i < points.length - 1)
|
||||
{
|
||||
nextPoint = points[i + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
nextPoint = point;
|
||||
}
|
||||
|
||||
perp.y = -(nextPoint.x - lastPoint.x);
|
||||
perp.x = nextPoint.y - lastPoint.y;
|
||||
|
||||
ratio = (1 - (i / (total - 1))) * 10;
|
||||
|
||||
if (ratio > 1)
|
||||
{
|
||||
ratio = 1;
|
||||
}
|
||||
|
||||
perpLength = Math.sqrt((perp.x * perp.x) + (perp.y * perp.y));
|
||||
num = this.texture.height / 2;
|
||||
perp.x /= perpLength;
|
||||
perp.y /= perpLength;
|
||||
|
||||
perp.x *= num;
|
||||
perp.y *= num;
|
||||
|
||||
vertices[index] = point.x + perp.x;
|
||||
vertices[index + 1] = point.y + perp.y;
|
||||
vertices[index + 2] = point.x - perp.x;
|
||||
vertices[index + 3] = point.y - perp.y;
|
||||
|
||||
lastPoint = point;
|
||||
}
|
||||
|
||||
PIXI.DisplayObjectContainer.prototype.updateTransform.call(this);
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Sets the Texture this Rope uses for rendering.
|
||||
*
|
||||
* @method Phaser.GameObject.Rope#setTexture
|
||||
* @memberof Phaser.GameObject.Rope
|
||||
* @param {Texture} texture - The texture that will be used.
|
||||
*/
|
||||
Phaser.GameObject.Rope.prototype.setTexture = function (texture) {
|
||||
|
||||
this.texture = texture;
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Renders the Rope to WebGL.
|
||||
*
|
||||
* @private
|
||||
* @method Phaser.GameObject.Rope#_renderWebGL
|
||||
* @memberof Phaser.GameObject.Rope
|
||||
*/
|
||||
Phaser.GameObject.Rope.prototype._renderWebGL = function (renderSession) {
|
||||
|
||||
if (!this.visible || this.alpha <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
renderSession.spriteBatch.stop();
|
||||
|
||||
if (!this._vertexBuffer)
|
||||
{
|
||||
this._initWebGL(renderSession);
|
||||
}
|
||||
|
||||
renderSession.shaderManager.setShader(renderSession.shaderManager.stripShader);
|
||||
|
||||
this._renderStrip(renderSession);
|
||||
|
||||
renderSession.spriteBatch.start();
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Builds the Strip.
|
||||
*
|
||||
* @private
|
||||
* @method Phaser.GameObject.Rope#_initWebGL
|
||||
* @memberof Phaser.GameObject.Rope
|
||||
*/
|
||||
Phaser.GameObject.Rope.prototype._initWebGL = function (renderSession) {
|
||||
|
||||
// build the strip!
|
||||
var gl = renderSession.gl;
|
||||
|
||||
this._vertexBuffer = gl.createBuffer();
|
||||
this._indexBuffer = gl.createBuffer();
|
||||
this._uvBuffer = gl.createBuffer();
|
||||
this._colorBuffer = gl.createBuffer();
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.vertices, gl.DYNAMIC_DRAW);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._uvBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.uvs, gl.STATIC_DRAW);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._colorBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.colors, gl.STATIC_DRAW);
|
||||
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW);
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Renders the Strip to WebGL.
|
||||
*
|
||||
* @private
|
||||
* @method Phaser.GameObject.Rope#_renderStrip
|
||||
* @memberof Phaser.GameObject.Rope
|
||||
*/
|
||||
Phaser.GameObject.Rope.prototype._renderStrip = function (renderSession) {
|
||||
|
||||
var gl = renderSession.gl;
|
||||
var projection = renderSession.projection;
|
||||
var offset = renderSession.offset;
|
||||
var shader = renderSession.shaderManager.stripShader;
|
||||
|
||||
var drawMode = (this.drawMode === Phaser.GameObject.Rope.TRIANGLE_STRIP) ? gl.TRIANGLE_STRIP : gl.TRIANGLES;
|
||||
|
||||
renderSession.blendModeManager.setBlendMode(this.blendMode);
|
||||
|
||||
// set uniforms
|
||||
gl.uniformMatrix3fv(shader.translationMatrix, false, this.worldTransform.toArray(true));
|
||||
gl.uniform2f(shader.projectionVector, projection.x, -projection.y);
|
||||
gl.uniform2f(shader.offsetVector, -offset.x, -offset.y);
|
||||
gl.uniform1f(shader.alpha, this.worldAlpha);
|
||||
|
||||
if (!this.dirty)
|
||||
{
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer);
|
||||
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.vertices);
|
||||
gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
// update the uvs
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._uvBuffer);
|
||||
gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
|
||||
// check if a texture is dirty..
|
||||
if (this.texture.baseTexture._dirty[gl.id])
|
||||
{
|
||||
renderSession.renderer.updateTexture(this.texture.baseTexture);
|
||||
}
|
||||
else
|
||||
{
|
||||
// bind the current texture
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures);
|
||||
}
|
||||
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dirty = false;
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.vertices, gl.STATIC_DRAW);
|
||||
gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
// update the uvs
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._uvBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.uvs, gl.STATIC_DRAW);
|
||||
gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
|
||||
// check if a texture is dirty..
|
||||
if (this.texture.baseTexture._dirty[gl.id])
|
||||
{
|
||||
renderSession.renderer.updateTexture(this.texture.baseTexture);
|
||||
}
|
||||
else
|
||||
{
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures);
|
||||
}
|
||||
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW);
|
||||
}
|
||||
|
||||
gl.drawElements(drawMode, this.indices.length, gl.UNSIGNED_SHORT, 0);
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Renders the Strip to Canvas.
|
||||
*
|
||||
* @private
|
||||
* @method Phaser.GameObject.Rope#_renderCanvas
|
||||
* @memberof Phaser.GameObject.Rope
|
||||
*/
|
||||
Phaser.GameObject.Rope.prototype._renderCanvas = function (renderSession) {
|
||||
|
||||
var context = renderSession.context;
|
||||
|
||||
var transform = this.worldTransform;
|
||||
|
||||
var tx = (transform.tx * renderSession.resolution) + renderSession.shakeX;
|
||||
var ty = (transform.ty * renderSession.resolution) + renderSession.shakeY;
|
||||
|
||||
if (renderSession.roundPixels)
|
||||
{
|
||||
context.setTransform(transform.a, transform.b, transform.c, transform.d, tx | 0, ty | 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.setTransform(transform.a, transform.b, transform.c, transform.d, tx, ty);
|
||||
}
|
||||
|
||||
if (this.drawMode === Phaser.GameObject.Rope.TRIANGLE_STRIP)
|
||||
{
|
||||
this._renderCanvasTriangleStrip(context);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._renderCanvasTriangles(context);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Renders a Triangle Strip to Canvas.
|
||||
*
|
||||
* @private
|
||||
* @method Phaser.GameObject.Rope#_renderCanvasTriangleStrip
|
||||
* @memberof Phaser.GameObject.Rope
|
||||
*/
|
||||
Phaser.GameObject.Rope.prototype._renderCanvasTriangleStrip = function (context) {
|
||||
|
||||
// draw triangles!!
|
||||
var vertices = this.vertices;
|
||||
var uvs = this.uvs;
|
||||
|
||||
var length = vertices.length / 2;
|
||||
|
||||
this.count++;
|
||||
|
||||
for (var i = 0; i < length - 2; i++)
|
||||
{
|
||||
var index = i * 2;
|
||||
this._renderCanvasDrawTriangle(context, vertices, uvs, index, (index + 2), (index + 4));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Renders a Triangle to Canvas.
|
||||
*
|
||||
* @private
|
||||
* @method Phaser.GameObject.Rope#_renderCanvasTriangles
|
||||
* @memberof Phaser.GameObject.Rope
|
||||
*/
|
||||
Phaser.GameObject.Rope.prototype._renderCanvasTriangles = function (context) {
|
||||
|
||||
var vertices = this.vertices;
|
||||
var uvs = this.uvs;
|
||||
var indices = this.indices;
|
||||
|
||||
var length = indices.length;
|
||||
|
||||
this.count++;
|
||||
|
||||
for (var i = 0; i < length; i += 3)
|
||||
{
|
||||
var index0 = indices[i] * 2;
|
||||
var index1 = indices[i + 1] * 2;
|
||||
var index2 = indices[i + 2] * 2;
|
||||
|
||||
this._renderCanvasDrawTriangle(context, vertices, uvs, index0, index1, index2);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Renders a Triangle to Canvas.
|
||||
*
|
||||
* @private
|
||||
* @method Phaser.GameObject.Rope#_renderCanvasDrawTriangle
|
||||
* @memberof Phaser.GameObject.Rope
|
||||
*/
|
||||
Phaser.GameObject.Rope.prototype._renderCanvasDrawTriangle = function (context, vertices, uvs, index0, index1, index2) {
|
||||
|
||||
var textureSource = this.texture.baseTexture.source;
|
||||
var textureWidth = this.texture.width;
|
||||
var textureHeight = this.texture.height;
|
||||
|
||||
var x0 = vertices[index0];
|
||||
var x1 = vertices[index1];
|
||||
var x2 = vertices[index2];
|
||||
var y0 = vertices[index0 + 1];
|
||||
var y1 = vertices[index1 + 1];
|
||||
var y2 = vertices[index2 + 1];
|
||||
|
||||
var u0 = uvs[index0] * textureWidth;
|
||||
var u1 = uvs[index1] * textureWidth;
|
||||
var u2 = uvs[index2] * textureWidth;
|
||||
var v0 = uvs[index0 + 1] * textureHeight;
|
||||
var v1 = uvs[index1 + 1] * textureHeight;
|
||||
var v2 = uvs[index2 + 1] * textureHeight;
|
||||
|
||||
if (this.canvasPadding > 0)
|
||||
{
|
||||
var paddingX = this.canvasPadding / this.worldTransform.a;
|
||||
var paddingY = this.canvasPadding / this.worldTransform.d;
|
||||
var centerX = (x0 + x1 + x2) / 3;
|
||||
var centerY = (y0 + y1 + y2) / 3;
|
||||
|
||||
var normX = x0 - centerX;
|
||||
var normY = y0 - centerY;
|
||||
|
||||
var dist = Math.sqrt((normX * normX) + (normY * normY));
|
||||
x0 = centerX + (normX / dist) * (dist + paddingX);
|
||||
y0 = centerY + (normY / dist) * (dist + paddingY);
|
||||
|
||||
normX = x1 - centerX;
|
||||
normY = y1 - centerY;
|
||||
|
||||
dist = Math.sqrt((normX * normX) + (normY * normY));
|
||||
x1 = centerX + (normX / dist) * (dist + paddingX);
|
||||
y1 = centerY + (normY / dist) * (dist + paddingY);
|
||||
|
||||
normX = x2 - centerX;
|
||||
normY = y2 - centerY;
|
||||
|
||||
dist = Math.sqrt((normX * normX) + (normY * normY));
|
||||
x2 = centerX + (normX / dist) * (dist + paddingX);
|
||||
y2 = centerY + (normY / dist) * (dist + paddingY);
|
||||
}
|
||||
|
||||
context.save();
|
||||
context.beginPath();
|
||||
|
||||
context.moveTo(x0, y0);
|
||||
context.lineTo(x1, y1);
|
||||
context.lineTo(x2, y2);
|
||||
|
||||
context.closePath();
|
||||
|
||||
context.clip();
|
||||
|
||||
// Compute matrix transform
|
||||
var delta = (u0 * v1) + (v0 * u2) + (u1 * v2) - (v1 * u2) - (v0 * u1) - (u0 * v2);
|
||||
var deltaA = (x0 * v1) + (v0 * x2) + (x1 * v2) - (v1 * x2) - (v0 * x1) - (x0 * v2);
|
||||
var deltaB = (u0 * x1) + (x0 * u2) + (u1 * x2) - (x1 * u2) - (x0 * u1) - (u0 * x2);
|
||||
var deltaC = (u0 * v1 * x2) + (v0 * x1 * u2) + (x0 * u1 * v2) - (x0 * v1 * u2) - (v0 * u1 * x2) - (u0 * x1 * v2);
|
||||
var deltaD = (y0 * v1) + (v0 * y2) + (y1 * v2) - (v1 * y2) - (v0 * y1) - (y0 * v2);
|
||||
var deltaE = (u0 * y1) + (y0 * u2) + (u1 * y2) - (y1 * u2) - (y0 * u1) - (u0 * y2);
|
||||
var deltaF = (u0 * v1 * y2) + (v0 * y1 * u2) + (y0 * u1 * v2) - (y0 * v1 * u2) - (v0 * u1 * y2) - (u0 * y1 * v2);
|
||||
|
||||
context.transform(
|
||||
deltaA / delta,
|
||||
deltaD / delta,
|
||||
deltaB / delta,
|
||||
deltaE / delta,
|
||||
deltaC / delta,
|
||||
deltaF / delta);
|
||||
|
||||
context.drawImage(textureSource, 0, 0);
|
||||
context.restore();
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Renders a flat strip.
|
||||
*
|
||||
* @method Phaser.GameObject.Rope#renderStripFlat
|
||||
* @memberof Phaser.GameObject.Rope
|
||||
*/
|
||||
Phaser.GameObject.Rope.prototype.renderStripFlat = function (strip) {
|
||||
|
||||
var context = this.context;
|
||||
var vertices = strip.vertices;
|
||||
|
||||
var length = vertices.length / 2;
|
||||
|
||||
this.count++;
|
||||
|
||||
context.beginPath();
|
||||
|
||||
for (var i = 1; i < length - 2; i++)
|
||||
{
|
||||
// draw some triangles!
|
||||
var index = i * 2;
|
||||
|
||||
var x0 = vertices[index];
|
||||
var x1 = vertices[index + 2];
|
||||
var x2 = vertices[index + 4];
|
||||
var y0 = vertices[index + 1];
|
||||
var y1 = vertices[index + 3];
|
||||
var y2 = vertices[index + 5];
|
||||
|
||||
context.moveTo(x0, y0);
|
||||
context.lineTo(x1, y1);
|
||||
context.lineTo(x2, y2);
|
||||
}
|
||||
|
||||
context.fillStyle = '#FF0000';
|
||||
context.fill();
|
||||
context.closePath();
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Returns the bounds of the mesh as a rectangle. The bounds calculation takes the worldTransform into account.
|
||||
*
|
||||
* @method Phaser.GameObject.Rope#getBounds
|
||||
* @memberof Phaser.GameObject.Rope
|
||||
* @param {Matrix} matrix - The transformation matrix of the Sprite.
|
||||
* @return {Rectangle} The framing rectangle.
|
||||
*/
|
||||
Phaser.GameObject.Rope.prototype.getBounds = function (matrix) {
|
||||
|
||||
var worldTransform = matrix || this.worldTransform;
|
||||
|
||||
var a = worldTransform.a;
|
||||
var b = worldTransform.b;
|
||||
var c = worldTransform.c;
|
||||
var d = worldTransform.d;
|
||||
var tx = worldTransform.tx;
|
||||
var ty = worldTransform.ty;
|
||||
|
||||
var maxX = -Infinity;
|
||||
var maxY = -Infinity;
|
||||
|
||||
var minX = Infinity;
|
||||
var minY = Infinity;
|
||||
|
||||
var vertices = this.vertices;
|
||||
|
||||
for (var i = 0; i < vertices.length; i += 2)
|
||||
{
|
||||
var rawX = vertices[i];
|
||||
var rawY = vertices[i + 1];
|
||||
var x = (a * rawX) + (c * rawY) + tx;
|
||||
var y = (d * rawY) + (b * rawX) + ty;
|
||||
|
||||
minX = x < minX ? x : minX;
|
||||
minY = y < minY ? y : minY;
|
||||
|
||||
maxX = x > maxX ? x : maxX;
|
||||
maxY = y > maxY ? y : maxY;
|
||||
}
|
||||
|
||||
if (minX === -Infinity || maxY === Infinity)
|
||||
{
|
||||
return Phaser.EmptyRectangle;
|
||||
}
|
||||
|
||||
var bounds = this._bounds;
|
||||
|
||||
bounds.x = minX;
|
||||
bounds.width = maxX - minX;
|
||||
|
||||
bounds.y = minY;
|
||||
bounds.height = maxY - minY;
|
||||
|
||||
// Store a reference so that if this function gets called again in the render cycle we do not have to recalculate
|
||||
this._currentBounds = bounds;
|
||||
|
||||
return bounds;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* A Rope will call its updateAnimation function on each update loop if it has one.
|
||||
*
|
||||
* @name Phaser.GameObject.Rope#updateAnimation
|
||||
* @property {function} updateAnimation - Set to a function if you'd like the rope to animate during the update phase. Set to false or null to remove it.
|
||||
*/
|
||||
Object.defineProperty(Phaser.GameObject.Rope.prototype, "updateAnimation", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this._updateAnimation;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value && typeof value === 'function')
|
||||
{
|
||||
this._hasUpdateAnimation = true;
|
||||
this._updateAnimation = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._hasUpdateAnimation = false;
|
||||
this._updateAnimation = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The segments that make up the rope body as an array of Phaser.Rectangles
|
||||
*
|
||||
* @name Phaser.GameObject.Rope#segments
|
||||
* @property {Phaser.Rectangles[]} updateAnimation - Returns an array of Phaser.Rectangles that represent the segments of the given rope
|
||||
*/
|
||||
Object.defineProperty(Phaser.GameObject.Rope.prototype, "segments", {
|
||||
|
||||
get: function () {
|
||||
|
||||
var segments = [];
|
||||
var index, x1, y1, x2, y2, width, height, rect;
|
||||
|
||||
for (var i = 0; i < this.points.length; i++)
|
||||
{
|
||||
index = i * 4;
|
||||
|
||||
x1 = this.vertices[index] * this.scale.x;
|
||||
y1 = this.vertices[index + 1] * this.scale.y;
|
||||
x2 = this.vertices[index + 4] * this.scale.x;
|
||||
y2 = this.vertices[index + 3] * this.scale.y;
|
||||
|
||||
width = Phaser.Math.difference(x1, x2);
|
||||
height = Phaser.Math.difference(y1, y2);
|
||||
|
||||
x1 += this.world.x;
|
||||
y1 += this.world.y;
|
||||
rect = new Phaser.Rectangle(x1, y1, width, height);
|
||||
segments.push(rect);
|
||||
}
|
||||
|
||||
return segments;
|
||||
}
|
||||
|
||||
});
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue