im on chapter five in the book and i dont seem to understand how it is programmed. there are several
commands i dont understand. ill list the code for "key"(actor) below
Key
i dont understnad why
public Key(String keyName, String soundFile )
has what it has in the parentheses. why is it there and what does it do? i dont think soundFile is an actual command so why is it equal to the variable sound? also in the end in the code
Greenfoot.playSound(sound);
why is the sound in the parantheses?
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) public class Key extends Actor { private boolean isDown; private String key; private String sound; /** * Create a new key. */ public Key(String keyName, String soundFile ) { key = keyName; sound = soundFile; } /** * Do the action for this key. */ public void act() { keyAnimation(); } public void keyAnimation() { if (!isDown && Greenfoot.isKeyDown(key) ) { setImage("white-key-down.png"); isDown = true; play(); } if ( isDown && !Greenfoot.isKeyDown(key) ) { setImage("white-key.png"); isDown = false; } } public void play() { Greenfoot.playSound(sound); } }