Hey, i’m new to processing and programming in general and i’m trying to do a game where there are birds coming for each edge of the screen at random heights with different speeds. The problem with this is that when i try to use an array of that class with PShape involved(for the bird image) the program bugs out when i press the button to get to the game display. My main page looks something like this
Bird b[i] = new Bird[20]();
PShape n;
void setup() {
size(1280, 720);
n = loadShape("piupiu.svg");
for (int i=0; i<b.length; i++) {
b[i] = new Bird();
}
}
void draw() {
background(0, 255, 0);
menu();
if (jogo==true) {
display();
b.show();
}
}
My bird class:
class Bird {
float x1, x2;
float xspeed = random(5, 10);
PShape n;
PVector v1, v2;
void show() {
shape(n,50,60,60,60);
}
}
1 Like
How exactly does it “bug out”? It should have an error popping up right below your code in a black rectangle.
Is there any? Can you copy it here?
P.S. When making a post, there’s a little button right above the text field that looks like </>
Please, when putting technical texts, select them and press this button to make them something like this
, as otherwise the forum’s thing assumes your code is text and makes it fancier by replacing symbols and removing spacebars before things
NullPointerException
But if i do an array of rects lets say they all appear.
Uhh, there must be more to this error? There’s usually at least 10 lines, most of which start with the word “at”…
I don’t see anything wrong with the code you posted except that it refers to things that aren’t really in it - maybe the problem is in other parts of the code?
When that error happens, it should highlight the exact line of code where this error happened - what is that line?
Oh. I guess that’s only because of n
since nothing else in this line of code could give an error.
And, you set n
to loadShape(“piupiu.svg”)
, so it shouldn’t be null
, so you shouldn’t get NullPointerException
… Except if loadShape(“piupiu.svg”)
fails.
Where is that file piupiu.svg
? If it’s in your data path or sketch’s path, you might want to use n = loadShape(dataPath("piupiu.svg"));
or n = loadShape(sketchPath("piupiu.svg"));
instead.
It’s on the data folder of my sketch