Question: Hello, I am having an issue with my processing code. shuffle ( string [ ] ) does not exist. Please help, here is the code:

Hello, I am having an issue with my processing code. shuffle(string[]) does not exist. Please help, here is the code:
import processing.core.*;
// Import SoundFile class
import processing.sound.*;
// 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"
};
// Track current scene index
int currentScene =0;
// Initial sprite position
int spriteX =0;
// Flag to control walking animation
boolean walking = false;
// Direction of sprite movement
boolean walkingRight = true;
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);
}
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
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.0){
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();
}
Please note that this is processing code not javascript

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!