How to add an inventory to your game

Making an Inventory
This is rather easy to achieve, and a lot of Role Playing Games(rpg) games have inventories. Here is how you make one.
We will only be using layer 1 for this tutorial.
We will start by making our custom cursor.
Draw out a small circle on the stage(any colour), convert it to a movie clip and name it cursor.
Now give the cursor an instance name of cursor. Now right click on the first frame of layer 1 and select actions, now on the first line type in the following:
Mouse.hide();
cursor.onMouseMove = function() {
this._x=_xmouse, this._y=_ymouse;
};

As we know this makes the mouse hidden and allows you to move the cursor whenever you move the mouse.

Now draw out a box using the rectangle tool, make the stroke colour black, and no fill. Using the text tool, (static text) draw out a text box underneath or above that box and type in Inventory.
This is obviously so the player knows what this box is.
Now draw a small black square using the rectangle tool and convert it to a movie clip, name it item. Right click on the black box and select copy, now paste that copy, and move it inside the box. Resize it if needed so that it fits in the box. Now give it an instance name of invitem. Change the alpha of this item to 0, this was explained in a previous tutorial.
The item in the inventory box should now be invisible. If so move on to the next step.
Right click on the visible box and select actions, now on the first line type in the following:
onClipEvent(enterFrame) {
if(this.hitTest(_root.cursor)) {
this._alpha=0;
_root.invitem._alpha=100;
}
}

Now what this means is if the box that is visible represented by “this” collides with the cursor. The visible box’s alpha will go to zero “this._alpha=0;” and the other box’s alpha will go to 100 “_root.invitem._alpha=100;”.

Test the movie, now when you are move the mouse over the visible box it will become invisible and the other one will appear.

FAQ’s ABOUT THIS TUTORIAL:
Q. Why have you used the code “this” and not the name of the box?
A. As I am applying the actions to the movie clip itself, I only need to put this, as I am talking about this item that I am applying the actions to.

Q. Why do you need to put onClipEvent (enterFrame)?
A. I need to put onClipEvent as I am applying these action to a movie clip. I have put enterFrame as I want this to happen when the frame is entered. I could have changed this mouseDown which would mean when the mouse is down.

2 comments:

Anonymous said...

hey um can you write about how to make your own source code please i need help with that

gamesdevelopmentcompanies said...

gamesdevelopmentcompanies