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

2017/1/11

How do I make my weapon semi-automatic?

yungbae yungbae

2017/1/11

#
When I click my mouse the cannon shoots twice. Once for when the mouse is held down and once when it is released. I do not see anything in the API for only going down. I haven't set a delay for the cannon yet so it still fires automatically as well when the mouse is moving.
    public void shoot()
    {
        MouseInfo mouse = Greenfoot.getMouseInfo();
        if(alive_ && mouse!=null)
        {
           if(mouse.getButton() == 1)
           {
               BlueBullet bullet = new BlueBullet();
               bullet.setRotation(getRotation());
               getWorld().addObject(bullet, getX(), getY());
           }
        }
    }
Super_Hippo Super_Hippo

2017/1/11

#
You could also use this as a condition: (in addition)
if (Greenfoot.mousePressed(null))
yungbae yungbae

2017/1/13

#
Super_Hippo wrote...
You could also use this as a condition: (in addition)
if (Greenfoot.mousePressed(null))
This works, thank you!
You need to login to post a reply.