Hi!
I have 8 different backgroundimages , and I want a random one of them to change when the game starts and when the score of the Counter goes
up.I do not have any ideas to fixe it.Can you help me please?
Thank you,
Fifilein
private GreenfootImage[] backgroundImages =
{
new GreenfootImage("bg1.png");
new GreenfootImage("bg2.png");
new GreenfootImage("bg3.png");
new GreenfootImage("bg4.png");
new GreenfootImage("bg5.png");
new GreenfootImage("bg6.png");
new GreenfootImage("bg7.png");
new GreenfootImage("bg8.png");
}
//when you want a random one
setBackground(backgroundImages(Greenfoot.getRandomNumber(backgroundImages.length)));import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.awt.Font;
//( family=Baskerville Old Face,name=Bakerville Old Face,style=italic,size=22);
/**
* Write a description of class StartMenu here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class StartMenu extends World
{
StartGame sg = new StartGame();
private GreenfootImage[] backgroundImages =
{ new GreenfootImage("Hintergrund1.png");
new GreenfootImage("Hintergrund2.png");
new GreenfootImage("Hintergrund3.png");
new GreenfootImage("Hintergrund4.png");
new GreenfootImage("Hintergrund5.png");
new GreenfootImage("Hintergrund6.png");
new GreenfootImage("Hintergrund7.png");
new GreenfootImage("Hintergrund8.png");}
/**
* Constructor for objects of class StartMenu.
*
*/
public StartMenu() //level frogfly
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
setBackground(backgroundImages(Greenfoot.getRandomNumber(backgroundImages.length)));
getBackground().setFont(new Font("", 0, 60));
getBackground().setColor(Color.black);
getBackground().drawString("frogfly-Level 1", 140, 50);
getBackground().setFont(new Font("",0, 28));
getBackground().setColor(Color.black);
getBackground().drawString("Du bist der Frosch und drücke die", 20, 100);
getBackground().drawString("Pfeiltasten um dich zu bewegen.", 20, 140);
getBackground().drawString("Sammel alle Fliegen ein um zu gewinnen.", 20, 180);
getBackground().drawString("Aber pass vor der Schlange auf!", 20, 220);
{
addObject(sg, 300, 300 );
}
}
}e("Hprivate GreenfootImage[] backgroundImages =
{
new GreenfootImage("Hintergrund1.png"),
new GreenfootImage("Hintergrund2.png"),
new GreenfootImage("Hintergrund3.png"),
new GreenfootImage("Hintergrund4.png"),
new GreenfootImage("Hintergrund5.png"),
new GreenfootImage("Hintergrund6.png"),
new GreenfootImage("Hintergrund7.png"),
new GreenfootImage("Hintergrund8.png")
};setBackground(backgroundImages(Greenfoot.getRandomNumber(backgroundImages.length)));
setBackground(backgroundImages[Greenfoot.getRandomNumber(backgroundImages.length)]);