We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a class Item with an attribute PImage image;
But i never create an instance of that image.
I do this for example:
class Heart extends Item{
PImage h = loadImage("heart_pink.png");
Heart(float x, float y){
super(x,y);
}
void show() {
image(h, x - h.width/2, y - h.height/2);
}
And it doesnt work cuz on Item, on image i get a null pointer.
I fix it by saying: PImage image = createImage(0,0,0);
But i dont really like it since BEFORE i call that image, on heart, i loadImage.
Answers
https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text
Rather than loading resources in classes, prefer passing an already loaded resource to the class: *-:)
interestingly, image h is only known in heart, not in item:
I have 2 classes (and i may add like 2 or 3 more) which extend from Item, so i CANT load an image on Item, cuz each class has its own image. I have a heart, spiders, i may have boomerangs and circles.
So thats why i add heart_pink only on heart class.
This is my class Item (i need an image to so i can make the collide method):
This is the heart constructor:
And this is the Enemy constructor:
As u see, each class take its own image before building the object. So i dont know why i get a null pointer on Item.
And sorry, idk how to write code format here
See link by gotoloop above
okey, done ^^