Author Topic: overriding flxpause, odd issue (dur... fixed)  (Read 1091 times)

zez

  • Active Member
  • ***
  • Posts: 203
  • Karma: +0/-0
    • View Profile
    • Devlog
overriding flxpause, odd issue (dur... fixed)
« on: Thu, May 13, 2010 »
I forgot to set true in share scroll when I added the stuff that was vanishing... heh.
So, I have an inventory screen that is activated by pausing the game, as that seemed like the easiest way to do what I wanted to do. It works totally fine like, 9/10 times, but sometimes it only half loads, and I end up with essentially an empty inventory screen (sometimes it will load some of the text, but not all of it, or most icons but not all of them, sometimes it will just load the background and the bit that says "inventory" and nothing else.... sometimes it gets stuck in whatever half loaded state its in for the whole time Im playing, other times it fixes itself as soon as I close and then re-open it...)
The class itself looks like this V
Code: [Select]
import org.flixel.*;
public class inventory extends FlxGroup
{
private var txt:FlxText;
private var txte:FlxText;
private var stats:FlxText;
private var bg:FlxSprite;
private var bg2:FlxSprite;
private var item:FlxTilemap;
private var eqitem:FlxSprite;
private var i:int = 0;
private var select:FlxSprite;
private var field:int = 0;
private var delay:uint = 0;
[Embed(source = 'data/inventoryicons.png')] private var icons:Class;
[Embed(source = 'data/static.png')] private var imgstatic:Class;
public function inventory()
{
scrollFactor.x = scrollFactor.y = 0;
bg = new FlxSprite();
bg.createGraphic(FlxG.width, FlxG.height, 0xffaa00cc);
bg.blend = "difference";
bg.antialiasing = true;
bg.alpha = 0.8;
bg.scale.x = bg.scale.y = 1.05;
add(bg, true);
bg2 = new FlxSprite(FlxG.width / 10, FlxG.height / 10);
bg2.loadGraphic(imgstatic, true, true, FlxG.width * 0.8, FlxG.height * 0.8);
bg2.color = 0x552399;
bg2.alpha = 0.2;
bg2.antialiasing = true;
add(bg2, true);
txt = new FlxText(0, FlxG.height /8, FlxG.width, "Inventory");
txt.alignment = "center";
txt.size = 24;
txt.color = 0xaa1111;
txt.font = "kremlin";
add(txt, true);
txte = new FlxText((FlxG.width / 8), (FlxG.height / 8) + 32, 100, "Equipment");
txte.size = 12;
txte.color = 0xaa1111;
txte.font = "kremlin";
add(txte, true);
stats = new FlxText((FlxG.width / 8), (FlxG.height / 8) + 64, 100);
stats.size = 12;
stats.color = 0xaa1111;
stats.font = "kremlin";
add(stats);
eqitem = new FlxSprite(FlxG.width / 8, (FlxG.height / 8) + 48);
eqitem.loadGraphic(icons, true, false, 16);
eqitem.frame = 1;
eqitem.color = 0xaaaaff;
add(eqitem, true);
item = new FlxTilemap();
item.x = (FlxG.width / 8) + 24;
item.y = (FlxG.height / 8) + 48;
item.loadMap("1,1,1,1,1", icons, 16);
add(item);
// add last
select = new FlxSprite(FlxG.width / 8, (FlxG.height / 8) + 48);
select.createGraphic(1, 1);
select.origin.x = select.origin.y = 0;
select.alpha = 0.5;
add(select);
}
override public function update():void
{
//select
if (delay > 0)
{
delay -= FlxG.elapsed;
}
if (field == 0)//main-items
{
if (select.scale.x != 104)
{
select.x = FlxG.width / 8;
select.y = (FlxG.height / 8) + 48;
select.scale.x = 108;
select.scale.y = 16;
}
if (FlxG.keys.C || FlxG.keys.V)
{
field = 5;
select.scale.x = select.scale.y = 16;
select.x = (FlxG.width / 8) + 24;
FlxG.resetInput();
}
}
if (field > 5 && field < 9)//submenu-items
{
if (FlxG.keys.Z || FlxG.keys.X)
{
field = 0;
}
if (FlxG.keys.LEFT && delay == 0)
{
delay = 1;
field -= 1;
select.x -= 16;
}
if (FlxG.keys.RIGHT && delay == 0)
{
delay = 1;
field += 1;
select.x += 16;
}
}
if (field == 5)//wraparound
{
if (FlxG.keys.RIGHT && delay == 0)
{
delay = 1;
field += 1;
select.x += 16;
}
if (FlxG.keys.LEFT && delay == 0)
{
delay = 1;
field = 9;
select.x += 64;
}
}
if (field == 9)
{
if (FlxG.keys.LEFT && delay == 0)
{
delay = 1;
field -= 1;
select.x -= 16;
}
if (FlxG.keys.RIGHT && delay == 0)
{
delay = 1;
field = 5;
select.x -= 64;
}
}//end item submenu, mostly
if (FlxG.keys.C || FlxG.keys.V)//selecting from menus
{
//item selection
// be damned sure to update this when more items are added.
if (item.getTileByIndex(field - 5) == 1)
{
if (FlxG.scores[8] > 1)
{
FlxG.scores[8] = 1;
}
if (FlxG.scores[9] > 1)
{
FlxG.scores[9] = 1;
}
}
if (item.getTileByIndex(field - 5) == 2)
{
if (FlxG.scores[8] > 0)
{
FlxG.scores[8] = 2;
}
if (FlxG.scores[9] > 1)
{
FlxG.scores[9] = 1;
}
}
if (item.getTileByIndex(field - 5) == 3)
{
if (FlxG.scores[8] > 1)
{
FlxG.scores[8] = 1;
}
if (FlxG.scores[9] > 0)
{
FlxG.scores[9] = 2;
}
}
}

//make menus
if (FlxG.scores[8] > 0 && i < FlxG.levels[12])//jetpack/wings
{
item.setTileByIndex(i, 2);
i += 1;
}
if (FlxG.scores[8] == 2)
{
eqitem.frame = 2;
}
if (FlxG.scores[9] > 0 && i < FlxG.levels[12])//gravity shoes
{
item.setTileByIndex(i, 3);
i += 1;
}
if (FlxG.scores[9] == 2)
{
eqitem.frame = 3;
}
if (FlxG.scores[8] < 2 && FlxG.scores[9] < 2)//no item, update when there are more items
{
eqitem.frame = 1;
}
if (FlxG.level == 0)
{
FlxG.pause = false;
}
//stats!
stats.text = "STATS" + "\n" + "Fire Rate: " + FlxG.scores[0] + "\n" + "Attack: " + FlxG.scores[2] + "\n" + "Jumps: " + FlxG.scores[10];
bg.draw(FlxState.screen);
bg2.randomFrame();
bg2.facing = FlxU.random() * 2;
super.update();
}
}

}
Im not really sure what Im doing wrong here, and like I said, it works most of the time, just sometimes it breaks itself for no real reason, as far as I can tell.[/s]
« Last Edit: Sat, May 15, 2010 by zez »