I have these two methods which should add and delete after some time a text.The problem is that I want to add text based on the user clicks but if he click again before the previous text was deleted the new text will be added over the old text.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | void addText(String _text) { if (text.getWorld() != null ) // i tried this if but it doesn't work { text.getWorld().removeObject(text); } text = new Label(_text, 30 ); getWorld().addObject(text, Dungeon1.WIDTH/ 2 , 60 ); textOnScreen = true ; textTimer.mark(); } void removeText() { if (textOnScreen && textTimer.millisElapsed() > 1500 ) { getWorld().removeObject(text); textOnScreen = false ; } } |