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

2016/3/21

How do I animate an actor using 3 objects? I was only taught 2 and I coped it and just changed the numbers/names of the actors, but it doesn't work.

tn13673 tn13673

2016/3/21

#
 public void animation()
{
    
    if(frame == 1)
    {
        setImage(soldier-anim1);
        frame = 2;
    }
    
    else if(frame == 2)
    {
        setImage(soldier-anim2);
        frame = 1;
       
    }
    
    else if(frame == 3)
    {
        setImage(soldier-anim3);
        frame = 3;
        
    }
}
tn13673 tn13673

2016/3/21

#
Updated- tn13673 wrote...
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Survivor1 here. * * @author (your name) * @version (a version number or a date) */ public class Survivor1 extends Actor { public int frame = 1; GreenfootImage Survivor1 = new GreenfootImage("Survivor-anim1.png"); GreenfootImage Survivor2 = new GreenfootImage("Survivor-anim2.png"); /** * Act - do whatever the Survivor1 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. } public void animation() { if(frame == 1) { setImage(Survivor-anim1); frame = 2; } else if(frame == 2) { setImage(Survivor-anim2); frame = 1; } else if(frame == 3) { setImage(Survivor-anim3); frame = 3; } } }
tn13673 tn13673

2016/3/21

#
I got it fixed
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Survivor1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Survivor1 extends Actor
{
     public int frame = 1;
      GreenfootImage Survivor1 = new GreenfootImage("Survivor-anim1.png");
    GreenfootImage Survivor2 = new GreenfootImage("Survivor-anim2.png");
    /**
     * Act - do whatever the Survivor1 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
   
   }    
   
   
    public void animation()
{
    
    if(frame == 1)
    {
        setImage(Survivor1);
        frame = 2;
    }
    
    else if(frame == 2)
    {
        setImage(Survivor1);
        frame = 1;
       
    }
    
    else if(frame == 3)
    {
        setImage(Survivor1);
        frame = 3;
        
    }
}
}
You need to login to post a reply.