That was the easy part. Now let’s work on setting up our basic inventory.

Inventory




Amazon.com Widgets

Your inventory takes up just one frame on your main timeline, but within the inventory movie clip itself there’s a lot going on. For the purposes of this tutorial, we’re going to create a game with just four objects, though obviously for a more complicated game, you’ll want more objects. When you set up your inventory you need to plan out how many objects you’ll end up having and how they’ll be used. Or you can wing it, like I have, but be prepared to have to go back and change a lot when you do.

What does an inventory do?

Firstly, it's where you “store” objects from the room that you’ve let your player collect. Then your player can drag objects back onto the room movie clip in order to interact with movie clips there. Since your player will be guessing what to use their objects for, you need to make sure that if they make the wrong choice with an object, somehow it’ll return to the inventory so that they can try again later. You also want the object to disappear or become grayed out once they’ve used it successfully.

What else does an inventory do? Well, most inventories allow you to select an object and get more information about it, usually through a close up view and some text. Some games also let you combine objects that are in your inventory to form new objects – either by dragging them to each other, or dragging one towards the other’s close up view. Some objects may let you manipulate them in close up – flip them over to see what's behind, for instance, or enter a code to open them.

As you can see, the inventory does a lot, arguably more than the room where the game appears to take place. We’re going to create an inventory that:

  1. houses three objects we collect from the room
  2. allows us to drag each of these objects into the room
  3. snaps the object back into place if we decide to return it to inventory
  4. removes the objects once it is used
  5. gives us a close up view of each object
  6. allows us to combine two inventory objects to create a third.

Let’s get started!

Name the layer containing the rectangle you’ve already created “background”. Now create, from top to bottom, the following layers: buttons, objects, labels and actions.

inventory1.png

We’ll be creating a few more layers when we add the close up views, but for now this is fine. Add a stop script to the first frame of your actions layer and let’s create our buttons.

The button layer is something of a cheap trick to work around the fact that creating doubleclicks in actionscript 2.0 is a pain. There are a few other ways to do this, all of them imperfect, but I’ve found this one works okay. Essentially, when you select your object from the inventory, you need to be able to drag it. When you click on the background of the object, it’ll take you to the object closeup. Create a largish rectangle on the buttons layer on top of your background. Modify it to a button and call it inv_button. The down, hit and up states should all look identical, but on rollover it should change to a “highlight” sort of color – a brighter color. Make four instances of this button and arrange them neatly on your background. This is why its helpful to know how many objects you will be using. If you create more inventory boxes than objects in your game it will confuse your players – trust me, they pay attention to things like that. We’ll come back to our inventory after we’ve created some objects to collect.