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

2020/1/21

Greenfoot bug or am I dumb?

CarolK CarolK

2020/1/21

#
I am currently working on a game & at this stage I started implementing the Skill Wheel. I want it to appear whenever the 'k' key it toggled and disappear when others are pressed, but for some reason the wheel won't appear in my world.
public class MyWorld extends World
{
    private boolean skillWheel_visible = false;
    
    private boolean keysPressed()
    {
        if(Greenfoot.isKeyDown("w") || Greenfoot.isKeyDown("a") || Greenfoot.isKeyDown("d"))
            return true;
        return false;
    }
    
    public void active_SkillW()
    {
        if(Greenfoot.isKeyDown("k"))
            if(!skillWheel_visible){
                addObject(new WeaponWheel(), 300, 300); 
                skillWheel_visible = true;}
        if(skillWheel_visible && keysPressed()){
            removeObjects(getObjects(WeaponWheel.class));skillWheel_visible = false;}
    }
    
    
    public MyWorld()
    {    
        super(600, 600, 1); 
        //addObject(new WeaponWheel(), 300, 300);
        active_SkillW();
    }
}
danpost danpost

2020/1/21

#
Line 27 should be in an act method, not in a constructor block.
CarolK CarolK

2020/1/21

#
Ok, so it was the second option... Thank you! I can not believe I forgot about it
You need to login to post a reply.