gpt4 book ai didi

java - 图像旋转动画

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:54:14 28 4
gpt4 key购买 nike

也许是一个简单答案的问题。我正在尝试为一艘船制作动画(小行星风格)。现在我只是在使用 Graphics2D 旋转方法。然而,现在它只是模糊了我的形象。解决这个问题并使其正常工作的最简单方法是什么? (每次屏幕刷新都会调用getImage方法,每次用户左右键都会调用rotate方法,bi1是之前读入的bufferedimage)

public void rotate(double rot) {
g = bi1.getGraphics();
Graphics2D g2d=(Graphics2D)g;
g2d.rotate(rot, 15, 15);
g2d.drawImage(bi1, 0, 0, null);
}

public BufferedImage getImage() {
return bi1;
}

最佳答案

尝试使用仿射变换:

  public void paint(Graphics g) {
// clear off screen bitmap
      super.paint(g);
      // cast graphics to graphics 2D
      Graphics2D g2 = (Graphics2D) g;
      AffineTransform tfm = new AffineTransform();
      tfm.rotate(0,0,0);
      g2.setTransform(tfm);
      g2.drawImage(backImage, 0, 0, this);
      tfm.rotate(Math.toRadians(player.angle+90), player.x+32, player.y+32);
      g2.setTransform(tfm);
      g2.drawImage(tank, player.x, player.y, this);      
  }

http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/geom/AffineTransform.html

关于java - 图像旋转动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9714629/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com