I want to spawn a GreenNote when "o" is pressed, it does that, but it spawns so many that the game freezes. How can I only spawn a single note each time "o" is pressed?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * @author Calculator * @version 2 */ public class GreenNote extends Actor { public GreenNote() { GreenfootImage image = getImage(); image.scale(60,60); setImage(image); } /** * noteSpeed will make the notes move down quicker. * noteSpawn2 SHOULD spawn a note upon key press of "o" */ public void act() { noteSpeed(5); noteSpawn2(); } public void noteSpeed(int howFast) { setLocation(getX(), getY()+howFast); } public void noteSpawn2() { GreenNote greennote = new GreenNote(); if(Greenfoot.isKeyDown("o")) { Greenfoot.delay(1); getWorld().addObject(greennote, 200, 0); } } }