Question: Hello, I am trying to create a code using processing that will have a sprite walking. I already showed you the png in the picture

Hello, I am trying to create a code using processing that will have a sprite walking. I already showed you the png in the picture if you want to see how the png looks like. I cant show the background png but it is just a park background. First I need to fix the code. It wont run. I will leave the code down here.
// The reason I have "phone" for parts of my code is because I was planning on adding a walking phone sprite but I changed my mind
// Variable declarations
PImage[] phoneSprites; // Array to store phone sprite images
PImage backgroundImg; // Background image or a longer image with all elements
int numSprites =6; // Number of phone sprite poses
int currentSprite =0; // Index of the current phone sprite
float phoneX, phoneY; // Smartphone position
float bgX =0; // Background position
String[] backgroundElements; // Array containing background element names
boolean[] elementShown; // Array to track if an element has been passed
void setup(){
size(600,400); // Adjusts window size
phoneSprites = new PImage[numSprites];
// Load phone sprites into the array
for (int i =0; i numSprites; i++){
phoneSprites[i]= loadImage(pngegg.png);
}
backgroundImg = loadImage(parkbackground.png); // Or use longer background image
phoneX = width /2; // Start phone in the center
phoneY = height /2;
backgroundElements = new String[]{"bench", "lamp", "icecream", "flowers"};
elementShown = new boolean[backgroundElements.length];
}
void draw(){
background(135,206,250); // Draw sky blue
// Draw background
image(backgroundImg, bgX,0);
// Move background based on phone movement
bgX -=1; // Adjust speed as needed
// Draw phone sprite
image(phoneSprites[currentSprite], phoneX, phoneY);
// Handle user input (update phoneX based on arrow keys)
// Check for element passing and update elementShown array
checkForElementPass();
// Randomize element order before each loop
shuffle(backgroundElements, true);
// Display elements based on randomized order and elementShown array
displayBackgroundElements();
updateSpriteAnimation(); // Update currentSprite for walking animation
}
void checkForElementPass(){
// Check if an element has passed the phone and update
Hello, I am trying to create a code using

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 Programming Questions!