From e1b57d37833224f27a61eed24f341ee2ee75903d Mon Sep 17 00:00:00 2001 From: Eemeli Kelokorpi Date: Sat, 5 Jan 2019 12:37:56 +0200 Subject: [PATCH 1/6] Updated version number --- src/engine/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/core.js b/src/engine/core.js index a24b358c..c1618b12 100644 --- a/src/engine/core.js +++ b/src/engine/core.js @@ -99,7 +99,7 @@ var game = { Engine version. @property {String} version **/ - version: '2.11.0', + version: '2.11.1dev', /** @property {Boolean} _booted @private From 0d9e42543b3d0f3e5ef7ccf55d6260f94ff43aa9 Mon Sep 17 00:00:00 2001 From: Eemeli Kelokorpi Date: Sat, 5 Jan 2019 12:38:47 +0200 Subject: [PATCH 2/6] Fixed tinting when using it on multiple sprites with same texture --- src/engine/renderer/sprite.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/engine/renderer/sprite.js b/src/engine/renderer/sprite.js index c9956e55..aee0905b 100644 --- a/src/engine/renderer/sprite.js +++ b/src/engine/renderer/sprite.js @@ -116,7 +116,9 @@ game.createClass('Sprite', 'Container', { this._worldAlpha = alpha; this.blendMode = blendMode; - var texture = game.Texture.fromCanvas(canvas); + var texture = game.Texture.fromImage(canvas.toDataURL()); + texture.width = canvas.width; + texture.height = canvas.height; game.Sprite._tintedTextures.push(texture); return texture; }, From df3f0128a94ea151e7b5b0a5d5383e7c954a8e18 Mon Sep 17 00:00:00 2001 From: Eemeli Kelokorpi Date: Tue, 8 Jan 2019 19:55:50 +0200 Subject: [PATCH 3/6] Added error message if tween easing function not found --- src/engine/tween.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/engine/tween.js b/src/engine/tween.js index 0b730126..36b18456 100644 --- a/src/engine/tween.js +++ b/src/engine/tween.js @@ -187,8 +187,11 @@ game.createClass('Tween', { **/ easing: function(easing) { if (typeof easing === 'string') { - easing = easing.split('.'); - this.easingFunction = game.Tween.Easing[easing[0]][easing[1]]; + var names = easing.split('.'); + if (!game.Tween.Easing[names[0]]) throw 'Easing ' + easing + ' not found'; + var easingFunc = game.Tween.Easing[names[0]][names[1]]; + if (!easingFunc) throw 'Easing ' + easing + ' not found'; + this.easingFunction = easingFunc; } else { this.easingFunction = easing; From bb526e0798180cc1ff40ddde6e4fcec34f00cbcf Mon Sep 17 00:00:00 2001 From: Eemeli Kelokorpi Date: Tue, 8 Jan 2019 19:56:16 +0200 Subject: [PATCH 4/6] Added new Curve class to geometry --- src/engine/geometry.js | 130 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/src/engine/geometry.js b/src/engine/geometry.js index 32147ac1..300392c2 100644 --- a/src/engine/geometry.js +++ b/src/engine/geometry.js @@ -84,6 +84,136 @@ game.createClass('Circle', { } }); +/** + @class Curve + @constructor + @param {Number} sx + @param {Number} sy + @param {Number} ex + @param {Number} ey + @param {Number} h1x + @param {Number} h1y + @param {Number} h2x + @param {Number} h2y +**/ +game.createClass('Curve', { + /** + End position of curve. + @property {Vector} end + **/ + end: null, + /** + Position of first control point. + @property {Vector} handle1 + **/ + handle1: null, + /** + Position of second control point. + @property {Vector} handle2 + **/ + handle2: null, + /** + Start position of curve. + @property {Vector} start + **/ + start: null, + + staticInit: function(sx, sy, ex, ey, h1x, h1y, h2x, h2y) { + this.start = new game.Vector(sx, sy); + if (typeof ex !== 'number') ex = sx; + if (typeof ey !== 'number') ey = sy; + this.end = new game.Vector(ex, ey); + if (typeof h1x !== 'number') h1x = sx; + if (typeof h1y !== 'number') h1y = sy; + if (typeof h2x !== 'number') h2x = ex; + if (typeof h2y !== 'number') h2y = ey; + this.handle1 = new game.Vector(h1x, h1y); + this.handle2 = new game.Vector(h2x, h2y); + }, + + /** + Get point from curve. + @method point + @param {Number} percent Location of the point. 0 is start and 1 is the end of the curve. + @param {Vector} [out] Optional vector, where the values are set. + @return {Vector} + **/ + point: function(percent, out) { + out = out || new game.Vector(); + + var x = this._interpolate(percent, this.start.x, this.handle1.x, this.handle2.x, this.end.x); + var y = this._interpolate(percent, this.start.y, this.handle1.y, this.handle2.y, this.end.y); + + out.set(x, y); + return out; + }, + + /** + @method _calcHandle1 + @param {Number} t + @param {Number} p + @return {Number} + @private + **/ + _calcHandle1: function(t, p) { + var k = 1 - t; + return 3 * k * k * t * p; + }, + + /** + @method _calcHandle2 + @param {Number} t + @param {Number} p + @return {Number} + @private + **/ + _calcHandle2: function(t, p) { + return 3 * (1 - t) * t * t * p; + }, + + /** + @method _calcEnd + @param {Number} t + @param {Number} p + @return {Number} + @private + **/ + _calcEnd: function(t, p) { + return t * t * t * p; + }, + + /** + @method _calcStart + @param {Number} t + @param {Number} p + @return {Number} + @private + **/ + _calcStart: function(t, p) { + var k = 1 - t; + return k * k * k * p; + }, + + /** + Get point from curve. + @method _interpolate + @param {Number} percent + @param {Number} s + @param {Number} h1 + @param {Number} h2 + @param {Number} e + @return {Number} + @private + **/ + _interpolate: function(percent, s, h1, h2, e) { + s = this._calcStart(percent, s); + h1 = this._calcHandle1(percent, h1); + h2 = this._calcHandle2(percent, h2); + e = this._calcEnd(percent, e); + return s + h1 + h2 + e; + } +}); + /** @class Polygon @constructor From 6f5c14b70e0cdc75645ab3df13fec28d7c12ff1b Mon Sep 17 00:00:00 2001 From: Eemeli Kelokorpi Date: Tue, 8 Jan 2019 19:57:04 +0200 Subject: [PATCH 5/6] Added drawCurve method to Graphics --- src/engine/renderer/graphics.js | 35 +++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/engine/renderer/graphics.js b/src/engine/renderer/graphics.js index 22d8fec8..9794e744 100644 --- a/src/engine/renderer/graphics.js +++ b/src/engine/renderer/graphics.js @@ -99,6 +99,26 @@ game.createClass('Graphics', 'Container', { this._drawShape(shape); return this; }, + + /** + Draw bezier curve. + @method drawCurve + @param {Curve|Number} sx + @param {Number} sy + @param {Number} ex + @param {Number} ey + @param {Number} h1x + @param {Number} h1y + @param {Number} h2x + @param {Number} h2y + @chainable + **/ + drawCurve: function(sx, sy, ex, ey, h1x, h1y, h2x, h2y) { + this.lineWidth = this.lineWidth || 1; + var shape = typeof sx === 'number' ? new game.Curve(sx, sy, ex, ey, h1x, h1y, h2x, h2y) : sx; + this._drawShape(shape, true); + return this; + }, /** @method drawLine @@ -325,7 +345,7 @@ game.createClass('GraphicsShape', { this._renderShape(context); - if (this.fillColor && this.fillAlpha) context.fill(); + if (this.fillColor && this.fillAlpha && !this.isLine) context.fill(); if (this.lineWidth) { context.globalAlpha = this.lineAlpha * alpha; context.stroke(); @@ -342,7 +362,18 @@ game.createClass('GraphicsShape', { var x = shape.x * game.scale; var y = shape.y * game.scale; - if (this.isLine) { + if (this.isLine && shape.start) { + context.moveTo(shape.start.x * game.scale, shape.start.y * game.scale); + context.bezierCurveTo( + shape.handle1.x * game.scale, + shape.handle1.y * game.scale, + shape.handle2.x * game.scale, + shape.handle2.y * game.scale, + shape.end.x * game.scale, + shape.end.y * game.scale + ); + } + else if (this.isLine) { context.moveTo(x, y); context.lineTo(shape.width, shape.height); } From fd76ee6a2a7d24d38f9558efb05a3a687a5a6855 Mon Sep 17 00:00:00 2001 From: Eemeli Kelokorpi Date: Wed, 9 Jan 2019 19:53:29 +0200 Subject: [PATCH 6/6] Updated version number --- src/engine/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/core.js b/src/engine/core.js index c1618b12..d05a6a1f 100644 --- a/src/engine/core.js +++ b/src/engine/core.js @@ -99,7 +99,7 @@ var game = { Engine version. @property {String} version **/ - version: '2.11.1dev', + version: '2.12.0', /** @property {Boolean} _booted @private