Hi. If the hero is on the screen and you press I, then the following happens
if (Input.pressed(Key.I))
{
if (inventoryUp == false)
{
trace("added inventory");
FP.world.add(inventory);
inventoryUp = true;
}
else
{
trace("removed inventory");
FP.world.remove(inventory);
inventoryUp = false;
}
}
As you can see, it toggles the inventory. This is the code in inventory.as:
package
{
import net.flashpunk.Entity;
import net.flashpunk.utils.Key;
import net.flashpunk.utils.Input;
import net.flashpunk.FP
import Talent.Armor;
public class Inventory extends Entity
{
[Embed(source = "Panels/inventory.oel", mimeType = "application/octet-stream")] private static const INVENTORY:Class;
private var add:int = 0;
private var armor:Armor = new Armor(10, 10);
public function Inventory():void
{
}
override public function update():void
{
if (Hero.inventoryUp && add == 0)
{
var level:InventoryParser = InventoryParser(FP.world.add(new InventoryParser(INVENTORY)));
FP.world.add(armor);
add++;
}
if(Hero.inventoryUp && add != 0)
{
var level = null;
FP.world.remove(armor);
}
}
}
}
For some reason, when the player toggles the inventory (as shown before), the whole content of inventory.as doesn’t get removed. So that’s problem number one.
Problem number two lies within inventory.as.
The inventory code doesn’t add “armor”, but only the inventory window. (this is remedied if I make it so that it adds an armor through “FP.world.add(new armor(blablabalblal))” But I can’t even remove it then, so yeah…
I don’t get it why it doesn’t remove “armor” and the inventory window (the inventory window is generated through an .oel file made in OGMO.
Here is the oel, btw.
package
{
import net.flashpunk.Entity;
import net.flashpunk.utils.Key;
import net.flashpunk.utils.Input;
import net.flashpunk.FP
import Talent.Armor;
public class Inventory extends Entity
{
[Embed(source = "Panels/inventory.oel", mimeType = "application/octet-stream")] private static const INVENTORY:Class;
private var add:int = 0;
private var armor:Armor = new Armor(10, 10);
public function Inventory():void
{
}
override public function update():void
{
if (Hero.inventoryUp && add == 0)
{
var level:InventoryParser = InventoryParser(FP.world.add(new InventoryParser(INVENTORY)));
FP.world.add(armor);
add++;
}
if(Hero.inventoryUp && add != 0)
{
var level = null;
FP.world.remove(armor);
}
}
}
}
Thanks in advance