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

2011/3/6

counter

lbk14 lbk14

2011/3/6

#
im looking to implement a counter i have a counter class i want an integer variable within this class to be updated everytime my user object fires a bullet and it hits the bot character...i also want this counter displayed in the world... what is the best way to go about this? i have a bullet class, a class for the user object, a class for the bot character, a counter class i'm not necessarily looking for written code here, just some pointers and tips to get me own my way implementing the counter
davmac davmac

2011/3/7

#
Write a method in the counter class which updates the integer and displays the updated value. The counter class should be a subclass of actor so that you can put it in the world. Maintain a reference to the counter from the world, and have the bullet fetch the counter reference from the world whenever it hits a bot, and call the update method. The easiest way to have the counter display a value is to use the GreenfootImage constructor which takes a string argument (and two Color arguments) and set the actor image to the resulting GreenfootImage.
needcodehelp needcodehelp

2012/5/18

#
Can you post some code examples?
davmac davmac

2012/5/18

#
There are plenty of examples out there, see tutorial #6 for instance.
You need to login to post a reply.