![]() If you look at the code danpost provided, you will see that can both cut down on the number of images you have and the number of lines of code but simply mirroring the image. Change those 6, 12, 18 values based on how often you want it to switch between images. It even remembers key-presses when changing worlds using setWorld(), as after the intro a new World starts where pressing enter has a certain effect, and if you press enter during the end of the intro, Greenfoot. However, a black key should not be created when an empty string is encountered in the loop within the 'displayKeys' method. Thus the image will always be set to image1. Even though isKeyDown() is supposed to return true only if the key is CURRENTLY pressed down, it seems to remember previous presses. 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. ![]() Numpad keys without an arrow (eg 9/PgUp) cannot be reliably detected when numlock is off. 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. darkmist255: those are multiple questions :p Numpad numbers should be either the number ('1', '2', '3' etc) or the arrow key ('left', 'right', 'up', 'down') depending on numlock state. Instead of adding blanks into the toggledBlack array, the blanks in the other arrays should be removed. If you want that one space is moved every time a key is pressed and released, then you can use the getKey method instead of the isKeyDown one. Yehuda wrote.I'm not sure what the purpose of all the blank array parts are for. 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. I triple checked and I am 99% sure that I did nothing wrong. Key key = new Key(blackKeys, blackNotes + ".wav", "black", toggledBlack) The simplest solution would simply be to use another key - is there any reason why you want to use the shift key in particular. As far as I can see the shift key isnt currently mapped to anything with Greenfoot and therefore wont work with isKeyDown(). Key key = new Key(whiteKeys, whiteNotes + ".wav", "white", toggledWhite) ĪddObject (key, 54 + (i*key.getImage().getWidth()), 140) I tried to use the 'isKeyDown()' function, but it dont get the shift key. ![]() Public Key(String keyName, String soundFile, String keyType, String toggle) I got the part where you type in the cheat just fine, but I have no clue as to how to make the cheat override previous code. Import greenfoot.* // (World, Actor, GreenfootImage, and Greenfoot) I am having trouble with a cheat code I am trying to make.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |