How do I convert a String to a PImage??
in
Programming Questions
•
1 years ago
Basically I have a levelManager class that is taking a string of background image PNG's and applying them to the load image of my background class depending on what level it is.
I've made a string for the images along with ints for other pieces of data that come from a levels.txt (which is formatted ok). the code that comes front he level manager looks like this:
String backgroundImage;
then the constructor, then:
void gotoLevel(int levelNumber)
{
if (levels.length > levelNumber)
{
//get the current level info as complete string
String level = levels[levelNumber];
//break level info into component parts
String[] levelInfo = level.split("\t");
//some more irrelevant data
backgroundImage = (levelInfo[3]);
//more data act..
}
}
then on my target(background) class, i have written:
PImage img;
then in the constructor:
img = loadImage(levelManager.backgroundImage);
then:
void display()
{
//unrelated data
//then:
image(img, xPos-60, yPos-60, width+100, height+100); //the image is meant to shake hense the oversizing
when i run this code i get a null pointer exception from the above line of code
does anyone have a method handy for extracting the name of an image from a text file and running it as a PImage??
any input would be appreciated,
Cheers then.
1