I am trying to make a healthbar but the healthbar goes down way to fast, i tried the Greenfoot.delay() but then everything slows down. Can someone help me?
I am trying to make a healthbar but the healthbar goes down way to fast, i tried the Greenfoot.delay() but then everything slows down. Can someone help me?
The Greenfoot.delay() method will suspend all actions for the number of act cycles given as its parameter. If the touching of another actor causes the healthbar to decrease, then it is probably true that for each act the touching occurs or continues, the healthbar will decrease. My suggestion is to list objects it touches and only decrease the healthbar when an object is added to the list (and not when the object is already on the list). The sequence of checks might be as follows:
* create new touching list
* remove objects from touch list that are not in new list (removing those no longer touching)
* add objects from new list to touch list when not in touch list and perform actions (healthbar, for example)
This last step may require the use of instanceof checks to determine the type of objects touched.