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

2015/2/11

Enquiry

1
2
danpost danpost

2015/2/11

#
You placed the code in the world constructor -- not in the world 'act' method. Currently, and by default, the World 'act' method is empty (void of any executable code). If you look at the World class API documentation, you will see that it is indeed present, however (just as in the Actor class). The class code should be as follows:
import greenfoot.*;

public class Background extends World
{
    public Background()
    {
        super(531, 709, 1);
        // any world preparation code
    }

    public void act()
    {
        if (getObjects(Food.class).isEmpty())
        {
            int x = Greenfoot.getRandomNumber(getWidth());
            int y = Greenfoot.getRandomNumber(getHeight());
            addObject(new Food(), x, y);
        }
    }

    // any other methods
}
Abanourmo Abanourmo

2015/2/11

#
You have helped me a lot. Thank you for your time ;-) I really appreciate your help. thank you again
You need to login to post a reply.
1
2