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 & HelpPrograms › Background Images
Page Index Toggle Pages: 1
Background Images (Read 344 times)
Background Images
Mar 28th, 2010, 10:00am
 
Hi everyone,
I've just started fiddling with images in Processing, and I've run into a bit of a problem.
I'd like to have an image bouncing on the screen, with another image as the background. Here's the code so far:
Code:
PImage img; //Variable for image file
//x location
float x=150;
//y location
float y=0;

float speed=0;
float gravity=.1;

void setup(){
 size(400,400);
 smooth();
//Image is from a screenshot of the game Polar Jump
 img= loadImage("jumpbear copy.jpg"); }

void draw(){
 background(255);
 image(img,x,y);
 
 //Add speed to location
 y=y+speed;
 
 //Add gravity to speed
 speed=speed+gravity;
 
 //If bear reaches bottom, reverse speed
 if(y>height-80){
   speed=speed*-.95;
 }
}


When I tried to add another image--clouds--as the background, I got a lot of errors. The background image shows just fine if it's by itself, like this:
Code:
PImage clouds=loadImage("clouds copy.jpg");
size(clouds.width, clouds.height);
background(clouds);


but I get a lot of errors when I try to add the background code to the bouncing bear code, no matter how I place or split up the background code. I'm sure I'm missing something simple, but being new to images, it's hard to tell what it is. Advice would be greatly appreciated.
Re: Background Images
Reply #1 - Mar 28th, 2010, 10:09am
 
the kind of errors you get would help us.
Re: Background Images
Reply #2 - Mar 28th, 2010, 10:26am
 
Sorry!

Actually, I managed to fix everything by messing with my code, but mostly I received 'NullPointerException' errors, I think.
Page Index Toggle Pages: 1