Skip to content

Commit 7dcaff0

Browse files
committed
Merge branch 'develop'
2 parents eb65a7e + fd76ee6 commit 7dcaff0

File tree

5 files changed

+172
-6
lines changed

5 files changed

+172
-6
lines changed

src/engine/core.js

+1-1
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.11.0',
102+
version: '2.12.0',
103103
/**
104104
@property {Boolean} _booted
105105
@private

src/engine/geometry.js

+130
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,136 @@ game.createClass('Circle', {
8484
}
8585
});
8686

87+
/**
88+
@class Curve
89+
@constructor
90+
@param {Number} sx
91+
@param {Number} sy
92+
@param {Number} ex
93+
@param {Number} ey
94+
@param {Number} h1x
95+
@param {Number} h1y
96+
@param {Number} h2x
97+
@param {Number} h2y
98+
**/
99+
game.createClass('Curve', {
100+
/**
101+
End position of curve.
102+
@property {Vector} end
103+
**/
104+
end: null,
105+
/**
106+
Position of first control point.
107+
@property {Vector} handle1
108+
**/
109+
handle1: null,
110+
/**
111+
Position of second control point.
112+
@property {Vector} handle2
113+
**/
114+
handle2: null,
115+
/**
116+
Start position of curve.
117+
@property {Vector} start
118+
**/
119+
start: null,
120+
121+
staticInit: function(sx, sy, ex, ey, h1x, h1y, h2x, h2y) {
122+
this.start = new game.Vector(sx, sy);
123+
if (typeof ex !== 'number') ex = sx;
124+
if (typeof ey !== 'number') ey = sy;
125+
this.end = new game.Vector(ex, ey);
126+
if (typeof h1x !== 'number') h1x = sx;
127+
if (typeof h1y !== 'number') h1y = sy;
128+
if (typeof h2x !== 'number') h2x = ex;
129+
if (typeof h2y !== 'number') h2y = ey;
130+
this.handle1 = new game.Vector(h1x, h1y);
131+
this.handle2 = new game.Vector(h2x, h2y);
132+
},
133+
134+
/**
135+
Get point from curve.
136+
@method point
137+
@param {Number} percent Location of the point. 0 is start and 1 is the end of the curve.
138+
@param {Vector} [out] Optional vector, where the values are set.
139+
@return {Vector}
140+
**/
141+
point: function(percent, out) {
142+
out = out || new game.Vector();
143+
144+
var x = this._interpolate(percent, this.start.x, this.handle1.x, this.handle2.x, this.end.x);
145+
var y = this._interpolate(percent, this.start.y, this.handle1.y, this.handle2.y, this.end.y);
146+
147+
out.set(x, y);
148+
return out;
149+
},
150+
151+
/**
152+
@method _calcHandle1
153+
@param {Number} t
154+
@param {Number} p
155+
@return {Number}
156+
@private
157+
**/
158+
_calcHandle1: function(t, p) {
159+
var k = 1 - t;
160+
return 3 * k * k * t * p;
161+
},
162+
163+
/**
164+
@method _calcHandle2
165+
@param {Number} t
166+
@param {Number} p
167+
@return {Number}
168+
@private
169+
**/
170+
_calcHandle2: function(t, p) {
171+
return 3 * (1 - t) * t * t * p;
172+
},
173+
174+
/**
175+
@method _calcEnd
176+
@param {Number} t
177+
@param {Number} p
178+
@return {Number}
179+
@private
180+
**/
181+
_calcEnd: function(t, p) {
182+
return t * t * t * p;
183+
},
184+
185+
/**
186+
@method _calcStart
187+
@param {Number} t
188+
@param {Number} p
189+
@return {Number}
190+
@private
191+
**/
192+
_calcStart: function(t, p) {
193+
var k = 1 - t;
194+
return k * k * k * p;
195+
},
196+
197+
/**
198+
Get point from curve.
199+
@method _interpolate
200+
@param {Number} percent
201+
@param {Number} s
202+
@param {Number} h1
203+
@param {Number} h2
204+
@param {Number} e
205+
@return {Number}
206+
@private
207+
**/
208+
_interpolate: function(percent, s, h1, h2, e) {
209+
s = this._calcStart(percent, s);
210+
h1 = this._calcHandle1(percent, h1);
211+
h2 = this._calcHandle2(percent, h2);
212+
e = this._calcEnd(percent, e);
213+
return s + h1 + h2 + e;
214+
}
215+
});
216+
87217
/**
88218
@class Polygon
89219
@constructor

src/engine/renderer/graphics.js

+33-2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,26 @@ game.createClass('Graphics', 'Container', {
9999
this._drawShape(shape);
100100
return this;
101101
},
102+
103+
/**
104+
Draw bezier curve.
105+
@method drawCurve
106+
@param {Curve|Number} sx
107+
@param {Number} sy
108+
@param {Number} ex
109+
@param {Number} ey
110+
@param {Number} h1x
111+
@param {Number} h1y
112+
@param {Number} h2x
113+
@param {Number} h2y
114+
@chainable
115+
**/
116+
drawCurve: function(sx, sy, ex, ey, h1x, h1y, h2x, h2y) {
117+
this.lineWidth = this.lineWidth || 1;
118+
var shape = typeof sx === 'number' ? new game.Curve(sx, sy, ex, ey, h1x, h1y, h2x, h2y) : sx;
119+
this._drawShape(shape, true);
120+
return this;
121+
},
102122

