多个矩形产生 [英] Multiple Rectangle Generation
问题描述
可能重复:结果
绘制多个像素/矩形
在我的$ C C I写道,在创建mouseX,mouseY的一个矩形的方法。但它是所有更新的矩形,它跟随鼠标,我希望它在鼠标创建一个新的每次方法运行时间,位置可有人请帮忙吗?
In my code i wrote a method that creates a rectangle at mouseX, mouseY. but all it does is update the position of that rectangle so it follows the mouse, i want it to create a new one at the mouse every time the method runs, can someone please help?
这是我的方法
public void drawParticle(float x, float y){
g.drawRect(x, y, 4, 4);
}
主类控制调用drawParticle方法;
The main class Control call the drawParticle method;
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;
}
}
谢谢 - 夏姆斯
Thanks - Shamus
推荐答案
做到这一点的方法是创建一个列表
作为成员变量,并添加一个新的长方形
每次用户点击鼠标的时间。然后在你的渲染()
方法,遍历长方形$ C的
列表
$ C>和油漆每个人。
One way to do this is to create a List
as a member variable and add a new Rectangle
each time the user clicks the mouse. Then in your render()
method, iterate through the List
of Rectangle
s and paint each one.
这篇关于多个矩形产生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!