Multiple Rectangle Generation

Posted by user1610541 on Stack Overflow See other posts from Stack Overflow or by user1610541
Published on 2012-10-08T02:26:53Z Indexed on 2012/10/08 3:37 UTC
Read the original article Hit count: 94

Filed under:
|
|
|
|

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?

this is my method

public void drawParticle(float x, float y){
    g.drawRect(x, y, 4, 4);
}

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

© Stack Overflow or respective owner

Related posts about java

Related posts about arrays