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

4 days ago

animation for enemys

sufyaan sufyaan

4 days ago

#
public class monster extends Actor
{
    private GreenfootImage image1 = new GreenfootImage ("spr_monster_idle_0.png"); 
    private GreenfootImage image2 = new GreenfootImage ("spr_monster_idle_1.png"); 
    private int time = 0;
    public void act() 
    {
        if(time > 0){
            time --;}
            else{
        animate();
    }
    }  
    public void animate()
    { 
        if(getImage().equals("spr_monster_idle_0.png")){
        setImage("spr_monster_idle_1.png");
        time = 30;
    }
    else if(getImage().equals("spr_monster_idle_1.png")){
        setImage("spr_monster_idle_0.png");
        time = 30;
    }
    }
this is what i have written to animate the enemy, i've used a similar code in my player which works to animate for him. I have no clue of what's wrong with this code though
danpost danpost

4 days ago

#
sufyaan wrote...
<< Code Omitted >> this is what i have written to animate the enemy, i've used a similar code in my player which works to animate for him. I have no clue of what's wrong with this code though
Use your image names (image1 and image2) to compare (using '==') and set the actor's image to and remove the condition after else.
You need to login to post a reply.