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

2021/2/5

One specific actor will make game lag if added in the world

Gbasire Gbasire

2021/2/5

#
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)
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;
                    }
                }
            }
        }
    }
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...
Super_Hippo Super_Hippo

2021/2/5

#
Maybe it is because of this line?
private GifImage animation = new GifImage("PeaShooter.gif");
Gbasire Gbasire

2021/2/6

#
Oh you're right I forgot about this, it works now ! Thanks !
You need to login to post a reply.