我正在制作一款自上而下的射击游戏,它依赖于始终朝着鼠标指针旋转的头像。我实现旋转这样的:为什么在上下文旋转后图像会丢失质量?
//Rendering.
context.save(); //Save the context state, we're about to change it a lot.
context.translate(position[0] + picture.width/2, position[1] + picture.height/2); //Translate the context to the center of the image.
context.rotate(phi); //Rotate the context by the object's phi.
context.drawImage(picture.image, -picture.width/2, -picture.height/2); //Draw the image at the appropriate position (center of the image = [0, 0]).
context.restore(); //Get the state back.
当phi
为零时,图像被在其正常质量渲染,具有尖锐边缘和可检测的像素。但是,当我设置phi
为非零值(实际上,当它不是0
,Pi/2
,Pi
,Pi+Pi/2
或2Pi
),图像失去它的清晰度和单个像素不能再看到的,因为他们是模糊的。
下面是截图(约截图的总体质量差抱歉,但我觉得差比明显更多):
这是,嗯,有点难以接受。我不能让图像一直模糊不清! 为什么会发生这种情况,我可以解决它吗?
想想原始像素需要如何与图像的旋转版本对齐..它们不会匹配像素网格 - 那么应该怎么做..? – Randy 2012-07-05 20:59:14
为什么在非HTML5游戏中不会发生这种情况?这天晚些时候我正在玩Dragon Fly,并且它没有旋转小龙的问题! – corazza 2012-07-05 21:00:09
Flash有点不同.. – Daedalus 2012-07-05 21:00:46