So I've made an update on my game, (making the text animate itself character by character, and some minor changes), and the game started to lag a lot more when touching "TallGrass.class".
The worlds also seem to take some time to load (about 0.5 sec before update, about 2-3 sec after update).
part of the code of Boy.class when he touches grass :
TransitionIn starts a new WorldWildBattle world, where the player can battle with his pokémon against a wild pokémon.
the way the caracters are animated is this one :
One other change I've done is that I've deleted all unnecessary curly braces in most of the classes
(for example :)
before :
after :
I've also gave the possibility for the player to be either a boy or a girl, but I don't think it changed a lot of things, as only a few lines were added and only 8 GreenfootImage variables were created.
what could cause the lag and how can I prevent it ?
public void checkGrass()
{
if(isTouching(TallGrass.class))
{
if(Greenfoot.getRandomNumber(200)<1)
{
getWorld().addObject(new TransitionIn(), 300, 200);
previousworld = "ROUTE";
speed = 0;
}
if(Greenfoot.getRandomNumber(5)+1<2)
getWorld().addObject(new Dust(),getX(),getY());
}
}public void animateText(String animation)
{
char[] letters = animation.toCharArray();
int length = animation.length();
if(texti < length)
{
writing += letters[texti];
texti++;
}
getWorld().showText(writing, getX(), getY());
}if(time == 40)
{
setImage(image1);
} if(time == 40)
setImage(image1);


