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

2014/3/17

cannot find symbol - variable Actor

nicole1996 nicole1996

2014/3/17

#
Whenever I try to compile my code it comes up with the error "cannot find symbol - variable Actor". When I click on the question mark, it says that I am using a variable name that hasn't been declared. I read the instructions but it's still really unclear to me, I kind of just want a straight answer as to what I've done wrong here. I've copied the code from YouTube tutorials, and it's work for them, and I don't know what I'm doing wrong. I'm creating a platformer. Thanks.
import greenfoot.*;

/**
* A small demo of a jumping movement
*
* @author N Reynolds
* @version 1.0
*/
public class Girl extends Actor 
{
    private int speed = 3;   // running speed (sideways)
    private int vSpeed = 0;
    private int acceleration = 2;
    private int jumpStrength = 5;
    private int spriteHeight; 
    private int lookForGround;
    
    private GreenfootImage R1 = new GreenfootImage("R1.png");
    private GreenfootImage R2 = new GreenfootImage("R2.png");
    private GreenfootImage R3 = new GreenfootImage("R3.png");
    
    private GreenfootImage L1 = new GreenfootImage("L1.png");
    private GreenfootImage L2 = new GreenfootImage("L2.png");
    private GreenfootImage L3 = new GreenfootImage("L3.png");
    
    private int frame = 1;
    private int animationCounter = 0;

    /**
    * Cehck keyboard input and act accordingly
    */
    public void act()
    {
        checkKeys();
        checkFall();
        
        
        
        
        animationCounter ++;
    }


    private void checkKeys()
    {
        if (Greenfoot.isKeyDown("left"))
        {
            setImage("L1.png");
            setImage("L2.png");
            setImage("L3.png");
            moveLeft();
        }
        if (Greenfoot.isKeyDown("right"))
        {
            setImage("R1.png");
            setImage("R2.png");
            setImage("R3.png");
            moveRight();
        }
        if (Greenfoot.isKeyDown("space"))
        {
            jump();
        }
    }
    public void jump()
    {
        vSpeed = -jumpStrength;
        fall();
    }
    public void checkFall()
    {
        if(onGround()) {
            vSpeed = 0;
        }
        else {
            fall();
        }
    }
           
            
    public boolean onGround()
    {
        spriteHeight = getImage().getHeight(); 
        lookForGround = (spriteHeight/ 2)- 8;
        
        Actor ground = getOneObjectAtOffset( 0, spriteHeight , PlatformOne.class);
        if(ground == null)
        {
        return false;
        }
        else
        {
         return true;   
        }
    }
    public boolean platformAbove()
    {
        int spriteHeight = getImage().getHeight(); 
        int yDistance = (int) (spriteHeight/ 2 + 5);
        lookForGround = 
        
        Actor; ground = getOneObjectAtOffset( 0, getImage, getHeight()/2, PlatformOne.class);
        if(ground == null)
        {
        return false;
        }
        else
        {
         return true;   
        }
    }
    
    public void fall()
    {
        setLocation ( getX(), getY() + vSpeed);
        vSpeed = vSpeed + acceleration;
    }
    public void moveRight()
    {
        setLocation ( getX() + speed, getY() );
        
        if (animationCounter % 2 == 0)
        animateRight();
    }

    public void animateRight()
    {
        if (frame == 1)
        {
            setImage(R1);
        }
       else if (frame == 2)
       {
           setImage(R2);
       }
        else if (frame == 3)
       {
           setImage(R3);
           frame = 1;
           return;
       }
       
       frame ++;
    }

    public void moveLeft()
    {
        setLocation ( getX() - speed, getY() );
        
        if (animationCounter % 2 == 0)
        animateLeft();
    }
    
        public void animateLeft()
    {
        if (frame == 1)
        {
            setImage(L1);
        }
       else if (frame == 2)
       {
           setImage(L2);
       }
        else if (frame == 3)
       {
           setImage(L3);
           frame = 1;
           return;
       }
       
       frame ++;
    }
}
danpost danpost

2014/3/17

#
Line 102 has a semi-colon after the word 'Actor' which should not be there.
You need to login to post a reply.