可能重复:
绘制多个像素/矩形
在我的代码中,我编写了一个在 mouseX、mouseY 处创建矩形的方法。但它所做的只是更新该矩形的位置,使其跟随鼠标,我希望它在每次运行该方法时在鼠标上创建一个新矩形,有人可以帮忙吗?
这是我的方法
public void drawParticle(float x, float y){
g.drawRect(x, y, 4, 4);
}
主类Control调用drawParticle方法;
import java.awt.Point;
import java.awt.geom.Point2D;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
public class Control extends BasicGameState {
public static final int ID = 1;
public Methods m = new Methods();
public Graphics g = new Graphics();
int mouseX;
int mouseY;
public void init(GameContainer container, StateBasedGame game) throws SlickException{
}
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
m.drawParticle(mouseX, mouseY);
}
public void update(GameContainer container, StateBasedGame game, int delta) {
}
public void mousePressed(int button, int x, int y) {
mouseX = x;
mouseY = y;
}
public int getID() {
return ID;
}
}
谢谢 - 沙姆斯