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

2013/6/12

How to have buttons open/close a gate?

hl2tf2 hl2tf2

2013/6/12

#
We are trying to a button change the image of an object each time it's pressed. The code below is what we used but the image does not change even when we call Change from the button class without the if statement. the following methods are in the gate class:
public boolean isOpen=false;
    public void act() 
    {
        if(isOpen)
        {
            setImage("portal-open.png");
        }
        else
        {
            setImage("portal-closed.png");
        }
    }
    
    public void change()
    {
        if (isOpen)
        {
            isOpen=false;
        }
        else
        {
            isOpen=true;
        }
    }
and this is in the button class:
public void act() 
    {
        if(canSee(Player.class))
        {
            change();
        }
    }
can see method:
public boolean canSee (Class clss)
    {
        Actor a = getOneObjectAtOffset(0,0,clss);
        return a!=null;
    }
hl2tf2 hl2tf2

2013/6/12

#
have*
You need to login to post a reply.