>我目前正在做一个学校项目,我们正在用代号一创建一个小行星游戏。我当前的功能运行良好,除了旋转船的图像。使用 Transform 类无效;无论如何应用变换或绘制图像,图像都不会旋转。
以下是用于 turn 的代码的示例部分:
public void turnRight() //Rotates the ship 5 degrees clockwise
{
if (direction==355)
direction = 0;
else
direction+=5;
Transform tmpTransform = Transform.makeIdentity();
theImage.getGraphics().getTransform(tmpTransform);
tmpTransform.rotate((float)Math.toRadians(5), x, y);
theImage.getGraphics().setTransform(tmpTransform);
theImage.getGraphics().drawImage(shipPic, 0, 0);
}
哪里:
- 图像是可变图像 (100x100(
- shipPic 是通过 Image.createImage(字符串路径(创建的映像
此外,我还尝试使用 draw(Graphics g, Point p( 方法并传递 theImage.getGraphics((,以及传递 shipPic.getGraphics((我不知所措,代号一关于这个主题的文档是没有帮助的。
我可以得到一些帮助吗?
您需要使用一个图形对象,如下所示:
图形 g = theImage.getGraphics((;
会更正确。在渲染到图像上时,还必须测试转换支持,因为低级图形并不总是可移植到所有表面中的所有操作系统。一个很好的例子是 iOS,其中渲染到图像上使用与显示渲染完全不同的低级实现。
通常我会直接渲染到显示器,因为它在现代设备上是硬件加速的,并且图像通常在软件中实现。
关于文档,您是否阅读了开发人员指南中的图形部分?
它应该包含所有内容的解释,如果缺少某些内容,则进行搜索。如果您仍然找不到某些内容并自己弄清楚,请注意,您还可以编辑文档并帮助我们改进它们。