Question: Hello, I have an issue with my processing code. it says size ( ) cannot be used here. Can i please get this minor issue

Hello, I have an issue with my processing code. it says size() cannot be used here. Can i please get this minor issue fixed? I will leave the code down here( This is processing code):
import processing.sound.*;
int numPoses =6; // Number of poses in the sprite sheet
int poseWidth =100; // Width of a pose in your sprite sheet
int poseHeight =100; // Height of a pose in your sprite sheet
int spriteSheetWidth = poseWidth * numPoses; // Total width of the sprite sheet
float x =0; // Position of the sprite
float y =0;
float speed =4; // Speed of the sprite
String[] locations ={"beach.png", "school.png", "landscape.png"};
PImage[] imgs = new PImage[locations.length];
SoundFile[] sounds = new SoundFile[locations.length]; // Use SoundFile class
int currentLocation =0;
PImage spriteSheet; // Declare spriteSheet at global scope
void preload(){
spriteSheet = loadImage("pnwegg.png"); // Load the sprite sheet
for (int i =0; i < locations.length; i++){
imgs[i]= loadImage(locations[i]); // Load the images for each location
sounds[i]= new SoundFile(this, locations[i].replace(".png",".mp3")); // Load the sound effects
}
}
void setup(){
size(poseWidth * numPoses, poseHeight); // Sets the window size based on the pose size and number of poses
currentLocation = floor(random(locations.length)); // Randomly chooses a starting location
}
void draw(){
background(255); // Clear the screen with a white background
image(imgs[currentLocation],0,0); // Display the current location image
PImage currentPose = spriteSheet.get((frameCount % numPoses)* poseWidth, 0, poseWidth, poseHeight); // Extract the current pose from the sprite sheet
image(currentPose, x, y); // Draw the current pose on top of the location image
x += speed; // Moves the sprite
if (x > width){// Check if the sprite has reached the end of the screen
sounds[currentLocation].play(); // Play the sound effect for the current location
x =0; // Reset the position
int nextLocation = floor(random(locations.length)); // Randomly choose the next location
while (nextLocation == currentLocation){// Make sure the next location is different from the current
nextLocation = floor(random(locations.length));
}
currentLocation = nextLocation;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!