Hi, i have 2 world "Island" as the main world and "Info" which i implement danpost's crayon babies as the info world that come out when we click a button.
the info is array string from "Information" class. Everything is going well but when level is updated the current information is still displayed.
How can i call resetK method from "Island" world,
or how to reset this world from "Island" world?
this is my Info World
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * Write a description of class Info here. * * @author (your name) * @version (a version number or a date) */ public class Info extends World { World toWorld = null; private String[] E = Information.I; /** * Constructor for objects of class Info. * */ public Info(int value, World inWorld) //public Info(int value) { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. //super(750, 500, 1); super(1000, 600, 1); setMainImage(); // create a base image to work on resetK(); // add the appropriate information to the base image switch (value) { //case 0: imageZero(); break; // the MainWorld info case 1: imageOne(); break; // the MenuWorld info //case 2: imageTwo(); break; // the ImageWorld info } toWorld = inWorld; // save world to return to } /** * Method setMainImage: creates the base image that information will be added to */ private void setMainImage() { // create the image for the background GreenfootImage main = new GreenfootImage(getWidth(), getHeight()); main.setColor(Color.black); main.fill(); // set a flat black background // create images and draw them on the background GreenfootImage img = new GreenfootImage("INFORMATION", 36, Color.yellow, Color.black); main.drawImage(img, (main.getWidth() - img.getWidth()) / 2, 50); img = new GreenfootImage("(you are now in InfoWorld)", 18, Color.yellow, Color.black); main.drawImage(img, (main.getWidth() - img.getWidth()) / 2, 90); // draw separator lines on the background main.setColor(Color.yellow); main.drawLine(0, 125, 1000, 125); main.drawLine(0, 420, 1000, 420); setBackground(main); // set the background image } /** * Method imageOne: adds the information about MenuWorld to the base image */ //private void imageOne(int x) private void imageOne() { //String[] E = Knowledges.K; // retrieve the background image GreenfootImage main = getBackground(); // create text images and draw them on the background GreenfootImage img = new GreenfootImage(E[0], 18, Color.yellow, Color.black); main.drawImage(img, (main.getWidth() - img.getWidth()) / 2, 150); img = new GreenfootImage(E[1], 18, Color.yellow, Color.black); main.drawImage(img, (main.getWidth() - img.getWidth()) / 2, 200); img = new GreenfootImage(E[2], 18, Color.yellow, Color.black); main.drawImage(img, (main.getWidth() - img.getWidth()) / 2, 250); img = new GreenfootImage(E[3], 18, Color.yellow, Color.black); main.drawImage(img, (main.getWidth() - img.getWidth()) / 2, 300); img = new GreenfootImage(E[4], 18, Color.yellow, Color.black); main.drawImage(img, (main.getWidth() - img.getWidth()) / 2, 350); img = new GreenfootImage("Click anywhere to proceed to MenuWorld", 18, Color.yellow, Color.black); main.drawImage(img, (main.getWidth() - img.getWidth()) / 2, 440); } /** * Method act: returns to calling world when mouse is clicked */ public void act() { if (Greenfoot.mouseClicked(null)) Greenfoot.setWorld(toWorld); // change to calling world when the mouse is clicked } public void resetK() { // retrieve the background image GreenfootImage main = getBackground(); // create text images and draw them on the background GreenfootImage img = new GreenfootImage("Information 1", 18, Color.yellow, Color.black); main.drawImage(img, (main.getWidth() - img.getWidth()) / 2, 150); img = new GreenfootImage("Information 2", 18, Color.yellow, Color.black); main.drawImage(img, (main.getWidth() - img.getWidth()) / 2, 200); img = new GreenfootImage("Information 3", 18, Color.yellow, Color.black); main.drawImage(img, (main.getWidth() - img.getWidth()) / 2, 250); img = new GreenfootImage("Information 4", 18, Color.yellow, Color.black); main.drawImage(img, (main.getWidth() - img.getWidth()) / 2, 300); img = new GreenfootImage("Information 5", 18, Color.yellow, Color.black); main.drawImage(img, (main.getWidth() - img.getWidth()) / 2, 350); img = new GreenfootImage("Click anywhere to proceed to MenuWorld", 18, Color.yellow, Color.black); main.drawImage(img, (main.getWidth() - img.getWidth()) / 2, 440); } }