Here I am again! Now I want to change Backgrounds by clicking the left or right arrow.That's what I've done so far, but I want to change the background to "c" if the current background is "b" and this doesn't happen and I've tried this with so many ways to the whole code as an example: Please I need some help.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Home here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Home extends World
{
/**
* Constructor for objects of class Home.
*
*/
public Home()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
setBackground("a.png");
Greenfoot.setSpeed(30);
}
public World inventory = new Inventory(this);
public void changeBackground()
{
GreenfootImage a = new GreenfootImage("a.png");
GreenfootImage b = new GreenfootImage("b.png");
GreenfootImage c = new GreenfootImage("c.png");
key key=new key();
if (Greenfoot.isKeyDown("right")&& inventory.getObjects(key.class).size()==0) {
setBackground(b);
addObject(key,300,300);
}
else if( Greenfoot.isKeyDown("right") && inventory.getObjects(key.class).size()!=0 )
{setBackground(b);}
if ( Greenfoot.isKeyDown("right")
setBackground(c);
if(Greenfoot.isKeyDown("left")){
setBackground(a);
}
if (Greenfoot.isKeyDown("i")){
Greenfoot.setWorld(inventory);
}
}
}
public void act() {
changeBackground();
}
}
if ( Greenfoot.isKeyDown("right")&& this.getBackground()==b ){
setBackground(boy);
}


