Question: Hello, my processing code has a syntax error. It says Error on parameter or method declaration near String [ ] backgrounds = { beach .

Hello, my processing code has a syntax error. It says "Error on parameter or method declaration near String[] backgrounds ={beach.png","?".
Can you please fix this minor error? Here is the code:
import processing.core.*; // import core processing library
PImage sprite, beach, landscape, school; // Declare image variables
PApplet p; // Declare PApplet variable
String[] backgrounds ={beach.png", "landscape.png", "schoolipng.png"}; Array for background images
String[] sounds ={"beachsound.mp3", "landscapesound.mp3", "schoolsound.mp3"}; // Array for sound files
int currentScene =0; // Track current scene index
int spriteX =0; // Initial sprite position
boolean walking = false; // Flag to control walking animation
boolean walkingRight = true; // Direction of sprite movement
void setup(){
p = this; // Assign PApplet instance
size(800,600); // Set window size
// Load images and sounds
sprite = loadImage("pngegg.png");
beach = loadImage("beach.png");
landscape = loadImage("landscape.png");
school = loadImage("schoolipng.png");
// Randomly shuffle background and sound order
shuffle(backgrounds, sounds);
}
void draw(){
background(loadImage(backgrounds[currentScene])); // Set background image
// Handle sprite movement
if (walking){
if (walkingRight){
spriteX +=5; // Move sprite right
if (spriteX + sprite.width >= width){
walking = false; // Stop walking at screen edge
playNextSound(); // Play next scene's sound
currentScene =(currentScene +1)% backgrounds.length; // Wrap around to next scene
}
} else {
spriteX -=5; // Move sprite left
if (spriteX <=0){
walking = false; // Stop walking at screen edge (left side)
playNextSound(); // Play next scene's sound
currentScene =(currentScene -1+ backgrounds.length)% backgrounds.length; // Wrap around to previous scene
}
}
}
// Draw sprite based on direction
if (walkingRight){
image(sprite, spriteX, height - sprite.height);
} else {
image(sprite, spriteX + sprite.width, height - sprite.height, -sprite.width, sprite.height); // Flip image horizontally
}
// Stop the program after completing all scenes
if (currentScene ==0 && !walking){
noLoop();
}
}
void mousePressed(){
walking = true; // Start walking animation on mouse press
if (spriteX > width /2){
walkingRight = false; // Start walking left if clicked on the right half
}
}
void playNextSound(){
// Play the sound file corresponding to the current scene
SoundFile sound = new SoundFile(p, sounds[currentScene]);
sound.play();
}

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!