added the image in the MenuWorld
import greenfoot.*;
public class MenuSelector extends Actor
{
Actor[] boxes; // to hold the objects to cycle among
int onBox; // index pointer to 'boxes' array (currently highlighted actor)
boolean rightDown; // last state of 'right' key
public MenuSelector(Actor[] actors)
{
boxes = actors; // save actors to cycle among
}
// highlight actor pointed to in array when added into world
protected void addedToWorld(World world)
{
updateLocation();
}
// highlight actor pointed to in array
private void updateLocation()
{
setLocation(boxes[onBox].getX(), boxes[onBox].getY());
}
// allow cycling of highlight among actors
public void act()
{
if (rightDown != Greenfoot.isKeyDown("right")) // is state of key changed
{
rightDown = ! rightDown; // save new state
if (rightDown) // if new state is "pressed"
{
onBox = (onBox+1)%boxes.length; // pointt to next index (with wrapping)
updateLocation(); // highlight actor now pointed at in array
}
}
}
}public class MainMenu extends World
{
/**
* Constructor for objects of class MainMenu.
*
*/
public MainMenu()
{
// Create a new world
super(25*48, 14*48, 1);
GreenfootImage Bg = new GreenfootImage("Background.jpg");
//scaling the image
Bg.scale(getWidth(), getHeight());
setBackground (Bg);
//Adding title
Title title = new Title ();
addObject (title, 610, 122);
//Adding text object for the menu
addObject (new Text ("Pokemon"), 458, 336);
addObject (new Text ("Items"), 809, 330);
addObject (new Text ("Map"), 654, 487);
//Adding the rectangle image
Selector select = new Selector ();
addObject (select, 458, 336);
}
public void act(){
if (Greenfoot.isKeyDown("enter") && Trigger.detected()) {
WalkingWorld.WorldNumber = 1;
WalkingWorld.CurrentWorld = 1;
Greenfoot.setWorld(new InsideArea(50));
}
Trigger.update();
}
}Text[] textBoxes = {new Text("Pokemon"), new Text("Items"), new Text("Map")};
addObject(textBoxes[0], 458, 336);
addObject(textBoxes[1], 809, 330);
addObject(textBoxes[2], 654, 487);
addObject(new MenuSelector(textBoxes), 0, 0);public class Selector extends Actor
{
public Selector ()
{
GreenfootImage image1= getImage ();
image1.scale (image1.getWidth () -200, image1.getHeight ()-300);
setImage (image1);
}