Author Topic: An inventory  (Read 1707 times)

Wolfstorm

  • Member
  • **
  • Posts: 8
  • Karma: +0/-0
    • View Profile
An inventory
« 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.)

bpercevic

  • Member
  • **
  • Posts: 87
  • Karma: +2/-0
    • View Profile
Re: An inventory
« Reply #1 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?

Wolfstorm

  • Member
  • **
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: An inventory
« Reply #2 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)

Berzee

  • Member
  • **
  • Posts: 69
  • Karma: +0/-0
    • View Profile
Re: An inventory
« Reply #3 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 =)

Titch

  • Contributor
  • ****
  • Posts: 270
  • Karma: +0/-0
  • Thing with the guy in the place.
    • View Profile
Re: An inventory
« Reply #4 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;
}
}
Free cake whippings every day at #flixel on irc.freenode.net.

Wolfstorm

  • Member
  • **
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: An inventory
« Reply #5 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 ^^