Skip to content

Commit 708567f

Browse files
committed
Merge branch 'develop'
2 parents 7dcaff0 + 472d6e3 commit 708567f

File tree

9 files changed

+120
-78
lines changed

9 files changed

+120
-78
lines changed

src/engine/audio.js

+1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ game.createClass('Audio', {
277277
request.open('GET', realPath, true);
278278
request.responseType = 'arraybuffer';
279279
request.onload = this._decode.bind(this, request, path, callback);
280+
request.onerror = this._error.bind(this, path, callback);
280281
request.send();
281282
}
282283
},

src/engine/core.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ var game = {
9999
Engine version.
100100
@property {String} version
101101
**/
102-
version: '2.12.0',
102+
version: '2.13.0',
103103
/**
104104
@property {Boolean} _booted
105105
@private
@@ -199,12 +199,14 @@ var game = {
199199
@method addAsset
200200
@param {String} filename
201201
@param {String} [id]
202+
@param {Boolean} [noCache] Force to not load file from cache
202203
**/
203-
addAsset: function(filename, id) {
204+
addAsset: function(filename, id, noCache) {
204205
if (!filename) throw 'addAsset: filename undefined';
205206
if (id && this.paths[id]) return;
206207
if (this.paths[filename]) return;
207208
var realPath = this._getFilePath(filename);
209+
if (id && noCache) realPath += '?' + Date.now();
208210
if (id) this.paths[id] = realPath;
209211
this.paths[filename] = realPath;
210212
if (this.mediaQueue.indexOf(realPath) === -1) this.mediaQueue.push(realPath);
@@ -398,7 +400,7 @@ var game = {
398400
var ext = from[key];
399401
if (
400402
typeof ext !== 'object' ||
401-
ext instanceof HTMLElement ||
403+
(typeof document !== 'undefined' && ext instanceof HTMLElement) ||
402404
ext instanceof this.Class ||
403405
ext instanceof this.Container
404406
) {
@@ -799,6 +801,9 @@ var game = {
799801
this.device.facebook = /FB/i.test(navigator.userAgent);
800802
this.device.panda2 = /Panda2/i.test(navigator.userAgent);
801803
this.device.electron = (!this.device.panda2 && /Electron/i.test(navigator.userAgent));
804+
this.device.chrome = /Chrome/i.test(navigator.userAgent);
805+
var chromeVer = navigator.userAgent.match(/Chrome\/([\d.]+)/);
806+
this.device.chromeVer = chromeVer ? parseInt(chromeVer[1]) : 0;
802807

803808
this.device.mobile = this.device.iOS || this.device.android || this.device.wp || this.device.wt;
804809
if (this.device.androidTV) this.device.mobile = false;
@@ -1037,7 +1042,10 @@ var game = {
10371042
}
10381043
}
10391044

1040-
if (typeof document === 'undefined') return;
1045+
if (typeof document === 'undefined') {
1046+
this.onReady();
1047+
return;
1048+
}
10411049
this._logoSource = document.createElement('img');
10421050
this._logoSource.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAA8BAMAAABfg2ObAAAALVBMVEUAAAD4uABHR0f4uABHR0f4uAD4uABHR0dHR0dHR0f4uABHR0f4uABHR0f4uADOcJEWAAAADXRSTlMAqqpV6UQkUMmUdBvjKrIhowAAAH1JREFUSMdjKLmLB7gz4Ae++DRfIaD5Ll4wqnlU8xDQzCqIDKRI05z3DgUsIEmzHapmgVHNo5qpovkGInkS1uykhApmo2cMGTyaFRgIAMZRzaOaRzUPJs2sEM0BZGlmSDYGAjMG0jUjwKjmUc2jmontlE0gUXMJckNgA2l6ASc7KJOPBNRIAAAAAElFTkSuQmCC';
10431051
this._logoSource.onload = this._readyLogo.bind(this);

src/engine/input.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ game.createClass('Input', {
168168
window.focus();
169169
game.renderer.canvas.focus();
170170
}
171-
if (!game.scene) return;
171+
if (!game.scene || game.system.paused) return;
172172

173173
this._preventDefault(input.event);
174174
this._calculateXY(input);
@@ -186,7 +186,7 @@ game.createClass('Input', {
186186
@private
187187
**/
188188
_inputmove: function(input) {
189-
if (!game.scene) return;
189+
if (!game.scene || game.system.paused) return;
190190

191191
this._preventDefault(input.event);
192192
this._calculateXY(input);
@@ -213,7 +213,7 @@ game.createClass('Input', {
213213
@private
214214
**/
215215
_inputup: function(input) {
216-
if (!game.scene) return;
216+
if (!game.scene || game.system.paused) return;
217217

218218
this._preventDefault(input.event);
219219
this._calculateXY(input);
@@ -267,7 +267,7 @@ game.createClass('Input', {
267267
@private
268268
**/
269269
_mouseout: function(event) {
270-
if (!game.scene) return;
270+
if (!game.scene || game.system.paused) return;
271271

272272
var input = this._mouseInput;
273273
input.event = event;

src/engine/physics.js

+56-47
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,18 @@ game.createClass('Body', {
8787
@private
8888
**/
8989
_collisionGroup: 0,
90-
91-
init: function(properties) {
90+
91+
staticInit: function() {
9292
this.force = new game.Vector();
9393
this.position = new game.Vector();
9494
this.velocity = new game.Vector();
9595
this.velocityLimit = new game.Vector(980, 980);
9696
this.last = new game.Vector();
97+
},
98+
99+
init: function(properties) {
97100
game.merge(this, properties);
101+
return true;
98102
},
99103

100104
/**
@@ -172,21 +176,25 @@ game.createClass('Body', {
172176
},
173177

174178
/**
175-
@method _update
176-
@private
179+
Update body position and velocity.
180+
@method update
181+
@param {Number} [delta]
177182
**/
178-
_update: function() {
183+
update: function(delta) {
184+
delta = delta || game.delta;
179185
this.last.copy(this.position);
180186

181187
if (this.static) return;
182-
183-
this.velocity.x += this.world.gravity.x * this.mass * game.delta;
184-
this.velocity.y += this.world.gravity.y * this.mass * game.delta;
185-
this.velocity.x += this.force.x * game.delta;
186-
this.velocity.y += this.force.y * game.delta;
188+
189+
if (this.world) {
190+
this.velocity.x += this.world.gravity.x * this.mass * delta;
191+
this.velocity.y += this.world.gravity.y * this.mass * delta;
192+
}
193+
this.velocity.x += this.force.x * delta;
194+
this.velocity.y += this.force.y * delta;
187195

188196
if (this.damping > 0 && this.damping < 1) {
189-
var damping = Math.pow(1 - this.damping, game.delta);
197+
var damping = Math.pow(1 - this.damping, delta);
190198
this.velocity.x *= damping;
191199
this.velocity.y *= damping;
192200
}
@@ -200,8 +208,8 @@ game.createClass('Body', {
200208
if (this.velocity.y < -this.velocityLimit.y) this.velocity.y = -this.velocityLimit.y;
201209
}
202210

203-
this.position.x += this.velocity.x * game.delta;
204-
this.position.y += this.velocity.y * game.delta;
211+
this.position.x += this.velocity.x * delta;
212+
this.position.y += this.velocity.y * delta;
205213
}
206214
});
207215

@@ -232,6 +240,7 @@ game.defineProperties('Body', {
232240
@constructor
233241
@param {Number} [x] Gravity x
234242
@param {Number} [y] Gravity y
243+
@param {Boolean} [manualUpdate] Don't update physics automatically
235244
**/
236245
game.createClass('Physics', {
237246
/**
@@ -251,11 +260,11 @@ game.createClass('Physics', {
251260
**/
252261
_collisionGroups: {},
253262

254-
staticInit: function(x, y) {
263+
staticInit: function(x, y, manualUpdate) {
255264
x = typeof x === 'number' ? x : 0;
256265
y = typeof y === 'number' ? y : 980;
257266
this.gravity = new game.Vector(x, y);
258-
if (game.scene) game.scene.physics.push(this);
267+
if (game.scene && !manualUpdate) game.scene.physics.push(this);
259268
},
260269

261270
/**
@@ -270,6 +279,37 @@ game.createClass('Physics', {
270279
this._addBodyCollision(body);
271280
},
272281

282+
/**
283+
Perform collision for body.
284+
@method collide
285+
@param {Body} body
286+
**/
287+
collide: function(body) {
288+
var g, i, b, group;
289+
290+
for (g = 0; g < body.collideAgainst.length; g++) {
291+
body._collides.length = 0;
292+
group = this._collisionGroups[body.collideAgainst[g]];
293+
294+
if (!group) continue;
295+
296+
for (i = group.length - 1; i >= 0; i--) {
297+
if (!group) break;
298+
b = group[i];
299+
if (body !== b) {
300+
if (this.hitTest(body, b)) {
301+
body._collides.push(b);
302+
}
303+
}
304+
}
305+
for (i = body._collides.length - 1; i >= 0; i--) {
306+
if (this.hitResponse(body, body._collides[i])) {
307+
body.afterCollide(body._collides[i]);
308+
}
309+
}
310+
}
311+
},
312+
273313
/**
274314
Hit response a versus b.
275315
@method hitResponse
@@ -379,37 +419,6 @@ game.createClass('Physics', {
379419
this._collisionGroups[body.collisionGroup].push(body);
380420
},
381421

382-
/**
383-
@method _collide
384-
@param {Body} body
385-
@private
386-
**/
387-
_collide: function(body) {
388-
var g, i, b, group;
389-
390-
for (g = 0; g < body.collideAgainst.length; g++) {
391-
body._collides.length = 0;
392-
group = this._collisionGroups[body.collideAgainst[g]];
393-
394-
if (!group) continue;
395-
396-
for (i = group.length - 1; i >= 0; i--) {
397-
if (!group) break;
398-
b = group[i];
399-
if (body !== b) {
400-
if (this.hitTest(body, b)) {
401-
body._collides.push(b);
402-
}
403-
}
404-
}
405-
for (i = body._collides.length - 1; i >= 0; i--) {
406-
if (this.hitResponse(body, body._collides[i])) {
407-
body.afterCollide(body._collides[i]);
408-
}
409-
}
410-
}
411-
},
412-
413422
/**
414423
@method _removeBodyCollision
415424
@param {Body} body
@@ -434,7 +443,7 @@ game.createClass('Physics', {
434443
this.bodies.splice(i, 1);
435444
}
436445
else {
437-
this.bodies[i]._update();
446+
this.bodies[i].update();
438447
}
439448
}
440449
},

src/engine/renderer/animation.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ game.createClass('Animation', 'Sprite', {
107107
Add new animation.
108108
@method addAnim
109109
@param {String} name Name of animation.
110-
@param {Array|Number|String} frames List of invidual frame indexes or start frame index or name that each frame starts with.
110+
@param {Array|Number|String} frames List of invidual frame indexes | List of frame names | Start frame index | Name that each frame starts with.
111111
@param {Number|Object} [frameCount] Number of frames or animation properties.
112112
@param {Object} [props] Animation properties.
113113
@chainable
@@ -127,7 +127,11 @@ game.createClass('Animation', 'Sprite', {
127127
}
128128
else if (frames.length) {
129129
for (var i = 0; i < frames.length; i++) {
130-
textures[i] = this.textures[frames[i]];
130+
if (typeof frames[i] === 'number') textures[i] = this.textures[frames[i]];
131+
else if (typeof frames[i] === 'string') {
132+
var index = this.textures.indexOf(frames[i]);
133+
if (index !== -1) textures[i] = this.textures[index];
134+
}
131135
}
132136
}
133137
else if (typeof frames === 'number' && typeof frameCount === 'number') {

src/engine/renderer/container.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ game.createClass('Container', {
585585
var context = game.Container._context;
586586
var bounds = this._getBounds();
587587

588+
if (bounds.width === 0 || bounds.height === 0) return;
589+
588590
canvas.width = (bounds.width / this.scale.x) * game.scale;
589591
canvas.height = (bounds.height / this.scale.y) * game.scale;
590592

@@ -593,8 +595,10 @@ game.createClass('Container', {
593595

594596
this._renderCanvas(context);
595597
this._renderChildren(context);
596-
597-
var texture = game.Texture.fromCanvas(canvas);
598+
599+
var texture = game.Texture.fromImage(canvas.toDataURL());
600+
texture.width = canvas.width;
601+
texture.height = canvas.height;
598602
var sprite = new game.Sprite(texture);
599603
sprite._parent = this;
600604

@@ -791,8 +795,10 @@ game.addAttributes('Container', {
791795
_context: null
792796
});
793797

794-
game.Container._canvas = document.createElement('canvas');
795-
game.Container._context = game.Container._canvas.getContext('2d');
798+
if (typeof document !== 'undefined') {
799+
game.Container._canvas = document.createElement('canvas');
800+
game.Container._context = game.Container._canvas.getContext('2d');
801+
}
796802

797803
game.defineProperties('Container', {
798804
/**

src/engine/renderer/sprite.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ game.addAttributes('Sprite', {
306306
}
307307
});
308308

309-
game.Sprite._canvas = document.createElement('canvas');
310-
game.Sprite._context = game.Sprite._canvas.getContext('2d');
309+
if (typeof document !== 'undefined') {
310+
game.Sprite._canvas = document.createElement('canvas');
311+
game.Sprite._context = game.Sprite._canvas.getContext('2d');
312+
}
311313

312314
});

src/engine/renderer/tilingsprite.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ game.createClass('TilingSprite', 'Container', {
101101
}
102102
}
103103

104-
var texture = game.Texture.fromCanvas(canvas);
104+
var texture = game.Texture.fromImage(canvas.toDataURL());
105+
texture.width = canvas.width;
106+
texture.height = canvas.height;
105107
this.tw = texture.width;
106108
this.th = texture.height;
107109
game.TilingSprite.cache[this.texture.baseTexture._id] = texture;
@@ -175,8 +177,8 @@ game.createClass('TilingSprite', 'Container', {
175177

176178
var scaleX = this._worldTransform.a / this._cosCache;
177179
var scaleY = this._worldTransform.d / this._cosCache;
178-
var tw = this.tw * game.scale;
179-
var th = this.th * game.scale;
180+
var tw = this.tw;
181+
var th = this.th;
180182
var width = this.width / scaleX * game.scale;
181183
var height = this.height / scaleY * game.scale;
182184
var tileX = this.tilePosition.x * game.scale;
@@ -273,8 +275,10 @@ game.addAttributes('TilingSprite', {
273275
}
274276
});
275277

276-
game.TilingSprite._canvas = document.createElement('canvas');
277-
game.TilingSprite._context = game.TilingSprite._canvas.getContext('2d');
278+
if (typeof document !== 'undefined') {
279+
game.TilingSprite._canvas = document.createElement('canvas');
280+
game.TilingSprite._context = game.TilingSprite._canvas.getContext('2d');
281+
}
278282

279283
game.defineProperties('TilingSprite', {
280284
width: {

0 commit comments

Comments
 (0)