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

2017/3/14

i need help cant find working code for background music

ninjaFI ninjaFI

2017/3/14

#
the mp3 is called "maskoff" and here is my world code
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class CopyOfworld1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class world1 extends World
{
    
    /**
     * Constructor for objects of class CopyOfworld1.
     * 
     */
    public world1()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1920, 1080, 1);
        prepare();
    }

    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {

        platform platform = new platform();
        addObject(platform,113,1041);
        platform platform2 = new platform();
        addObject(platform2,393,1036);
        platform platform3 = new platform();
        addObject(platform3,777,1036);
        platform platform4 = new platform();
        addObject(platform4,1043,1027);
        platform platform5 = new platform();
        addObject(platform5,566,1035);
        platform platform6 = new platform();
        addObject(platform6,1210,1037);
        platform platform7 = new platform();
        addObject(platform7,1371,1033);
        platform platform8 = new platform();
        addObject(platform8,1620,1044);
        platform platform9 = new platform();
        addObject(platform9,1829,1041);
        platform platform10 = new platform();
        addObject(platform10,1485,1043);
        platform.setLocation(101,1045);
        platform2.setLocation(300,1045);
        platform5.setLocation(498,1045);
        platform3.setLocation(697,1045);
        platform4.setLocation(894,1045);
        platform6.setLocation(1092,1045);
        platform7.setLocation(1287,1045);
        platform10.setLocation(1488,1044);
        platform10.setLocation(1486,1045);
        platform8.setLocation(1686,1045);
        platform9.setLocation(1829,1041);
        platform9.setLocation(1829,1041);
        platform9.setLocation(1829,1041);
        platform9.setLocation(1829,1041);
        platform9.setLocation(1829,1041);
        platform9.setLocation(1829,1041);
        platform9.setLocation(1880,1045);
        platform platform11 = new platform();
        addObject(platform11,1874,994);
        platform platform22 = new platform();
        addObject(platform22,840,820);
        platform platform23 = new platform();
        addObject(platform23,1245,626);
        platform platform24 = new platform();
        addObject(platform24,1591,473);
        platform platform25 = new platform();
        addObject(platform25,411,912);
        platform platform26 = new platform();
        addObject(platform26,1862,355);
        CopyofPlayer1 copyofplayer12 = new CopyofPlayer1();
        addObject(copyofplayer12,87,953);
        Enemy enemy4 = new Enemy();
        addObject(enemy4,918,732);
        Enemy enemy5 = new Enemy();
        addObject(enemy5,1661,396);
        Enemy enemy6 = new Enemy();
        addObject(enemy6,1818,909);
    }
}
Nosson1459 Nosson1459

2017/3/14

#
The following code will do the same thing as your (CopyOf)World1 code just it will also play a sound file called "maskoff.mp3" (I changed all the class names to start with a capital letter which is the proper way for them to be):
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class CopyOfWorld1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class World1 extends World
{
    /**
     * Constructor for objects of class CopyOfWorld1.
     * 
     */
    public World1()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1920, 1080, 1);
        prepare();
    }

    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {
        Platform platform = new Platform();
        addObject(platform,101,1045);
        Platform platform2 = new Platform();
        addObject(platform2,300,1045);
        Platform platform3 = new Platform();
        addObject(platform3,697,1045);
        Platform platform4 = new Platform();
        addObject(platform4,894,1045);
        Platform platform5 = new Platform();
        addObject(platform5,498,1045);
        Platform platform6 = new Platform();
        addObject(platform6,1092,1045);
        Platform platform7 = new Platform();
        addObject(platform7,1287,1045);
        Platform platform8 = new Platform();
        addObject(platform8,1686,1045);
        Platform platform9 = new Platform();
        addObject(platform9,1880,1045);
        Platform platform10 = new Platform();
        addObject(platform10,1486,1045);
        Platform platform11 = new Platform();
        addObject(platform11,1874,994);
        Platform platform22 = new Platform();
        addObject(platform22,840,820);
        Platform platform23 = new Platform();
        addObject(platform23,1245,626);
        Platform platform24 = new Platform();
        addObject(platform24,1591,473);
        Platform platform25 = new Platform();
        addObject(platform25,411,912);
        Platform platform26 = new Platform();
        addObject(platform26,1862,355);
        CopyofPlayer1 copyofplayer12 = new CopyofPlayer1();
        addObject(copyofplayer12,87,953);
        Enemy enemy4 = new Enemy();
        addObject(enemy4,918,732);
        Enemy enemy5 = new Enemy();
        addObject(enemy5,1661,396);
        Enemy enemy6 = new Enemy();
        addObject(enemy6,1818,909);
        
        Greenfoot.playSound("maskoff.mp3"); // line of code to play a sound file called "maskoff.mp3"
    }
}
You don't either need to create a separate object/field of each class to add but I left them just in case you'll be using all those fields later. Technically lines 28 - 67 can be:
addObject(new Platform(),101,1045);
addObject(new Platform(),300,1045);
addObject(new Platform(),697,1045);
addObject(new Platform(),894,1045);
addObject(new Platform(),498,1045);
addObject(new Platform(),1092,1045);
addObject(new Platform(),1287,1045);
addObject(new Platform(),1686,1045);
addObject(new Platform(),1880,1045);
addObject(new Platform(),1486,1045);
addObject(new Platform(),1874,994);
addObject(new Platform(),840,820);
addObject(new Platform(),1245,626);
addObject(new Platform(),1591,473);
addObject(new Platform(),411,912);
addObject(new Platform(),1862,355);
addObject(new CopyofPlayer1(),87,953);
addObject(new Enemy(),918,732);
addObject(new Enemy(),1661,396);
addObject(new Enemy(),1818,909);
You need to login to post a reply.