mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
fixed sprite rendering
This commit is contained in:
parent
885c39b9c3
commit
aabd202a9d
1 changed files with 12 additions and 3 deletions
|
@ -267,13 +267,22 @@ var Render = {};
|
|||
if (body.render.sprite && !options.wireframes) {
|
||||
// body sprite
|
||||
var sprite = body.render.sprite;
|
||||
c.save();
|
||||
c.webkitImageSmoothingEnabled = true;
|
||||
|
||||
if (options.showSleeping && body.isSleeping)
|
||||
c.globalAlpha = 0.5;
|
||||
|
||||
c.translate(body.position.x, body.position.y);
|
||||
c.rotate(body.angle);
|
||||
|
||||
c.drawImage(sprite.image, sprite.width * -0.5 * sprite.xScale, sprite.height * -0.5 * sprite.yScale,
|
||||
sprite.width * sprite.xScale, sprite.height * sprite.yScale);
|
||||
c.restore();
|
||||
|
||||
// revert translation, hopefully faster than save / restore
|
||||
c.rotate(-body.angle);
|
||||
c.translate(-body.position.x, -body.position.y);
|
||||
|
||||
if (options.showSleeping && body.isSleeping)
|
||||
c.globalAlpha = 1;
|
||||
} else {
|
||||
// body polygon
|
||||
if (body.circleRadius) {
|
||||
|
|
Loading…
Reference in a new issue