I am making a game where you have to dodge bullets to win. To start the game, you have to press the run button and then space bar to start any of the code. I want to spawn a car, a karen, and a kid. I have the isKeyDown command in the world and they do not spawn when I press the spacebar. The sound does not play when I press the spacebar either. Here is my code:
Any help on how to make them spawn and for the sound to play correctly?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class tile extends World { /** * Constructor for objects of class tile. * */ public tile() { super(1280, 720, 1); addObject(new spacetostart(), 640, 350); if (Greenfoot.isKeyDown("space")) { Greenfoot.playSound("earrapeflamingo1.mp3"); } if (Greenfoot.isKeyDown("space")) { addObject(new karen(), 646, 77); addObject(new kid(), 650, 77); addObject(new car(), 650, 350); } } }