Simple question about arrays and motion.
in
Programming Questions
•
6 months ago
Hi, im new to the forum and processing so bare with me.
Im trying to get an array of arrows to move across the screen, so far i can only get one column to do so and i think ive gone the wrong way about doing it...
Any help would be very very appreciated!
here is my code:
PImage arrow;
Cell[][] grid;
// Number of columns and rows in the grid
int cols = 12;
int rows = 16;
void setup() {
size(480, 320);
grid = new Cell[cols][rows];
arrow = loadImage("arrow.png");
for (int i = 0; i < cols; i ++ ) {
for (int j = 0; j < rows; j ++ ) {
// Initialize each object
grid[i][j] = new Cell( i*20, j*20, i + j);
}
}
}
void draw() {
background(0);
for (int i = 0; i < cols; i ++ ) {
for (int j = 0; j < rows; j ++ ) {
// Oscillate and display each object
grid[i][j].update();
grid[i][j].display();
}
}
}
class Cell {
float x, y; // x,y location
float s;
// Cell Constructor
Cell( float tempX, float tempY, float speed) {
x = tempX;
y = tempY;
s = speed;
}
void update() {
s++;
if (s>480) {
s=0;
}
}
void display() {
stroke(255);
fill(255);
//can only add in 2 values, x,y produces array of arrows but with no movement
image(arrow, s, y);
}
}
1