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

2013/6/6

Enemys disappearing with no reason bug

Maddin Maddin

2013/6/6

#
Hi, I have a bug in my game (http://www.greenfoot.org/scenarios/8167), when you play the game you'll notice, that when you shoot some enemys just die without being hit, i don't know why please help me to solve the bug! Thanks in advantage
davmac davmac

2013/6/6

#
I think your problem is in the Kugel class, in this method
    public void gegnerToeten() //Wenn die Kugel einen Gegner "sieht" töter er ihn
    { 
        Actor gegnermesser = getOneObjectAtOffset(0, 0, GegnerMesser.class);
        if (canSee(GegnerMesser.class))
        {
            ((GegnerMesser)getWorld().getObjects(GegnerMesser.class).get(0)).lebenVerlieren();
        }
    }
You check to see if the Kugel can see a GegnerMesser, and if it can, you then ask the world for all GegnerMesser objects and remove life from the first one. However, that might not be the one that the Kugel hit. You should probably just have:
    public void gegnerToeten() //Wenn die Kugel einen Gegner "sieht" töter er ihn
    { 
        GegnerMesser gegnermesser = (GegnerMesser) getOneObjectAtOffset(0, 0, GegnerMesser.class);
        if (gegnermesser != null) {
            gegnermesser.lebenVerlieren();
        }
    }
Maddin Maddin

2013/6/6

#
Thank you i'll try it later :)
You need to login to post a reply.