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

2013/9/29

my animtion is not working??

finbololz finbololz

2013/9/29

#
I tried adding an animation to my player but when I place my player In the world he vanishes and I get a greenfoot terminal window saying the image was not found even though I put it in the greenfoot folder can any1 help? ps.its a platformer
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class player here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class player extends Actor
 {
     private int speed = 4;
     private int vSpeed = 0;
     private int acceleration = 1;
     private int jumpStrength = 9;
     
     private GreenfootImage moveLeft1 = new GreenfootImage("playerleftrun1.gif");
     private GreenfootImage moveLeft2 = new GreenfootImage("playerleftrun2.gif");
     private GreenfootImage moveRight1 = new GreenfootImage("playerrightrun1.gif");
     private GreenfootImage moveRight2 = new GreenfootImage("playerrightrun2.gif");
     private int frame = 1;
    /**
     * Act - do whatever the player wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
       checkKeys();
       checkfall();
    }   
    
    
    private void checkKeys()
    {
        if (Greenfoot.isKeyDown("left") )
        {
            setImage("player-left.gif");
            moveLeft();
    }
     if (Greenfoot.isKeyDown("right") )
    {
            setImage("player-right.gif");
            moveRight();
    }
    if (Greenfoot.isKeyDown("up") )    {
            jump();
    }
   }
   
   public void jump()
   {
       vSpeed = -jumpStrength;
       fall();
       
    }
   
   public void checkfall()
   {
    if(onGround()) {
        vSpeed = 0;
        
    }
    else{
         fall();
    }
   }
    
   public boolean onGround()
    {
     Actor under = getOneObjectAtOffset( 0, getImage().getHeight() / 2 , platform.class);
     return under != null;
    }
    
   public void fall()
   {
     setLocation ( getX(), getY() + vSpeed);
     vSpeed = vSpeed + acceleration;
  
    } 
    
   public void moveRight()
   {
       setLocation ( getX() + speed, getY() );
       animateRight();
    }
    
    public void animateRight()
    {
        if(frame == 1)
        {
           setImage(moveRight1);    
    
        }
        else if(frame ==2)
        {
            setImage(moveRight2);  
            frame = 1;
            return;
        }
        
        frame ++;
    }
    
    public void moveLeft()
    {
        setLocation ( getX() - speed, getY() );
        animateLeft();
    }
    
    
    public void animateLeft()
    {
        if(frame == 1)
        {
           setImage(moveLeft1);    
    
        }
        else if(frame ==2)
        {
            setImage(moveLeft2);  
            frame = 1;
            return;
        }
        
        frame ++;
}
}
Gevater_Tod4711 Gevater_Tod4711

2013/9/29

#
I think there are two things that can cause this problem: The first: Are you shure that your spelling of the image names is right? The second: Have you saved the image in the greenfoot folder or did you create a new folder in the greenfoot folder? If you have another folder in your greenfoot folder you need to access the image like this: new GreenfootImage("FolderName/ImageName.png").
finbololz finbololz

2013/9/29

#
thanx its working now
You need to login to post a reply.