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

2015/1/13

HELP!! sound used to work but not anymore

Dan123 Dan123

2015/1/13

#
just want there to be any music in the background code for balloons: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class balloon here. * * @author (your name) * @version (a version number or a date) */ public class balloon extends Actor { /** * Act - do whatever the balloon wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(15); setRotation(Greenfoot.getRandomNumber(540));} } code for ball :import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class GoldenBall here. * * @author (your name) * @version (a version number or a date) */ public class GoldenBall extends Actor { /** * Act - do whatever the GoldenBall wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { key(); win(); checkballoon(); } public boolean canMove(int x, int y) { Actor sand; sand=getOneObjectAtOffset(x,y,sandroad.class); //the section below checks if there is a block you can move to // if there is it sets sand to a vlaue otherwise it says null // The errors are in this section boolean flag=false; if (sand !=null) { flag=true; } return flag; } /** * Check if ball hits balloon */ private void checkballoon() { Actor balloon= getOneIntersectingObject(balloon.class); if (balloon !=null ) { getWorld().removeObject(balloon); } } public void key() { //Note 1: Down the page increase the y value and going to the right increases the x value //Note 2: Each block is 60 pixels wide and high int leftChange=-60; int rightChange=60; int upChange=-60; int downChange=60; if (Greenfoot.isKeyDown("left")) { if (canMove(leftChange, 0)==true){ setLocation(getX()+leftChange, getY()) ;} } if (Greenfoot.isKeyDown("right")) { if (canMove(rightChange, 0)==true){ setLocation(getX()+rightChange, getY()) ;} } if (Greenfoot.isKeyDown("up")) { if (canMove(0, upChange)==true){ setLocation(getX(), getY()+upChange) ;} } if (Greenfoot.isKeyDown("down")) { if (canMove(0, downChange)==true){ setLocation(getX(), getY()+downChange) ;} } } public void win() { Actor win; win=getOneObjectAtOffset(0,0,Goal.class); if (win !=null) { Greenfoot.stop(); } } int count = 0; {if (balloon !=null ) { getWorld().removeObject(balloon); count++; example EXAMPLE = new example(); } act(); { getWorld().addObject(example) ; } //Create a new class, example act(); { setImage((new GreenfootImage("Counter : " + count,50,Color.GREEN,new Color(0,0,0,0)))); } } } ; }
xFabi xFabi

2015/1/13

#
press code, at the left bot to include code..
like()
{
this
okay()?
}
You didnt include any sound commands, how can you expect it to play sound then o.o?
Dan123 Dan123

2015/1/13

#
oh sorry sound plays constantly but i want it to play when ball collects a balloon Balloon code:
public void act() 
    {
       move(15);
       setRotation(Greenfoot.getRandomNumber(540)); 
       
       Greenfoot.playSound("1shot2shine.wav");
       
     
      
       
    }    
}
ball code:
public void act() 
    {
        key();
        win();
        checkballoon();

       
    }    
    public boolean canMove(int x, int y)
    {
        
        Actor sand;
        sand=getOneObjectAtOffset(x,y,sandroad.class);
        
        //the section below checks if there is a block you can move to
        // if there is it sets sand to a vlaue otherwise it says null
        // The errors are in this section
        boolean flag=false;
        if (sand !=null)
        {
            flag=true;
        }
        return flag;
    }
    /**
     * Check if ball hits balloon
     */
    private void checkballoon()
    {
        Actor balloon= getOneIntersectingObject(balloon.class);
        
        if (balloon !=null ) 
        
        {   
            getWorld().removeObject(balloon);
          
        }
            
        
    
    
    }
        
    public void key()
    {
       //Note 1: Down the page increase the y value and going to the right increases the x value
       //Note 2: Each block is 60 pixels wide and high 
        int leftChange=-60;
       int rightChange=60; 
       int upChange=-60;
       int downChange=60;
        if (Greenfoot.isKeyDown("left"))
        {
            if (canMove(leftChange, 0)==true){
            setLocation(getX()+leftChange, getY()) ;}
        }
        if (Greenfoot.isKeyDown("right"))
        {
           if (canMove(rightChange, 0)==true){
            setLocation(getX()+rightChange, getY()) ;}
        }
        if (Greenfoot.isKeyDown("up"))
        {
            if (canMove(0, upChange)==true){
            setLocation(getX(), getY()+upChange) ;}
        }
        if (Greenfoot.isKeyDown("down"))
        {
            if (canMove(0, downChange)==true){
            setLocation(getX(), getY()+downChange) ;}
        }
    }
    public void win()
    {
        Actor win;
        win=getOneObjectAtOffset(0,0,Goal.class);
        if (win !=null)
        {
            Greenfoot.stop();
        }

    }
    
    
}
xFabi xFabi

2015/1/13

#
Dan123 wrote...
oh sorry sound plays constantly but i want it to play when ball collects a balloon Balloon code:
public void act() 
    {
       move(15);
       setRotation(Greenfoot.getRandomNumber(540)); 
       Actor a = getOneIntersectingObject(ball.class);
       if(a!=null)
{
       Greenfoot.playSound("1shot2shine.wav");
 }      
     
}
Im out for now, school 'n stuff, wait for dan to reply if you've got any more questions
Dan123 Dan123

2015/1/13

#
dont worry fixed it
You need to login to post a reply.