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

2012/4/27

i cannot get my sound to play *cannot find symbol- method playsound("fallenthing.wav");*

javafan88 javafan88

2012/4/27

#
(First, open the Leaf class. Take a look at the act() method. It calls two methods – falling() and checkForMiss(). The falling() method causes the leaves to flutter downwards. The checkForMiss() method checks to see if the baby missed the leaf – in other words, the leaf has hit the bottom without being caught. Add code to play the “fallenthing” sound (look in the images folder to find the file for this sound). This will go inside the IF clause. Test – everytime a leaf hits the bottom, you should hear this noise.) Above is part of my assignment, i cannot get the sound to compile it gives me an error saying cannot find symbol
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Leaf here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Leaf  extends Actor
{
        private GreenfootImage leaf0 = new GreenfootImage("cutoutleaf0.png");
        private GreenfootImage leaf1 = new GreenfootImage("cutoutleaf1.png");
        private GreenfootImage leaf2 = new GreenfootImage("cutoutleaf2.png");
        private GreenfootImage leaf3 = new GreenfootImage("cutoutleaf3.png");
        private int speed; //set the speed of each leaf

    public Leaf()
    {
    
        
        /* Change the image of the leaf depending on whether the random
         * number is 0, 1, 2, or 3. Also, rotate the object a random amount
         * to create the appearance of many leaves
         */
        
     
        speed = (Greenfoot.getRandomNumber(2)+1);//plus 1 to take care of speed 0
    }

    /**
     * Act - do whatever the Leaf wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        
        falling();
        checkForMiss();
    }   
    
   /**
    * falling - simulate the leaf falling to the ground.  Slowly rotate, change
    * course just a little horizontally each time through
    */
    public void falling()
    {
        int newX = Greenfoot.getRandomNumber(7) - 3; //gives me a # between -5 & 5
        setLocation(getX() + newX, getY()+speed);
        setRotation(getRotation() - 1); // have leaf slowly rotate

    }
    
    /**
     * checkForMiss - if the leaf hits the ground, it means the Catcher
     * did not catch the leaf. Remove the leaf object and do whatever you want 
     */
    public void checkForMiss(){
        if (getY()> getWorld().getHeight() - 25) 
        {    
        
            getWorld().removeObject(this);
            Greenfoot.playsound("fallenthing.wav");
        }
    }
 
}
javafan88 javafan88

2012/4/27

#
line 62 is where i am getting my issue
ttamasu ttamasu

2012/4/27

#
Method names are case sensitive. You have Greenfoot.playsound ("fallenthing.wav") , It should be Greenfoot.playSound ("fallenthing.wav") (Note that the "S" in sound should be capitalized). Also you may want to fix line 47 if you want random number from -5 to 5 it should be: int newX = Greenfoot.getRandomNumber(11) - 5; cheers Takashi
javafan88 javafan88

2012/4/28

#
thank you ttamasu it was the uppercase S that was the issue....yea i need a random number but i need the random number to link to different images so that different images appear. this is exactly the problem: Take a look at the constructor. Right now, all it does is set a speed for the leaves. Notice that there are 4 possible images for leaves, even though right now, only one image is displayed. Add code that generates a random number and uses that to decide which leaf image to display. That will make the display look more interesting. Test – you should see 4 kinds of leaves falling.
You need to login to post a reply.