I'm currently trying to create a Plants VS Zombies game (https://www.greenfoot.org/scenarios/27363) and The method I use to add a plant is pretty simple :
(In the cursor class)
the problem is that if I add a sunflower, the game will work normally, but if I add a peashooter, the game will freeze for like 5 seconds (only on web though, it works normally on greenfoot software)
What could be happening ? Both plants use a similar code...
public void addPlant()
{
if(Greenfoot.isKeyDown("enter"))
{
if(money >= 100)
{
if(plantselected == "PeaShooter")
{
if(isTouching(Plants.class)== false)
{
getWorld().addObject(new PlantPeaShooter(),
getX(), getY());
money = money - 100;
}
}
}
if(money >= 50)
{
if(plantselected == "SunFlower")
{
if(isTouching(Plants.class)== false)
{
getWorld().addObject(new PlantSunFlower(),
getX(), getY());
money = money - 50;
}
}
}
}
}

