gpt4 book ai didi

java - 多重矩形生成

转载 作者:行者123 更新时间:2023-11-29 03:41:56 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Drawing multiple pixels/rectangles

在我的代码中,我编写了一个在 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;
}

}

谢谢 - Shamus

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