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

2024/5/10

Other

Alexnikolaidou Alexnikolaidou

2024/5/10

#
I have no syntax errors. How do I display the objects in my world ?
danpost danpost

2024/5/10

#
Alexnikolaidou wrote...
I have no syntax errors. How do I display the objects in my world ?
import greenfoot.*;

public class MyWorld extends World
{
    public MyWorld()
    {
        super(800, 600, 1);
        /**  CREATE AND ADD AN OBJECT INTO WORLD */
        Actor object = getActor(); // to reference an Actor object
        addObject(object, 400, 300); // actor is put in world
    }
    
    // doesn't matter what type of Actor object is used
    /**  DON"T ACTUALLY USE THE FOLLOWING */
    // just returns an Actor object
    private Actor getActor()
    {
        return new Actor(){};
    }
}
All Actor objects are given an image (at least to start with). You can create an Actor object by using any subclass of Actor (any class that extends beyond Actor). An image can be set as the default image for objects of its class or an image can be created and assigned to the object (you know,
setImage(new GreenfootImage(...));
). If an image is not specified for any Actor object, it will be given the default greenfoot image (a green foot).
You need to login to post a reply.