float x = 200;
float y = 200;
int[] pipeX, pipeY; //Declaring
void setup()
{
size(800, 620);
bg =loadImage("bg.jpg");
top_pipes = loadImage("top.png");
bottom_pipes = loadImage("bottom.png");
pipeX = new int [4];
pipeY = new int[pipeX.length];
//Populate array with values
for (int i = 0; i < pipeX.length; i++)
{
pipeX[i] = width + 200*i;
pipeY[i] = (int) random (-350, 50); //float to int
}
}
void draw()
{
setBg();
cleo();
for (int i = 0; i < pipeX.length; i++)
{
image(top_pipes, pipeX[i], pipeY[i]);
image(bottom_pipes, pipeX[i], pipeY[i] + 680);
pipeX[i]--;
}
}
There’s two ways of doing this, one is to use 2 more parameters in the image() function.
image(top_pipes, pipeX[i], pipeY[i], 100,100); // will make it 100 by 100 pixels
The other method is to use the resize function in setup.
top_pipes.resize(100,100);
They both do the same thing and as far as I can tell one has no advantage over the other, Hope that helps
2 Likes