This site requires JavaScript, please enable it in your browser!
Greenfoot back
WizardGamer
WizardGamer wrote ...

2 days ago

Adding Title Screen Music

WizardGamer WizardGamer

2 days ago

#
I want to add music to my title screen, but I can not get the music to play. Here is my code. Any suggestions?
GreenfootSound music = new GreenfootSound("TitleMusic.wav");

public void backgroundMusic(){
        music.playLoop();
    }
    
    public void titleScreen(){
        if(getBackground()==image1){
            backgroundMusic();
            setBackground(image2);
            Greenfoot.delay(25);
        }
        else if(getBackground()==image2){
            setBackground(image3);
            Greenfoot.delay(13);
        }
danpost danpost

2 days ago

#
WizardGamer wrote...
I want to add music to my title screen, but I can not get the music to play. Here is my code. Any suggestions? << Code Omitted >>
Please show the entire class.
WizardGamer WizardGamer

2 days ago

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)


public class Title extends World
{
   
    GreenfootImage image1 = new GreenfootImage("Game Title-1.png");
    GreenfootImage image2 = new GreenfootImage("Game Title-2.png");
    GreenfootImage image3 = new GreenfootImage("Game Title (Final)-3.png.png");
    GreenfootImage image4 = new GreenfootImage("Game Title (Final)-4.png.png");
    GreenfootImage image5 = new GreenfootImage("Game Title (Final)-5.png.png");
    GreenfootImage image6 = new GreenfootImage("Game Title (Final)-6.png.png");
    GreenfootImage image7 = new GreenfootImage("Game Title (Final)-7.png.png");
    GreenfootImage image8 = new GreenfootImage("Game Title (Final)-8.png.png");
    GreenfootImage image9 = new GreenfootImage("Game Title (Final)-9.png.png");
    GreenfootImage image10 = new GreenfootImage("Game Title (Final)-10.png.png");
    GreenfootImage image11 = new GreenfootImage("Game Title (Final)-11.png.png");
    GreenfootImage image12 = new GreenfootImage("Game Title (Final)-12.png.png");
    GreenfootImage image13 = new GreenfootImage("Game Title (Final)-13.png.png");
    GreenfootImage image14 = new GreenfootImage("Game Title (Final)-14.png.png");
    GreenfootImage image15 = new GreenfootImage("Game Title (Final)-15.png.png");
    GreenfootImage image16 = new GreenfootImage("Game Title (Final)-16.png.png");
    GreenfootImage image17 = new GreenfootImage("Game Title (Final)-17.png.png");
    GreenfootImage image18 = new GreenfootImage("Game Title (Final)-18.png.png");
    GreenfootImage image19 = new GreenfootImage("Game Title (Final)-19.png.png"); 
    GreenfootImage image20 = new GreenfootImage("Game Title (Final)-20.png.png");
    GreenfootImage image21 = new GreenfootImage("Game Title (Final)-21.png.png");
    GreenfootImage image22 = new GreenfootImage("Game Title (Final)-22.png.png");
    GreenfootImage image23 = new GreenfootImage("Game Title (Final)-23.png.png");
    GreenfootImage image24 = new GreenfootImage("Game Title (Final)-24.png.png");
    GreenfootImage image25 = new GreenfootImage("Game Title (Final)-25.png.png");
    GreenfootImage image26 = new GreenfootImage("Game Title (Final)-26.png.png");
    GreenfootImage image27 = new GreenfootImage("Game Title (Final)-27.png.png");
    GreenfootImage image28 = new GreenfootImage("Game Title (Final)-28.png.png");
    GreenfootImage image29 = new GreenfootImage("Game Title (Final)-29.png.png");
    GreenfootImage image30 = new GreenfootImage("Game Title (Final)-30.png.png");
    GreenfootImage image31 = new GreenfootImage("Game Title (Final)-31.png.png");
    GreenfootImage image32 = new GreenfootImage("Game Title (Final)-32.png.png");
    GreenfootImage image33 = new GreenfootImage("Game Title (Final)-33.png.png");
    GreenfootImage image34 = new GreenfootImage("Game Title (Final)-34.png.png");
    GreenfootImage image35 = new GreenfootImage("Game Title (Final)-35.png.png");
    GreenfootImage image36 = new GreenfootImage("Game Title (Final)-36.png.png");
    GreenfootImage image37 = new GreenfootImage("Game Title (Final)-37.png.png");
    GreenfootImage image38 = new GreenfootImage("Game Title (Final)-38.png.png");
    GreenfootImage image39 = new GreenfootImage("Game Title (Final)-39.png.png"); 
    GreenfootImage image40 = new GreenfootImage("Game Title (Final)-40.png.png");
    GreenfootImage image41 = new GreenfootImage("Game Title (Final)-41.png.png");
    GreenfootImage image42 = new GreenfootImage("Game Title (Final)-42.png.png");
    GreenfootImage image43 = new GreenfootImage("Game Title (Final)-43.png.png");
    GreenfootImage image44 = new GreenfootImage("Game Title (Final)-44.png.png");
    GreenfootImage image45 = new GreenfootImage("Game Title (Final)-45.png.png");
    GreenfootImage image46 = new GreenfootImage("Game Title (Final)-46.png.png");
    GreenfootImage image47 = new GreenfootImage("Game Title (Final)-47.png.png");
    GreenfootImage image48 = new GreenfootImage("Game Title (Final)-48.png.png");
    GreenfootImage image49 = new GreenfootImage("Game Title (Final)-49.png.png");
    
