Hello, i have made a game quite long ago and it's biggest problem was just how laggy it was. I decided to try and fix this problem and i settled on a single reason why my game was so slow: When creating a new Actor object frequently, Greenfoot slows to a crawl.
To demonstrate this, you can try to run the following code in Greenfoot and see the results for yourself:
My game basically had a spaceship that could shoot lots of lazers, but when shooting 3~7 lazers at once every 100ms the game slowed to a crawl.
Does anyone have an idea if this can be avoided somehow?
I had an idea where you would cast the lazers before the game started and just recycle removed lazers, but because the Lazer objects in my game are disposable, this didn't seem practical.
Thanks in advance.
1 2 3 4 5 6 7 8 9 10 11 | // first of course, you have to make a class called Actor1 /** * This code should be put in an actor that will later be added to the world **/ public void act() { new Actor1(); new Actor1(); // If your PC is quite powerful, you might want to add more // But since mine is not that good, two were enough. } |