Answer the question
In order to leave comments, you need to log in
HTML5 Canvas: Why does the image leave a trail when setTransform is set?
Here is the whole code:
<canvas id="g" width="300" height="225"></canvas>
<script>
var canvas = document.getElementById('g');
var ctx = canvas.getContext('2d');
var img = new Image();
img.src = 'logo.gif';
ctx.fillStyle = '#0fffff';
var angle = 0;
setInterval(function() {
angle += .005;
ctx.fillRect(0, 0, 300, 225);
ctx.setTransform(Math.cos(angle),Math.sin(angle),-Math.sin(angle),Math.cos(angle),10-223/2,10-43/2);
ctx.drawImage(img, 10, 10, 223, 43);
ctx.setTransform(0,0,0,0,0,0);
}, 18);
</script>
For some reason, the image leaves a trail behind it, as if the rectangle is not being redrawn. If you use rotate instead of setTransform, then the problem disappears. Where does this behavior come from and how to get rid of it? Answer the question
In order to leave comments, you need to log in
Weird, I tested it and everything works smoothly without blurring
codepen.io/anon/pen/ABbhq
upload the page to the fiddle along with the gif - debug
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question