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

2013/3/7

Missile shooting question

leeyong0 leeyong0

2013/3/7

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Missile here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Missile extends Actor
{int turncounter = 0;
    /**
     * Act - do whatever the Missile wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if (turncounter == 0){
            turn(-90);
            turncounter++;
        }
        else{
            
        }
        move (-8);
    }    
}
I have a question I have made my missile shoot but it shoots in vast numbers even when I tap it slighty, it shoots like 3 or more. Please help
danpost danpost

2013/3/7

#
Sounds like you are using 'Greenfoot.isKeyDown' instead of 'Greenfoot.getKey' to determine whether to shoot or not.
leeyong0 leeyong0

2013/3/12

#
Thanks a lot!
steved steved

2013/3/12

#
another way you could do it is set some kind of reload timer so that if you hold the hey down it fires once every so often.
You need to login to post a reply.