Greenfoot piano scenario code12/5/2023 ![]() When g is pressed the musical keyboard key switches to the picture of it down. Later on we will choose keys on the computer keyboard with thought and purpose, right now we just want to get the code right. Take a look at this code:įor this example we choose a letter more or less at random, (the “g” key) to get the key object to react to. You just need code that will switch the image to the white-key-down.png when the right key on the computer keyboard is pressed. Since we already sort of know how to do this when we animated our crabs walking, we should be able to do this pretty easily. The white-key.png is the image that is set to default for class Key. Those are the two states that we want to show. The scenario already has two images files, one is called white-key.png and the other is called white-key-down.png. The first task is to animate the piano key, when a key is pressed on the keyboard, we want the key object in the world to change so it looks like it’s pressed down. You can start experimenting by placing down an object of class Key in the world and then running the scenario. If you looked at the code, you know that there is not much there, the Piano class only has the size and resolution of the world, and the key class only has method stubs ( an empty method) for the act and the constructor method. Make a few of them and place them all next to each other. Explain the code that is already there and what it does.ĥ.2 Do This: Create an object of class Key and put it in the world. ![]() Start by opening the scenario called piano-1 from the Handout folder.ĥ.1 Do This: Open the scenario piano-1 and look at the code that is already there for the two classes that already exist, Piano and Key. Now we are going to start a new project, a piano that you can play with the computers keyboard.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |