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

2018/6/10

All Actors freeze when i want to freeze on thread

MrCaspar MrCaspar

2018/6/10

#
Everytime two Actors meet dealdamage() is called and they should only deal each other damage every 1.5 seconds but every actor extending Enemy Freezes for 1.5 seconds. How can i delay the damage dealing but nothing else?
public class Enemy extends Actor
{
    int hitpoints, damage;
    
    public Enemy(int pHitpoints, int pDamage){
        hitpoints = pHitpoints;
        damage = pDamage;
    }
       
    public void dealDamage(int damagetaken){
        hitpoints = hitpoints - damagetaken;
        try {
                Thread.currentThread().sleep(1500);
        }
        catch(InterruptedException ie) {
        }
        if(hitpoints <= 0){
            this.getWorld().removeObject(this);
        }
    }
}
danpost danpost

2018/6/11

#
MrCaspar wrote...
Everytime two Actors meet dealdamage() is called and they should only deal each other damage every 1.5 seconds but every actor extending Enemy Freezes for 1.5 seconds. How can i delay the damage dealing but nothing else? << Code Omitted >>
It is probably not a good idea to work with threads in greenfoot. Better might be to use int timer fields.
You need to login to post a reply.