if I write this:
can I make it like it never happened ( remove it ) ?
getBackground().drawString("hi", getWidth() / 2, getHeight() / 2);getBackground().drawString("hi", getWidth() / 2, getHeight() / 2);// field
GreenfootImage savedBG = null;
// draw the string
savedBG = new GreenfootImage(getBackground());
getBackground().drawString("hi", getWidth() / 2, getHeight() / 2);
// remove the string
setBackground(savedBG);// import
import java.awt.Color;
// fields
GreenfootImage savedImage = null;
int savedImageX, savedImageY;
// draw "hi" onto background
// step 1: create the text image
int fontsize = 16;
Color txtColor = Color.black;
Color transparent = new Color(0, 0, 0, 0);
GreenfootImage txtImage = new GreenfootImage("hi", fontsize, txtColor, transparent);
// step2: save the background where the image will be
savedImage = new GreenfootImage(txtImage.getWidth(), txtImage.getHeight());
savedImageX = getWidth() / 2 - savedImage.getWidth() / 2;
savedImageY = getHeight() / 2 - savedImage.getHeight() / 2;
savedImage.drawImage(getBackground(), -savedImageX, -savedImageY);
// step 3: draw the image on the background
getBackground().drawImage(txtImage, savedImageX, savedImageY);
// remove the string from background
getBackground().drawImage(savedImage, savedImageX, savedImageY);import greenfoot.*;
import java.awt.Color;
public class Backing extends World
{
GreenfootImage savedImage = null;
int savedImageX, savedImageY;
public Backing()
{
super(600, 400, 1);
drawText("hi");
}
private void drawText(String text)
{
int fontsize = 24;
Color txtColor = Color.black;
Color transparent = new Color(0, 0, 0, 0);
GreenfootImage txtImage = new GreenfootImage(text, fontsize, txtColor, transparent);
savedImage = new GreenfootImage(txtImage.getWidth(), txtImage.getHeight());
savedImageX = getWidth() / 2 - savedImage.getWidth() / 2;
savedImageY = getHeight() / 2 - savedImage.getHeight() / 2;
savedImage.drawImage(getBackground(), -savedImageX, -savedImageY);
getBackground().drawImage(txtImage, savedImageX, savedImageY);
}
public void act()
{
if (Greenfoot.getKey() == null) return;
getBackground().drawImage(savedImage, savedImageX, savedImageY);
Greenfoot.stop();
}
}getImage().clear();
getImage().drawImage(new GreenfootImage("filename"), 0, 0);public void rename(String string);
public Text text;
// following is in the contructer
text = new Text();
// this in a method
text.rename("hi");