Question: Hello I am having an issue with my processing code. I dont know if the png files are the problem but when i run the
Hello I am having an issue with my processing code. I dont know if the png files are the problem but when i run the code, the sketch crashes!I will leave the code down here:
import processing.sound.;
int numPoses ; Number of poses in the sprite sheet
int poseWidth ; Width of a pose in your sprite sheet
int poseHeight ; Height of a pose in your sprite sheet
int spriteSheetWidth poseWidth numPoses; Total width of the sprite sheet
float x ; Position of the sprite
float y ;
float speed ; Speed of the sprite
String locations beachpng "school.png "landscape.png;
PImage imgs new PImagelocationslength;
SoundFile sounds new SoundFilelocationslength; Use SoundFile class
int currentLocation ;
PImage spriteSheet; Declare spriteSheet at global scope
void preload
spriteSheet loadImagepnweggpng; Load the sprite sheet
for int i ; i locations.length; i
imgsi loadImagelocationsi; Load the images for each location
soundsi new SoundFilethis locationsireplacepngmp; Load the sound effects
void setup
fullScreen; Sets the window size full screen
currentLocation floorrandomlocationslength; Randomly chooses a starting location
void draw
background; Clear the screen with a white background
imageimgscurrentLocation; Display the current location image
PImage currentPose spriteSheet.getframeCount numPoses poseWidth, poseWidth, poseHeight; Extract the current pose from the sprite sheet
imagecurrentPose 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
soundscurrentLocationplay; Play the sound effect for the current location
x ; Reset the position
int nextLocation floorrandomlocationslength; Randomly choose the next location
while nextLocation currentLocation Make sure the next location is different from the current
nextLocation floorrandomlocationslength;
currentLocation nextLocation;
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
