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

2016/1/3

How to clear an image?

sheshank sheshank

2016/1/3

#
Here is my code in World: Title title = new Title(); NextPage nextpage = new NextPage(); /** * Constructor for objects of class GreenfootWorld. * */ public GreenfootWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); prepare(); if(Greenfoot.mouseClicked(nextpage)) { title.clearImage(); } } I dont have anything in next Page. in Title i have: public void act() { } public void clearImage(){ getImage().clear(); } I'm making a book and I'm trying to clear the title when the nextImage button is clicked. I'm sure I made a simple error because in the Greenfoot API it says clear() is the method. Please respond fast!!!
Super_Hippo Super_Hippo

2016/1/3

#
First, you need to add the Title object into the world. Add this line in the constructor of the 'GreenfootWorld' if it isn't in the 'prepare' method yet:
addObject(title, 100, 100); //change numbers to where ever it has to go
Then, the check for a mouse click should be in the act method, not in the constructor.
sheshank sheshank

2016/1/3

#
Thank you! I had the addObject line but I didn't see the constructor. I thought there was only the act method. Thanks a lot!
You need to login to post a reply.