A few subtle draw performance fixes
By rounding all floated values to whole numbers... we can help a tad with aliasing and the like
This commit is contained in:
parent
9d615b5a25
commit
f6cd6434ae
|
@ -55,8 +55,8 @@ Engine.Particle.Fixed.prototype = {
|
||||||
// Draw a circle - far less performant
|
// Draw a circle - far less performant
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.arc(
|
ctx.arc(
|
||||||
this.pos.x * scale,
|
this.pos.x * scale >> 0,
|
||||||
this.pos.y * scale,
|
this.pos.y * scale >> 0,
|
||||||
this.radius * scale,
|
this.radius * scale,
|
||||||
0,
|
0,
|
||||||
Math.PI * 2,
|
Math.PI * 2,
|
||||||
|
|
|
@ -135,8 +135,8 @@ Engine.Particle.prototype = {
|
||||||
|
|
||||||
// Draw a square - very performant
|
// Draw a square - very performant
|
||||||
ctx.fillRect(
|
ctx.fillRect(
|
||||||
this.pos.x * scale,
|
this.pos.x * scale >> 0,
|
||||||
this.pos.y * scale,
|
this.pos.y * scale >> 0,
|
||||||
this.radius * scale,
|
this.radius * scale,
|
||||||
this.radius * scale
|
this.radius * scale
|
||||||
);
|
);
|
||||||
|
|
|
@ -63,16 +63,16 @@ Engine.Polygon.prototype = {
|
||||||
draw: function(ctx, scale){
|
draw: function(ctx, scale){
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(
|
ctx.moveTo(
|
||||||
this.a.pos.x * scale,
|
this.a.pos.x * scale >> 0,
|
||||||
this.a.pos.y * scale
|
this.a.pos.y * scale >> 0
|
||||||
);
|
);
|
||||||
ctx.lineTo(
|
ctx.lineTo(
|
||||||
this.b.pos.x * scale,
|
this.b.pos.x * scale >> 0,
|
||||||
this.b.pos.y * scale
|
this.b.pos.y * scale >> 0
|
||||||
);
|
);
|
||||||
ctx.lineTo(
|
ctx.lineTo(
|
||||||
this.c.pos.x * scale,
|
this.c.pos.x * scale >> 0,
|
||||||
this.c.pos.y * scale
|
this.c.pos.y * scale >> 0
|
||||||
);
|
);
|
||||||
ctx.closePath();
|
ctx.closePath();
|
||||||
ctx.fillStyle = this.fillStyle;
|
ctx.fillStyle = this.fillStyle;
|
||||||
|
|
|
@ -42,20 +42,23 @@ Engine.Shape.prototype = {
|
||||||
|
|
||||||
selfDestruct: function(time){
|
selfDestruct: function(time){
|
||||||
this.destruct = time;
|
this.destruct = time;
|
||||||
|
this.elapsed = 0;
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
update: function(engine){
|
update: function(engine){
|
||||||
var p;
|
var p;
|
||||||
|
|
||||||
|
// if (this.destruct) {
|
||||||
|
// this.elapsed += engine.tick;
|
||||||
|
// }
|
||||||
|
|
||||||
for (p = 0; p < this.points.length; p++) {
|
for (p = 0; p < this.points.length; p++) {
|
||||||
this.points[p].update(engine);
|
this.points[p].update(engine);
|
||||||
// this.points[p].draw(this.context, scale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (p = 0; p < this.polygons.length; p++) {
|
for (p = 0; p < this.polygons.length; p++) {
|
||||||
this.polygons[p].update(engine);
|
this.polygons[p].update(engine);
|
||||||
// this.polygons[p].draw(this.context, scale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -65,7 +68,10 @@ Engine.Shape.prototype = {
|
||||||
var p;
|
var p;
|
||||||
|
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.translate(this.pos.x * scale, this.pos.y * scale);
|
ctx.translate(
|
||||||
|
this.pos.x * scale >> 0,
|
||||||
|
this.pos.y * scale >> 0
|
||||||
|
);
|
||||||
for (p = 0; p < this.polygons.length; p++) {
|
for (p = 0; p < this.polygons.length; p++) {
|
||||||
this.polygons[p].draw(ctx, scale);
|
this.polygons[p].draw(ctx, scale);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue