我在Processing(Java)中创建了以下草图:
ArrayList<Piece> pieces = new ArrayList<Piece>();
void setup() {
size(300, 300);
pieces.add(new Piece(100, 200)); // I ADD ONE PIECE TO THE ARRAY LIST
}
void draw() {
background(0);
for (int i = 0; i < pieces.size(); i++) {
Piece p = pieces.get(i);
p.display(); // I WANT TO DRAW THE PIECE I'VE CREATED IN SETUP()
}
}
class Piece {
int x;
int y;
Piece (int x, int y) {
x = x;
y = y;
}
void display() {
fill(255); …Run Code Online (Sandbox Code Playgroud)