Flixel Forums

development => help => Topic started by: Wolfstorm on Thu, Mar 10, 2011

Title: An inventory
Post by: Wolfstorm on Thu, Mar 10, 2011
I'm trying to work out how to create an inventory for my game. However, I'm stuck on a few issues.
First thing is, is that if I try add( --- ) or super( --- ) in a custom class that doesn't extend from FlxState, I get an error saying that's not the appropriate method.
This leads to my second problem: if I were to create a list of item-classes, I wouldn't be able to add them to the inventory dynamically.

Can someone give me some pointers?

(Ps. Im new to Flash AS3 and Flixel, meaning I've only started using it since 2-3 weeks.)
Title: Re: An inventory
Post by: bpercevic on Sat, Mar 12, 2011
if your class isn't extending anything then super() isnt necessary.  super() just calls the constructor from the base class, so no extension means you have no base class.

i'm not sure what you mean by a list of item classes, do you mean an array that holds all the items?
Title: Re: An inventory
Post by: Wolfstorm on Mon, Mar 14, 2011
Yeah, Im trying to get an array or list of items that the inventory can call upon to check for the variables of an item (like price, icon, etc)
Title: Re: An inventory
Post by: Berzee on Mon, Mar 14, 2011
Not sure if this is helpful at all but I was makin' a strategy game and I did some stuff to show a list of units you could train from a barracks, for example. Maybe you can do the same for an inventory, like so:

Make an Inventory class that extends FlxGroup.

Make all of your items extend FlxSprite (because an item probably has a picture that goes along with it anyway, and using FlxSprites makes it easy to display the items).

I dunno if that makes sense -- I can give you more detail if you desire =)
Title: Re: An inventory
Post by: Titch on Mon, Mar 14, 2011
Using a vector might be better than a FlxGroup for the purposes of sorting stuff, since if you use a FlxGroup you are locked into using _members to iterate through the contents. If you are doing an inventory I strongly recommend some sort of count on your inventory items so you can stack identical instances to save memory

Code: [Select]

//Begin psudo code
public function addItem ($new_item:Item)
{
for each (var $held_item:Item in inventory)
{
if ($held_item.name == $new_item.name)
{
$held_item.count += $new_item.count;
}
}
Title: Re: An inventory
Post by: Wolfstorm on Thu, Mar 17, 2011
I see what you mean with the count. However, Im not sure what you mean by using a vector.
And yeah, I was just trying to make a FlxGroup to use as ItemLibrary, thanks ^^