103123
/**
104124
@method drawLine
@@ -325,7 +345,7 @@ game.createClass('GraphicsShape', {
325345

326346
this._renderShape(context);
327347

328-
if (this.fillColor && this.fillAlpha) context.fill();
348+
if (this.fillColor && this.fillAlpha && !this.isLine) context.fill();
329349
if (this.lineWidth) {
330350
context.globalAlpha = this.lineAlpha * alpha;
331351
context.stroke();
@@ -342,7 +362,18 @@ game.createClass('GraphicsShape', {
342362
var x = shape.x * game.scale;
343363
var y = shape.y * game.scale;
344364

345-
if (this.isLine) {
365+
if (this.isLine && shape.start) {
366+
context.moveTo(shape.start.x * game.scale, shape.start.y * game.scale);
367+
context.bezierCurveTo(
368+
shape.handle1.x * game.scale,
369+
shape.handle1.y * game.scale,
370+
shape.handle2.x * game.scale,
371+
shape.handle2.y * game.scale,
372+
shape.end.x * game.scale,
373+
shape.end.y * game.scale
374+
);
375+
}
376+
else if (this.isLine) {
346377
context.moveTo(x, y);
347378
context.lineTo(shape.width, shape.height);
348379
}

src/engine/renderer/sprite.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ game.createClass('Sprite', 'Container', {
116116
this._worldAlpha = alpha;
117117
this.blendMode = blendMode;
118118

119-
var texture = game.Texture.fromCanvas(canvas);
119+
var texture = game.Texture.fromImage(canvas.toDataURL());
120+
texture.width = canvas.width;
121+
texture.height = canvas.height;
120122
game.Sprite._tintedTextures.push(texture);
121123
return texture;
122124
},

src/engine/tween.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,11 @@ game.createClass('Tween', {
187187
**/
188188
easing: function(easing) {
189189
if (typeof easing === 'string') {
190-
easing = easing.split('.');
191-
this.easingFunction = game.Tween.Easing[easing[0]][easing[1]];
190+
var names = easing.split('.');
191+
if (!game.Tween.Easing[names[0]]) throw 'Easing ' + easing + ' not found';
192+
var easingFunc = game.Tween.Easing[names[0]][names[1]];
193+
if (!easingFunc) throw 'Easing ' + easing + ' not found';
194+
this.easingFunction = easingFunc;
192195
}
193196
else {
194197
this.easingFunction = easing;

0 commit comments

Comments
 (0)