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

2014/1/23

Enemy won't spawn

GreenAnthony GreenAnthony

2014/1/23

#
Hi, I know I already had this discussion posted but I didn't get anything out of it. However I changed the way it was. But now there is a new problem.... Okay here is everything in detail: So I have got an Boss Enemy and I am telling him to spawn when the time is right but he won't spawn, if I then insert a Boss Enemy manually the Boss Enemy that was supposed to spawn spawns but then like 5 seconds later another one spawns and then another one and so on.... Here is the coding:
int BossSpawn = 1;
    int Counter = 3;
    private int direction = 1;
    /**
     * Act - do whatever the BossEnemy wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if (canSee(Bullet.class))
        {
            eat(Bullet.class);
            Counter--;
        }
        if (Counter == 0)
        {
            getWorld().removeObject(this);
        }
        if ((direction < 0 && getX() < 20) || (direction > 0 && getX() > getWorld().getWidth()-20))  
        {  
            direction = -direction;  
        }  
        if (BossSpawn==50)
        {
            removeObject(EnemyRocket.class);
            getWorld().addObject(new BossEnemy(), 400, 50);
        }
        setLocation(getX()+5*direction, getY());       
        BossSpawn++;
    }
}
Can u guys find the bug and tell me how to fix it, cuz I can't!
davmac davmac

2014/1/23

#
What class is this code in?
danpost danpost

2014/1/23

#
I hope this spawning code is not in the BossEnemy class.
GreenAnthony GreenAnthony

2014/1/23

#
Oh f*ck now I see my mistake...!
You need to login to post a reply.