We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have this code:
PImage[] lol;
PImage thing;
void setup() {
size(500,300);
thing = loadImage("c_0.png");
loadImages(lol, 12);
}
void loadImages(PImage[] p1, int size) {
p1 = new PImage[size];
for(int i = 0; i < size; i++) {
p1[i] = thing;
}
}
void draw() {
image(lol[3], 30, 40);
}
However, this gives me a NullPointerException. Why? Can't I initialize the PImages inside a method?
Thank you for any help :)
Answers
Parameters are also local variables. Once their function ends, local variables are gone too! :-&
Also, why would you need to have some array filled w/ the the same PImage?! :-/
I was trying to create a method for initializing spritesheets. My full code was this:
I would run this method like this:
loadImages(tileSS, "36086464-ocean-wallpaper.jpg", tileS, 7, 3, 50, 50);
Thank you very much for answering! :)
I'd go w/ something like this: *-:)
Thank you :) :ar!