diff --git a/src/core/particles/ParticleContainer.js b/src/core/particles/ParticleContainer.js index 8289de0..9f96bde 100644 --- a/src/core/particles/ParticleContainer.js +++ b/src/core/particles/ParticleContainer.js @@ -77,6 +77,14 @@ */ this.blendMode = CONST.BLEND_MODES.NORMAL; + /** + * Used for canvas renderering. If true then the elements will be positioned at the nearest pixel. This provides a nice speed boost. + * + * @member {boolean} + * @default true; + */ + this.roundPixels = true; + this.setProperties(properties); } @@ -198,6 +206,12 @@ var context = renderer.context; var transform = this.worldTransform; var isRotated = true; + + var positionX = 0; + var positionY = 0; + + var finalWidth = 0; + var finalHeight = 0; context.globalAlpha = this.worldAlpha; @@ -233,17 +247,12 @@ isRotated = false; } - context.drawImage( - child.texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, - ((child.anchor.x) * (-frame.width * child.scale.x) + child.position.x + 0.5) | 0, - ((child.anchor.y) * (-frame.height * child.scale.y) + child.position.y + 0.5) | 0, - frame.width * child.scale.x, - frame.height * child.scale.y - ); + positionX = ((child.anchor.x) * (-frame.width * child.scale.x) + child.position.x + 0.5); + positionY = ((child.anchor.y) * (-frame.height * child.scale.y) + child.position.y + 0.5); + + finalWidth = frame.width * child.scale.x; + finalHeight = frame.height * child.scale.y; + } else { @@ -279,17 +288,23 @@ ); } - context.drawImage( - child.texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, - ((child.anchor.x) * (-frame.width) + 0.5) | 0, - ((child.anchor.y) * (-frame.height) + 0.5) | 0, - frame.width, - frame.height - ); + positionX = ((child.anchor.x) * (-frame.width) + 0.5); + positionY = ((child.anchor.y) * (-frame.height) + 0.5); + + finalWidth = frame.width; + finalHeight = frame.height; } + + context.drawImage( + child.texture.baseTexture.source, + frame.x, + frame.y, + frame.width, + frame.height, + positionX, + positionY, + finalWidth, + finalHeight + ); } };