I am trying to create a starting screen background for my first game in Processing and it keeps erroring with the following message:
>When not using the PDE, size() can only be used inside settings(). Remove the size() method from setup(), and add the following: public void settings() { size(800, 800); } IllegalStateException: size() cannot be used here, see https://processing.org/reference/size_.html Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help ? Troubleshooting.
I’ve tried to solve the problem by following the message and by searching around but I don’t manage to solve it.
this is the part for the background:
``` void setup() { bg = loadImage("rot.png"); size(800, 800); strokeWeight( 10 ); frameRate( 30 ); background(bg); ```
If needed I’ll send the whole part but this is where I believe the problem exist
thanks in advance
Advertisement
Answer
The settings()
method in processing has only been added in 3.0, and a lot of people just ignore it’s existence. It’s a great add, though, which permits stuff which the setup()
method didn’t (such as defining the window size using variables, for example).
Just move your size()
line in a new settings()
method, exactly as the program says.
(Also, if you are animating the sketch, you should draw the background in the draw()
loop.)
PImage bg; void settings() { size(800, 800); } void setup() { bg = loadImage("rot.png"); } void draw() { background(bg); }
Have fun!