Hi following is my code, now I want to remove the object from the world which has a text message in it.Similarly I want to even add some more text in the world after some work is performed.Can you help me in this.
----------------------------------------------------------------------------------------------------------
Now I am finding it difficult to add and remove a text message at runtime....
Thanks
public void act() { int mouseX, mouseY ; String text ="Have Coin!"; String text1= "Have penny"; if(Greenfoot.mouseDragged(this)) { MouseInfo mouse = Greenfoot.getMouseInfo(); mouseX=mouse.getX(); mouseY=mouse.getY(); setLocation(mouseX, mouseY); if((mouseX>300 && mouseX <400) && (mouseY>200 && mouseY<250)) { World w = getWorld(); w.removeObject(this); //getMessage(); //Message message= new Message(text); w.addObject(new Message(text),380,450); //getWorld().addObject(message(text),380,450); update(); Greenfoot.playSound("coin-drop.wav"); Greenfoot.delay(10); }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; public class Message extends Actor { public Message(String text) { GreenfootImage gi= new greenfoot.GreenfootImage(100,30); gi.drawString(text,2,20); setImage(gi); } }