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

2020/2/22

Can't stop updating text

Levantaj Levantaj

2020/2/22

#
I'm new in this programing language, but using the internet I am trying to make a game, but now i'm stuck at this point and it's so annoying.
public class ker1 extends Actor
{
    /**
     * Act - do whatever the ker1 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        int stone_speed = 4;
        setLocation( getX() - stone_speed, getY() );
        if (getX()==0) getWorld().removeObject(this);
        updateImage();
    }
    private void updateImage()
    {
        setImage(new GreenfootImage("" + getSplashes()[Greenfoot.getRandomNumber(getSplashes().length)], 20, null, null));
    }
    public static String[] getSplashes()
    {
        String[] splashes = {"cin>>a;", "cin>>b;", "cout<<boop;","cin>>a;","cout<<3;","cout<<a+b;","cout<<23;","cin>>n;","cin>>prim2;",
                             "cout<<a<<9;"};
        return splashes;
    }
}
danpost danpost

2020/2/22

#
The only problem I can see is the "null, null" on line 16. Replace them with Color objects -- like "Color.BLACK, new Color(0, 0, 0, 0)", for example.
danpost danpost

2020/2/23

#
Ah, okay. Remove line 12 and insert the following at line 3:
public ker1()
{
    updateImage();
}
This is a constructor block which will execute (once) when you create a new instance of the class.
Levantaj Levantaj

2020/2/23

#
Thanks!
You need to login to post a reply.