Attempting to improve performance a bit

This commit is contained in:
Amadeus Demarzi 2014-07-25 21:16:16 -07:00
parent c6a5b0458e
commit 5f10724025
3 changed files with 28 additions and 13 deletions

View File

@ -87,30 +87,38 @@ Engine.Shape.Puller.prototype = {
this.polygons[p].update(engine, this);
}
if (this.alpha < 0.2) {
this.alpha += 1 * engine.tick;
if (this.alpha < 1) {
this.alpha = Math.min(this.alpha + 2 * engine.tick, 1);
}
return this;
},
draw: function(ctx, scale){
draw: function(ctx, scale, engine){
var p;
ctx.save();
ctx.translate(
this.pos.x * scale >> 0,
this.pos.y * scale >> 0
);
if (this.alpha < 1) {
ctx.globalAlpha = this.alpha;
}
ctx.beginPath();
for (p = 0; p < this.polygons.length; p++) {
this.polygons[p].draw(ctx, scale);
}
ctx.closePath();
ctx.lineWidth = 1 * scale;
ctx.strokeStyle = 'rgba(108,0,243,' + this.alpha + ')';
ctx.strokeStyle = 'rgba(108,0,243,0.2)';
ctx.stroke();
if (this.alpha < 1) {
ctx.globalAlpha = 1;
}
for (p = 0; p < this.points.length; p++) {
this.points[p].draw(ctx, scale);
}
@ -125,7 +133,11 @@ Engine.Shape.Puller.prototype = {
ctx.fillStyle = 'rgba(108,0,243,0.1)';
ctx.fill();
ctx.restore();
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.translate(
engine.width / 2 * engine.scale >> 0,
engine.height / 2 * engine.scale >> 0
);
return this;
}

View File

@ -68,10 +68,9 @@ Engine.Shape.prototype = {
return this;
},
draw: function(ctx, scale){
draw: function(ctx, scale, engine){
var p;
ctx.save();
ctx.translate(
this.pos.x * scale >> 0,
this.pos.y * scale >> 0
@ -79,7 +78,11 @@ Engine.Shape.prototype = {
for (p = 0; p < this.polygons.length; p++) {
this.polygons[p].draw(ctx, scale, this.noStroke);
}
ctx.restore();
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.translate(
engine.width / 2 * engine.scale >> 0,
engine.height / 2 * engine.scale >> 0
);
return this;
}

View File

@ -164,7 +164,7 @@ Engine = Base.extend({
if (this.showGrid) {
this.grid
.update(this)
.draw(this.context, scale);
.draw(this.context, scale, this);
}
if (this.showShapes) {
@ -182,12 +182,12 @@ Engine = Base.extend({
for (p = 0; p < this.shapes.length; p++) {
this.shapes[p]
.update(this)
.draw(this.context, scale);
.draw(this.context, scale, this);
}
this.logo
.update(this)
.draw(this.context, scale);
.draw(this.context, scale, this);
// Remove destroyed shapes
for (p = 0; p < this._deferredShapes.length; p++) {
@ -275,7 +275,7 @@ Engine = Base.extend({
for (p = 0; p < this.particles.length; p++) {
this.particles[p]
.update(this)
.draw(this.context, scale);
.draw(this.context, scale, this);
}
// Remove destroyed particles