    GreenfootSound music = new GreenfootSound("TitleMusic.wav");

    /**
     * Constructor for objects of class Title.
     * 
     */
    public Title()
    {    
        // Create a new world with 512x288 cells with a cell size of 1x1 pixels.
        super(512,288, 1); 

        addObject(new Box(),448,229); //just black box in corner
        setBackground(image1);
    }

    public void act(){
        titleScreen();
    }
    
    public void backgroundMusic(){
        music.playLoop();
    }
    
    public void titleScreen(){
        if(getBackground()==image1){
            backgroundMusic();
            setBackground(image2);
            Greenfoot.delay(25);
        }
        else if(getBackground()==image2){
            setBackground(image3);
            Greenfoot.delay(13);
        }
        else if(getBackground()==image3){
            setBackground(image4);
            Greenfoot.delay(13);
        }
        else if(getBackground()==image4){
            setBackground(image5);
            Greenfoot.delay(13);
        }
        else if(getBackground()==image5){
            setBackground(image6);
            Greenfoot.delay(13);
        }
        else if(getBackground()==image6){
            setBackground(image7);
            Greenfoot.delay(13);
        }
        else if(getBackground()==image7){
            setBackground(image8);
            Greenfoot.delay(13);
        }
        else if(getBackground()==image8){
            setBackground(image9);
            Greenfoot.delay(13);
        }
        else if(getBackground()==image9){
            setBackground(image10);
            Greenfoot.delay(13);
        }
        else if(getBackground()==image10){
            setBackground(image11);
            Greenfoot.delay(13);
        }
        else if(getBackground()==image11){
            setBackground(image12);
            Greenfoot.delay(13);
        }
        else if(getBackground()==image12){
            setBackground(image13);
            Greenfoot.delay(13);
        }
        else if(getBackground()==image13){
            setBackground(image14);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image14){
            setBackground(image15);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image15){
            setBackground(image16);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image16){
            setBackground(image17);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image17){
            setBackground(image18);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image18){
            setBackground(image19);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image19){
            setBackground(image20);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image20){
            setBackground(image21);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image21){
            setBackground(image22);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image22){
            setBackground(image23);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image23){
            setBackground(image24);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image24){
            setBackground(image25);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image25){
            setBackground(image26);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image26){
            setBackground(image27);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image27){
            setBackground(image28);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image28){
            setBackground(image29);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image29){
            setBackground(image30);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image30){
            setBackground(image31);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image31){
            setBackground(image32);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image32){
            setBackground(image33);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image33){
            setBackground(image34);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image34){
            setBackground(image35);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image35){
            setBackground(image36);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image36){
            setBackground(image37);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image37){
            setBackground(image38);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image38){
            setBackground(image39);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image39){
            setBackground(image40);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image40){
            setBackground(image41);
            Greenfoot.delay(10);
        }       

        else if(getBackground()==image41){
            setBackground(image42);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image42){
            setBackground(image43);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image43){
            setBackground(image44);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image44){
            setBackground(image45);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image45){
            setBackground(image46);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image46){
            setBackground(image47);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image47){
            setBackground(image48);
            Greenfoot.delay(10);
        }
        else if(getBackground()==image48){
            setBackground(image49);
            Greenfoot.delay(10);
            addObject(new Start(),433,264); 
        }
        else {
            setBackground(image1); 
        }
     }
    }


danpost danpost

2 days ago

#
WizardGamer wrote...
<< Code Omitted >>
Where are you calling the backgroundMusic method from?
WizardGamer WizardGamer

2 days ago

#
What do you mean by from? Do you mean in the code? I have it on line 82 of the code.
danpost danpost

2 days ago

#
WizardGamer wrote...
What do you mean by from? Do you mean in the code? I have it on line 82 of the code.
Oh, I see (missed it there). Okay -- line 81 compares two images that are not the same image. If fact, none of your image comparisons throughout the method will ever be true. Greenfoot creates and retains a new image (do to possible tiling of the image) for the background. Add a field to hold the current image and assign each image to it before setting the background image with them. Then use the field for your comparisons.
WizardGamer WizardGamer

2 days ago

#
The music is playing now. Thank you!
You need to login to post a reply.