We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › PImage stored in class
Page Index Toggle Pages: 1
PImage stored in class? (Read 540 times)
PImage stored in class?
Jan 23rd, 2010, 12:42pm
 
Hello!
First of all I want to say sorry for my English - I'm German so pardon me please.

I've got a class for Cars which looks like this (very simplified):

class Car {
 PImage carimage;

 Car(String carimageurl) {
   carimage = loadImage(carimageurl);
 }
}


And I create my Car like this:

Car Car1 = new Car("car.png");

void setup() {
 //more Code here
}

void draw() {
 //even more Code here
}


Everything's very simplified, but you get the idea.
The car.png is available and accessible in the sketch's data folder but processing is of another opinion. Do I have to add something to the path when calling loadImage from inside a class? Is it better to directly pass a PImage to the class?

Thank you in advance.
Re: PImage stored in class?
Reply #1 - Jan 23rd, 2010, 2:33pm
 
that looks fine.

what's the exact error you're getting?
Re: PImage stored in class?
Reply #2 - Jan 23rd, 2010, 2:35pm
 
you might need to make your Car constructor public
Re: PImage stored in class?
Reply #3 - Jan 24th, 2010, 1:20am
 
Move your car creation into setup() (keeping the declaration outside).
loadImage() called outside is executed before setup(), but only at setup() time the path to the data folder is known.
Page Index Toggle Pages: 1