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

2019/9/29

How can I draw something?

ihjufaeshiju ihjufaeshiju

2019/9/29

#
I'm currently trying to draw a simple polygon onto the screen. As of now I can't see anything on the screen. I also need the xPoints and yPoints to be adjustable. How can I achieve that? Will I have to reconstruct the MyWorld class in order for the new xPoints and yPoints to be visible? I don't want them to only update on construction of the World. Inside of my Screen class, I have this code
    
    public void DrawScreen() {
        GreenfootImage screen = new GreenfootImage(300,200);
        screen.setColor(Color.RED);
        int[] xPoints = {0, 0, 10, 10};
        int[] yPoints = {10,0,0, 10  };
        screen.drawPolygon(xPoints, yPoints, 3); 
        this.setImage(screen);
    }
And the MyWorld constructor is as follows:
    
public MyWorld()
    {    
        super(600, 400, 1);
        Screen screen = new Screen();
        screen.DrawScreen();
    }
danpost danpost

2019/9/29

#
You would need to add the Screen actor into the world for it to be visible. Also, when drawing the polygon, the last value needs to match the number of elements in the arrays (4, not 3).
You need to login to post a reply.