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 ; Number of phone sprite poses
int currentSprite ; Index of the current phone sprite
float phoneX, phoneY; Smartphone position
float bgX ; Background position
String backgroundElements; Array containing background element names
boolean elementShown; Array to track if an element has been passed
void setup
size; Adjusts window size
phoneSprites new PImagenumSprites;
Load phone sprites into the array
for int i ; i numSprites; i
phoneSpritesi loadImagepngeggpng;
backgroundImg loadImageparkbackgroundpng; Or use longer background image
phoneX width ; Start phone in the center
phoneY height ;
backgroundElements new Stringbench "lamp", "icecream", "flowers";
elementShown new booleanbackgroundElementslength;
void draw
background; Draw sky blue
Draw background
imagebackgroundImg bgX;
Move background based on phone movement
bgX ; Adjust speed as needed
Draw phone sprite
imagephoneSpritescurrentSprite 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
shufflebackgroundElements 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
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
