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

2013/9/11

Gum ball machine

Th3j4 Th3j4

2013/9/11

#
Hello guys, I want to print the text when my quarter touches the gumball machine before machine takes the quarter. I used two types of code 1.this REPLACES my machine with the text Actor coin; coin=getOneObjectAtOffset(0,0,Coin.class); if(coin !=null) { World world=getWorld(); GreenfootImage m=new GreenfootImage(100,100); m.drawString("have coin",0,50); setImage(m); world.removeObject(coin); } 2. Created a class under actor(say text) i called the method(constructor) from my main class which displays the text in the terminal with System.out.println method. But its not displayed on the greenfoot world. GreenfootImage m=new GreenfootImage(text, 28, Color.black, Color.White); m.drawString(text,400,300); setImage(m); Someone help me with this..
danpost danpost

2013/9/11

#
It appears you are trying to the draw the image of the text at a location of (400, 300) on an image that is only 100x100 pixels in size.
Th3j4 Th3j4

2013/9/11

#
Danpost both are two different cases and moreover I have tried using the location of (0,50) and several other locations. But,when i add the text class to the world i can see the text on the world. And, i have to add the text over my machine image. In the first case the text replaces the image. In the second case i can't see the text in the world.. Hope this makes my question clear O.o
danpost danpost

2013/9/11

#
In the first case, yes; you programmed the image of the quarter to change to the image of the text. In the second case, it appear you are trying try use 'drawString' to draw an image (not a string); try using:
m.drawImage(text, 40, 30);
If you want the text to be separate from the image of the quarter, you should probably create a class that creates actor objects whose images have changeable text. You only need create one object of this type, but keep a reference to it in your world class. Then, you can add and remove that objects from the world as needed and change the text as needed.
Th3j4 Th3j4

2013/9/11

#
drawImage method is not working in this scenario. And yeah i have created another actor and when i use addObject method the object is not displayed on the screen... But as i said earlier if i add an object manually i can see the text and also in the terminal. Can you post me the simple example for adding objects dynamically to the world. Thanks
danpost danpost

2013/9/11

#
Please show the class you wrote (whether working or not) that is supposed to show the text. Also show how you call the constructor (where you create a 'new' actor object of that type); and give what class the call is in and the type of class (the name of the class and what it extends).
Th3j4 Th3j4

2013/9/11

#
I am now able to display the text using drawImage method in the world but not over the image that's already existed in the world. And i want to remove the displayed text after say 2 secs. How can i do that?
danpost danpost

2013/9/12

#
Again, in order to assist in removing the text, you need to show how it is displayed. "Show your code!".
You need to login to post a reply.