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

2021/11/18

hey im trying to get this to do an animation but it just keeps bringing up an error

whitecrow whitecrow

2021/11/18

#
the error that the image file does not exist so can you help meeeeeeee oh and the error states that it cannot set breakpoint:no code in this line and yes this is a fnf fan game
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class BOYFREIND here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class BOYFREIND extends Actor
{
    private int vSpeed= 0;
    private int acceleration= 2;
    private GreenfootImage BOYFRIEND_Copy05=new GreenfootImage("BOYFRIEND_Copy05.png");
    private GreenfootImage BOYFRIEND_Copy05_Copy=new GreenfootImage("BOYFRIEND_Copy05_Copy.png");
    private GreenfootImage BOYFRIEND_Copy05_Copy01=new GreenfootImage("BOYFRIEND_Copy05_Copy01.png");
    private GreenfootImage BOYFRIEND_Copy06=new GreenfootImage("BOYFRIEND_Copy06.png");
    private GreenfootImage BOYFRIEND_Copy07=new GreenfootImage("BOYFRIEND_Copy07.png");
    private GreenfootImage BOYFRIEND_Copy03=new GreenfootImage("BOYFRIEND_Copy03.png");
    private GreenfootImage BOYFRIEND_Copy04=new GreenfootImage("BOYFRIEND_Copy04.png");
    private GreenfootImage BOYFRIEND = new GreenfootImage("BOYFRIEND.png");
    private GreenfootImage BOYFRIEND_Copy=new GreenfootImage("BOYFRIEND_Copy.png");
    private GreenfootImage BOYFRIEND_Copy01=new GreenfootImage("BOYFRIEND_Copy01.png");
    private GreenfootImage BOYFRIEND_Copy02=new GreenfootImage("BOYFRIEND_Copy02.png");
    private GreenfootImage BOYFRIEND_Copy02_copy=new GreenfootImage("BOYFRIEND_Copy02_Copy.png");
    private int frame = 1;
    /**
     * Act - do whatever the BOYFREIND wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        checkKey ();// Add your action code here.
    }   

    public void AnimateLeft()
    {
        if(frame==1)
        {
            setImage("BOYFRIEND_Copy03");
        }
        else if (frame == 2)
        {
            setImage("BOYFRIEND_Copy04");
            frame=1;
            return;
        }
        frame ++;
    }

    public void AnimateRight()
    {
        if(frame==1)
        {
            setImage("BOYFRIEND_Copy05");
        }
        else if(frame==2)
        {
            setImage("BOYFRIEND_Copy05_Copy");
            frame =1;
            return;
        }
        frame ++;
    }

    public void checkKey()
    {
        if(Greenfoot.isKeyDown("right"))
        {
            AnimateRight();  
        }
        if(Greenfoot.isKeyDown("left"))
        {
            AnimateLeft();
        }
    }
}
danpost danpost

2021/11/18

#
Copy/paste error message.
Spock47 Spock47

2021/11/29

#
danpost is right: It is always easier to solve a problem if the error message is given. Here, especially the information which line throws the error, is most relevant. From looking at the source code, I guess that in lines 39, 43, 54 and 58 you actually want to use the images defined in the attributes at the beginning. For referencing variables, you just use the name without quotation marks. So, removing the quotation marks in these lines should solve your problem, e.g.:
setImage(BOYFRIEND_Copy03);

Live long and prosper, Spock47
whitecrow whitecrow

2021/11/30

#
hey guys I've got it fixed now but now the idle animation for when I don't press any thing won't work and I've been trying for several months now and it still won't
public void playIdleAnimation ()
    {
        AnimateLeft=false;
        {
            idleAnimation();
        }
    }
like everything is working except the idle animation

    public void idleAnimation()
    {
        if(frame==1)
        {
            setImage("BOYFRIEND_Copy");
            frame=2;
            return;
        }
        else if (frame ==2)
        {
            setImage("BOYFRIEND_Copy01");
            frame=3;
            return;
        }
        else if (frame ==3)
        {
            setImage("BOYFRIEND_Copy02");
            frame=4;
            return;
        }
        else if (frame ==4)
        {
            setImage("BOYFRIEND_Copy02_Copy");
            frame=1;
            return;
        }
        frame++;
    }
work
Spock47 Spock47

2021/11/30

#
Can you please provide the complete source code of the class? Also: please describe 1. what is the behavior you expect (what it should do) and 2. what is the actual behavior (what it currently does instead of the wanted behavior)? Live long and prosper, Spock47
danpost danpost

2021/12/1

#
The boolean animateLeft is not good enough for your needs. It only has two states, but you have 3 animation sets (left, right AND idle). An int value would be more appropriate to track which animation is being used. The best values for each set are '-1' for left, '0' for idle and '1' for right. By adding 1 to the animation set value, simple indices can be acquired (0, 1, and 2), which leads to the opportunity of placing the animation sets in an array. Sample code might look like this:
private GreenfootImage[][] imgSets = new GreenfootImage[3]; // animation sets [0]-left, [1]-idle, [2]-right
private int imgSet = 1; // current animation (idle to start)
private int frame; // current frame of current animation

public BOYFRIEND()
{
    // left images
    imgSets[0] = new GreenfootImage[]
    {
        new GreenfootImage("BOYFRIEND_COPY03.png"),
        new GreenfootImage("BOYFRIEND_COPY04.png")
    };
    // idle images
    imgSets[1] = new GreenfootImage[]
    {
        new GreenfootImage("BOYFRIEND_COPY.png"),
        new GreenfootImage("BOYFRIEND_COPY01.png"),
        new GreenfootImage("BOYFRIEND_COPY02.png"),
        new GreenfootImage("BOYFRIEND_COPY02_COPY.png")
    };
    // right images
    imgSets[2] = new GreenfootImage[]
    {
        new GreenfootImage("BOYFRIEND_COPY05.png"),
        new GreenfootImage("BOYFRIEND_COPY05_COPY.png")
    };
    setImage(imgSets[imgSet][frame]); // initial image
}

public void act()
{
    int dx = 0;
    if (Greenfoot.isKeyDown("left")) dx--;
    if (GreenfootisKeyDown("right")) dx++;
    imgSet = dx+1;
    frame = (frame+1)%(imgSets[imgSet].length);
    setImage(imgSets[imgSet][frame]);
}
Unfortunately, I am not aware of what the other images in your code are for. So, it is unknown how to incorporate them into the above code.
You need to login to post a reply.