Chapter 1 Introduction Hopefully, at this point in the course, you're hooked on programming and excited about the worlds you're able to create. Today, we'll add multimedia effects to your bag of tricks. Specifically, you're going to learn how to use image and sound files in your worlds. Alice provides a lot of images and a few sound files with its objects. Using these will definitely enhance your worlds. However, you can also use your own images and sounds. I'll start by showing you how to place individual image files into a world and then show you how to use these same files to color other objects. Finally, I'll show you how to use some of the built-in sounds in some of the Alice objects and then show you how to use your own sound files. Chapter 2 Image Files As you've seen, Alice has a lot of 3-D objects for us to use. This is a big plus because earlier in the course, I said that without a lot of background in 3-D graphics, it's difficult to create original objects for an Alice world. However, it's really easy to create 2-D graphics. All you need is an image file. Alice lets you use graphics files with common formats like GIF, BMP, JPG, or TIF. Here's an overall comparison of each type: BMP – Bitmap files are generally an uncompressed format. This means that the file size is usually larger than the others. GIF – GIF files are in a compressed format that works well for simple diagrams and cartoonlike images. JPG – JPEGs are also in a compressed format that works well for images with numerous colors, such as photographs. TIF – TIFF files (also compressed format files) are used by many digital cameras. They have a better quality than JPG, but files are usually larger. In general, you'll want to use either GIF files for simple drawings and JPG files for photographs in your Alice worlds due to their relatively smaller file sizes. But before we go on, let's take a brief look at the issue of copyrights. When you decide to use images or sounds in your Alice worlds, you need to be careful with copyrighted materials. It's illegal to use such material without permission. Although, there is part of the copyright law that allows for the use of copyrighted materials for educational purposes. Then there's the concept of fair use. Page 1 Since I'm not a lawyer, I want to be extra careful with using someone else's work. To be sure we're not breaking any copyright laws in this lesson, all of the images and sounds are my own work. To avoid copyright issues yourself, or maybe just to be extra creative, you may want to create your own images, too. The good thing about creating 2-D images is that there are lots of free programs out there that let you do this. Microsoft Windows operating systems come with MS Paint, which is a simple image editor. If you're using a Macintosh or Linux operating system, a common editor is the GNU Image Manipulation Program (GIMP). For this lesson, I've created an image using the simple Microsoft Paint program that comes with Windows. Billboard Objects Alice allows you to place a 2-D image into your worlds as a billboard. Billboards are a great way to place instructions into your Alice worlds. For example, in our previous lesson that had the flight simulator, it would have been nice to tell the user to use the arrow keys to steer the plane. However, you can certainly use a billboard anywhere you like, but I think once you use them, you'll see why they are best suited as user directions. Start a new Alice world with the dirt template. Next, we'll add our billboard. Unlike adding other Alice objects, the only way to add a billboard object is to go to the menu bar at the top of the window. Here you'll need to click File > Make Billboard. You'll see a dialog box that lets you select the image file to use as the billboard. Select the billboard.bmp file I provided and click Import. Go to the student shared drive – then Game Design-Ms. Doherty – Then click the Game Design Billboard. The image will appear in the World window, and an object named billboard will be in the Object Tree. Create a mouse event that allows the user to move the camera. Play this world and move the camera around this object. You'll see that this object is flat. Try moving the camera through the billboard, then turning around and looking at it from behind. The text is reversed because we're looking at it from the back. Here's an example of what you should see: Billboard object from behind Page 2 The interesting thing about billboards is that they're just like any other Alice object. That is, they have a list of properties, methods, and functions. Let's use one of these methods to turn our billboard so that it's facing the camera. Remember that you can use the layout tools to turn an object, or you can right-click the billboard object in the Object Tree. This gives you access to all the object's methods. Let's right-click the billboard object and select methods > billboard turn to face > camera. Now the billboard should be facing the camera. Now that we've got our billboard in the world, let's make it disappear after the user has read it. There are two ways that we can accomplish this. We can either use the isShowing property or the opacity property. The isShowing property determines whether or not an object is showing, while opacity controls how transparent it is. An opacity of 1 (100%) means that an object is solid, while a value of 0 (0%) means that an object is transparent. Let's test each of these properties by creating a method that is run when the user clicks his or her mouse. It makes the most sense for this to be a billboard method. So, make sure the billboard object is selected, click the methods tab in the Details area, and then click the create new method button. Name this method disappear, and then click OK. Select the properties tab and look for isShowing. Drag this icon into the Editor area and select False from the shortcut menu. When this method is run, our billboard will immediately disappear. It still exists in the world, it just isn't visible. We can make it reappear at any time by changing the isShowing property back to true. Next, we need to link our mouse event to this method. Go to the Events area and click create new event. Use the shortcut menu, and select When the mouse is clicked on something. At the end of this event's line, click the drop-down arrow next to Nothing and select billboard > disappear. Play the world and you'll see the billboard. Click the mouse anywhere and the billboard disappears. This is exactly what we wanted to happen. However, what if we wanted it to slowly fade? You might think that we can just go to the disappear method and change the duration property of the line that sets the isShowing property to false. Unfortunately, this won't work. The reason this isn't possible is because isShowing is either true or false. The object is either showing or it isn't; there's no in between. Fortunately, there's a way we can make the object slowly disappear: the opacity property. Remove or disable the isShowing property in the Editor area, and then drag and drop the billboard's opacity property there instead. When the shortcut menu appears, select 0 (0%: invisible). Now play your world and click the mouse button. You'll see that the billboard slowly becomes transparent. Personally, I like this effect much better. But whether you like it disappearing immediately or slowly fading, it's good to know how to do both. In the next chapter, I'll show you how to use images as textures for our Alice objects. Once you know how to do this, you won't have to settle for using Alice's standard colors. Page 3 Chapter 3 Working With Object Textures All visible Alice objects have two properties that control their appearance: color and skin texture. These may seem like the same thing, but they're not. The color property lets you choose from a list of colors for your object, while the skin texture property lets you choose an image file. You already have some experience with one of these. Do you remember using the color property to change the color of our atmosphere? The best way to see the difference between these two properties is with the cow object. Start a new Alice world that uses the grass template. Open the Animals gallery and add a Cow to your world. Go to the Object Tree and select cow. Then click properties in the Details area. Look through the list and you'll see that the cow's color property is set to white. Well, you'll see that there is a white box with a drop-down arrow in it. Click that drop-down arrow and change the color of your cow to something else. When you do, you'll see that your cow keeps its black patches, but the white part changes to whatever color you selected. Next, look in the Details area for the skin texture property. You'll see that the value for this property is cow.texture. If you click the drop-down arrow here, you'll see that there are three textures to choose from: cow.texture, ground.GrassTexture, and None. Select None and the cow's black patches will disappear. That's because the cow.texture is no longer present. Curious about ground.GrassTexture? Go ahead and try it. You might have thought that the cow would be invisible on top of the ground because they are both using the same texture. However, because the cow is a 3-D object, it's shaded, and this shading helps it to stand out from the ground. Okay, let's get really twisted and keep the ground texture for the cow and try to change the ground's texture to the cow. Why not, right? Just select the ground object in the Object Tree, and then change its skin texture to be cow.texture. You'll see that the cow's pattern of white with colored blotches is splashed all over the ground. Make note the image used for the ground and any other object is just a single image that's repeated again and again. It's pretty interesting that you can use any object's skin texture for any other object in a world. You might find it even more powerful that you can use any image file as a texture for any of your objects as well. Let's give this a try using the billboard.bmp file. At the bottom of the properties list for every object, there's a button for import texture map. If you don't see it, select the plus sign next to Texture Maps. Every Alice object has this button in its properties list. This means you'll need to be careful before clicking this button. The reason is organization. The worlds we've created so far have been pretty small, and it's been easy to find things. However, when you start writing more-complex worlds, you can easily misplace things. For example, imagine using the import texture map on your cow object. Then, you use that texture map to color your ground. Then, for some reason, you decided to remove the cow from the world. That is going to create a problem because without the cow, you don't have access to the ground's texture. Page 4 So, I recommend that anytime you want to import a texture map into your world, you make it part of the world object. This ensures that you know exactly where your texture maps are located and you'll never delete one by accident. With this in mind, go to the Object Tree and select the world object. Go back to the bottom of the property list in the Details area and click import texture map. Use the dialog box to select the billboard.bmp image file. Next, change the skin texture of both the ground and cow objects to world.billboard. Again, this makes for a strange world. You might think you'll never use this. But I can think of a couple of times when you might. For instance, there might be a time when you want to create a grid in your world. It'd be easy to create an image file that has nothing more than a square. If you set the ground's skin texture property to this image, then you'd have your grid. And what about using the texture for an object, like the cow, on something else? Did you ever think there were all of those different colors in the cow.texture pattern before you applied it to the ground? I didn't. I couldn't believe I didn't notice the reds, browns, pinks, and even blues in the pattern! I think the reason I never noticed it was because it was spread all over the cow. But the colors were there. So the idea is that there may be a time when you want to design a unique pattern and this is the way to do it. Now that you have an idea of how to use your own image files in Alice, let's turn our attention to sounds. After all, we've been stimulating our user's visual senses during the entire course. Let's start working on their ears! Chapter 4 Audio Files One thing that is going to make your Alice worlds even more fun to play, whether the world is telling a story or is an interactive game, is the use of sounds. The creators of Alice realized this and built some sounds into the world object. It's very easy to incorporate these sounds into our world. To get going on tickling your users' ears, start a new Alice world with the grass template. Before adding any objects, select the ground object in the Object Tree. Scroll through this list of methods in the Details area until you find the ground's play sound method. Drag this method from the Details area and drop it in the Editor area. The shortcut menu that Alice gives you now lets you choose from a variety of sounds that you can play. Page 5 These sounds are supposed to be generic things that you might want your world to play. There are things like thud1, whoosh1, pop and splash, which seem generic enough. However, the Alice creators also give us the ability to play a doorbell chime and the cluck of a chicken. Be aware that because these sounds are built into Alice, every object has a play sound method except for the world object. Remember that the world object is special in that it doesn't contain any methods, but it does provide some unique functions. Go ahead and try out some of these sounds to hear what they sound like. Remember, we're putting this code in the world.my first method method. That means that when the world is first played, you'll hear the sound. While adding sound to your worlds is a powerful tool, please be sure to use it only when appropriate. Your users will really appreciate this because playing the same sound effects over and over can get annoying. Go to the Animals gallery and add a bunny to your world. Use the Object Tree and select the bunny to move it 10 meters to the left. This will put the bunny off the screen. Next, put a Do together structure in your world.my first method method. Inside that structure put code to move the bunny to the right, 10 meters. Finally, use the bunny's play sound method to play the whoosh2 sound. Now when you play the world, the bunny should go sliding across the screen as the whoosh2 sound plays. This is a simple example, but it shows you how playing sounds can make your world more interesting. In addition to playing Alice's built-in sounds, you can also import sounds into your worlds. This is done just like we did when importing our textures. Alice allows you to import WAV or MP3 files. Similar to the different image file formats, WAV files are uncompressed and therefore typically larger than MP3s, which are compressed files. Again, I suggest that you try to work with MP3 files, as anytime you can keep your programs smaller, you decrease the likelihood that they will crash on your users. To import a sound, just go to the properties list for any object. There you'll find an item for Sounds. If you click the plus sign next to Sounds, you'll see two buttons, import sound and record sound. Again, since every object has these two buttons, you'll want to be sure that you use the appropriate object to better organize your files. It may be a good idea to put all of your sounds in the world object so you know where all of your sounds are. The import sound button works exactly the same as the import texture map button. If you click this, a dialog box will open that allows you to select the file that you want to import. You'll then be able to select this sound from the list in the play sound method. The record sound button does just what it says; it allows you to record a sound using Alice. In order to use this feature, you'll need a microphone attached to your computer. When you click this button, the dialog box shown below opens. This has a place to give your sound file a name, a Record button, and a Play button. Click Record to start the recording, and you'll see that this button now says Stop. When you're finished recording, you can replay the sound to make sure that you like it, and then click OK to save it. This will add the sound to your object under the Sounds heading. Page 6 Record sound dialog box YOU CAN TRY THIS ON YOUR OWN How about playing a sound in the background? This would be sort of a soundtrack for your world. If you have a sound file to use as background music for your world, just right-click and download the zipped MP3 file below to your computer. You can then use the file and play it over and over in the background. Actually, this is something you already know how to do. Do you remember how to make something happen again and again as the world is playing from an earlier lesson? You just need to make a new method for your object, create a new event, and then attach the new method to the event. If you're still a little bit fuzzy on how to do this, just follow the directions below. Since background music will be part of the world, select the world object, and then click create new method in the Details area. Give your new method the name, background music. Since the world object doesn't have a play sound method, you'll need to select another object that does. I'll use the ground object, because it will always be part of my world. Drag the ground play sound method into the background music method and select import sound file. Then navigate to the location on your computer where you saved the loops.mp3 file from the lesson. Select this file and click Import. Next, go to the Events area, click create new event, and then choose When the world starts from the shortcut menu. Right-click this event and select change to > While the world is running. Finally, click the drop-down arrow next to the None in During, and choose background music. Play your world and you'll see the bunny comes whooshing in as the background music plays over and over. Not bad. Notice how this background music adds a whole new dimension to your world. You might even want to add some code to your world to make your bunny dance after it comes into view. Personally, I added some code to make my bunny turn around and around, but feel free to take some time and spice up your dancing bunny! Chapter 5 Summary I hope you found today's lesson fun and informative! You learned how to use graphics in your Alice worlds and how to manipulate the appearance of your Alice objects with their color and skin texture properties. You also learned how to use the Billboard object and how to make objects appear or disappear using the isShowing and opacity properties. Page 7 In addition to all of this visual appeal, you also discovered how to add and work with sound. Alice not only lets you import your own WAV and MP3 files for playing in your world, but you also have the ability to record sounds as well. Placing sounds in your world truly makes for a multimedia experience that's sure to delight your users. In the next lesson, we'll turn our attention back to programming structure, where I'll teach you about the Alice list structure. Other programming languages call these things arrays, which is nothing more than a group of related items. We'll explore this concept in the next lesson by putting a group of objects into a list. You'll then see how easy it is to make all of the objects in the list do the exact same thing with just a line or two of code. You can use this idea if you ever want to create a world that has something going on in the background, like people or animals walking around or birds flying randomly in the air. We'll do that and a whole lot more in Lesson 11. Page 8