[quote=bluemagica;2325409]You started alright with your inventory, but then you are going a bit off-track with the duplicating bit. There are many ways of doing an inventory, but i will tell you a simple way. First Make a tweened background for your inventory, like you have done…Now, go inside this , say invBack_mc. And move it in such a way that the origin point of the invBack_mc lies exactly on the top left corner position, from where you want to start placing the slots. Now comes the fun/trick portion. Make a new mc say 32x32 or so, and call it invSlot_mc , and on the first frame draw a empty square to act as the slot on where to place the items.And then on each successive frame put the pictures of your inventory items, sword, potion, whatever. i hope you have got the idea by now, anyway…
Next just think up how many slots you want in your inventory, 3 columns and 4 rows…
var slot=new Array();
var pos_x=this._x;
var pos_y=this._y;
var gap=5;
for(var i=0;i<4;i++)
{
for(var j=0;j<4;j++)
{
slot[i+j]=this.attachMovie("invSlot_mc","slot_"+(i+j),this.getNextHighestDepth());
slot[i+j]._x=pos_x
slot[i+j]._y=pos_y
slot[i+j].gotoAndStop(1);
slot[i+j].state="free";
pos_x+=pos_x+gap;
}
pos_y+=pos_y+gap;
}
Now when you make the item mc’s, give them a “item_id” equal to the slot frame number. so on collision
for(var i=0;i<slot.length;i++)
{
if(_root.invBack_mc.slot*.state=="free")
{
_root.invBack_mc.slot*.gotoAndStop(item_id);
_root.invBack_mc.slot*.state=="item_id";
} //remember to remove the mc though;
}
This is a very simple way of doing it, if you want to attach actual mc, then just use attachMovie() instead of simple frames.
There are loads of other ways, and most times each coder has his own ways…try to find a way for yourself too ;)[/quote]
Thanks a whole bunch ^^ I figured out a way to dynamically do the sliding animation so thats one thing I don’t have to worry about. Now, for the inventory. I dont really want to make a empty frame for each item, since theres going to be a hell lot of items in this game. I just want to create a database with all the items/item id in it(something like a array), then just duplicate a copy from that database whenever a player needs a item. Or I could just assign each item with a id, and create a database full with items idea, then attach a item from the library according to the ID. Is there anyway to do that?
PS: This is my current code for my inventory, although I have no idea how it works and for some reason, it only works if the slots are not in another symbol.
On The Frame:
function addToslot (item) {
if (!item.found) {
item._x = eval (“itemSlot” + currentslotnum)._x;
item._y = eval (“itemSlot” + currentslotnum)._y;
item.found = true;
currentslotnum++;
}
}
On The Items:
onClipEvent (enterFrame) {
if (_root.player.hitTest (this)) {
_root.addToslot (this);
}
}