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

2016/2/3

Movement in Tower Defense

Luc_Stoffer Luc_Stoffer

2016/2/3

#
Hallo At the moment I'm trying to creat my first game in Greenfoot. Actually it's a Tower Defense game. Now I have created a method, which should move my enemies around the map on a path. The problem is now that the more enemies I create, the slower my program gets. Does anyone out there know how I could fix taht problem? Here is the code of the method which is responsible for the moving:
public void LaufeEntlangPfad1()
    { 
        if(Zähler > Startverzögerung){
            Position++;
        }
        int[] Koordinaten = Welt1.Pfadpunkte.get(Position);
        int x = Koordinaten[0];
        int y = Koordinaten[1];
        setLocation(x,y);
        Greenfoot.delay(Geschwindigkeit);
        if(this.getX()==880)
        {
            getWorld().removeObject(this);
        }
        ++Zähler;
    }
danpost danpost

2016/2/3

#
Luc_Stoffer wrote...
The problem is now that the more enemies I create, the slower my program gets.
Normally, when a scenario gradually slows down, it is because actors are being created and added into the world continuously or exponentially; or actors are not being removed from the world when needed.
You need to login to post a reply.