Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ekelokorpi committed Jan 9, 2019
2 parents eb65a7e + fd76ee6 commit 7dcaff0
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/engine/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ var game = {
Engine version.
@property {String} version
**/
version: '2.11.0',
version: '2.12.0',
/**
@property {Boolean} _booted
@private
Expand Down
130 changes: 130 additions & 0 deletions src/engine/geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 33 additions & 2 deletions src/engine/renderer/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/engine/renderer/sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
7 changes: 5 additions & 2 deletions src/engine/tween.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7dcaff0

Please sign in to comment.