0
我想做一个子弹类。当它被调用时,它会得到一个方向和一个初始位置。问题是方向不起作用,无论我设定为什么方向,它都只会上升。旋转图形
请帮忙。
在此先感谢
public class Bullet extends JComponent implements ActionListener{
private int bx,by;
private double theta;
private double BvelX, BvelY;
private Timer timer = new Timer(8,this);
public Bullet(int bx, int by, double theta)
{
this.bx = bx;
this.by = by;
this.theta = theta;
BvelX = 0;
BvelY = -1;
timer.start();
revalidate();
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D graphicsS = (Graphics2D) g;
graphicsS.rotate(theta, bx, by);
graphicsS.setColor(Color.RED);
graphicsS.fillOval(bx, by, 8, 8);
}
public void actionPerformed(ActionEvent e)
{
bx += BvelX;
by += BvelY;
/*by += 5*(Math.sin(theta));
bx += 5*(Math.cos(theta));*/
revalidate();
repaint();
}
}
我也试过,但方向是关闭的 – user2378547 2013-05-13 21:27:54
而且我也有一个与graphicsS.rotate(theta,bx,by)的旋转;怎么没有做什么? – user2378547 2013-05-13 21:28:59
,因为你永远不会更新'theta',所以它保持不变。您需要按照“bx”和“by”的方式进行操作。 – 2013-05-13 21:44:52