However, a black key should not be created when an empty string is encountered in the loop within the 'displayKeys' method. Greenfoot.isKeyDown(d) ) if (isTurning & Greenfoot.isKeyDown(d) ) if (isTurning & Greenfoot.isKeyDown(d) ) () Correct 45. Adding blanks in the toggledBlack array will help to even out the arrays. With the blank spaces in the arrays you are creating keys with the keyName not being equal to an existing key in Greenfoot.The blanks (empty strings) are place holders for where there is no black key on the piano keyboard. In the Key class you can't ckeck to see if a key is down if that key ("") doesn't exist. Just like you didn't for all the other keys on the board.Įven if you do add in spaces into the array, you will still get errors, just in a different class. It happens to be that on a computer keyboard, the letter 'R' lies between the letters 'E' and 'T', but that doesn't mean you have to give it a blank index in an array. Instead of adding blanks into the toggledBlack array, the blanks in the other arrays should be removed. There are a couple of things to consider here. Also, I presume that the random part of moving is for the direction of movement, not speed or distance. Yehuda wrote.I'm not sure what the purpose of all the blank array parts are for. I presume you mean AAARGH add getRandomNumber to move the worm randomly. getKey() also returns uppercase characters when appropriate. , 'z' (alphabetical keys), '0'.'9' (digits), most punctuation marks. In my computer science class at school, Greenfoot throws weird exceptions that have nothing to do with my code but I am not sure if that is the case this time. The methods getKey() and isKeyDown() are used for this and they return/understand the following key names: 'a', 'b'. I triple checked and I am 99% sure that I did nothing wrong. Key key = new Key(blackKeys, blackNotes + ".wav", "black", toggledBlack) Key key = new Key(whiteKeys, whiteNotes + ".wav", "white", toggledWhite) ĪddObject (key, 54 + (i*key.getImage().getWidth()), 140) String myKey '' while ( ('enter'. Public Key(String keyName, String soundFile, String keyType, String toggle) Instead of checking if the key is down, just send the keystroke to a variable and check it for enter. Enter that code, compile it, and try it out. Im making an application where buttons are either toggled on or off. If you want something like 'a' and 'd', just use those instead Our code is saying: if those keys are down, turn a certain number of degrees. Between the quotes is the name of the key, 'left' is the left cursor key, 'right' is right. Import greenfoot.* // (World, Actor, GreenfootImage, and Greenfoot) We use the Greenfoot built-in methods for checking if a key is down.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |