Author Topic: FlxSubState displays but doesn't update  (Read 1604 times)

smacks

  • Member
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
FlxSubState displays but doesn't update
« on: Wed, Mar 7, 2012 »
Hey folks!

So i'm doing several substates for pause, options etc.
Those substates are drawn, all the objects displays but they are not updated, the main problem is that buttons doesn't work, as the isBlocking feature of FlxSubState.

However when i use the substates i created as FlxState with FlxG.switchState() method everything is working fine, but it behaves as a simple FlxState so i miss substates functionnalities.

I got the FlxState.as and FlxSubState.as from the github of IQAndreas so they should be valid, and i followed the EZPlatformer + substates example https://github.com/IQAndreas/EZPlatformer so i got the same declaration and structure as in the example.

Here is how i trigger my PauseState:
Code: [Select]

if (FlxG.keys.justPressed("P"))
{
        this.setSubState(new PauseState(), onMenuClosed);
}
and the PauseState:

Code: [Select]
package
{
import org.flixel.*;

/**
* ...
* @author ...
*/
public class PauseState extends FlxSubState
{
public static const TO_GAME:String = "PauseState::to_game";
public static const TO_MENU:String = "PauseState::to_menu";
public var btnMenu:FlxButton;
public var btnOptions:FlxButton;
public var btnResume:FlxButton;
public var btnRetry:FlxButton;
public var pauseText:FlxText;
public var scoreText:FlxText;
public var scoreVal:FlxText;
private var cornerTL:FlxSprite = new FlxSprite(94, 86,null);
private var cornerTR:FlxSprite = new FlxSprite(356, 86,null);
private var cornerBL:FlxSprite = new FlxSprite(94, 420,null);
private var cornerBR:FlxSprite = new FlxSprite(356, 420,null);

public function PauseState()
{
super(true, 0x88000000, true);
}
public override function create():void
{
cornerTL.loadGraphic(RegAssets.CORNER, false, true, 24, 24, false);
cornerTL.angle = 0;
cornerTR.loadGraphic(RegAssets.CORNER, false, true, 24, 24, false);
cornerTR.angle = 90;
cornerBL.loadGraphic(RegAssets.CORNER, false, true, 24, 24, false);
cornerBL.angle = 270;
cornerBR.loadGraphic(RegAssets.CORNER, false, true, 24, 24, false);
cornerBR.angle = 180;

btnOptions = new FlxButton(190, 268, 100, 40, "OPTIONS", clickOptions);
btnOptions.setLabelFormat("OPTIONS", Fonts.lest, 20, 0xFF875959, "center");
btnMenu = new FlxButton(190, 316, 100, 40, "MENU", clickMenu);
btnMenu.setLabelFormat("MENU", Fonts.lest, 20, 0xFF875959, "center");
btnRetry = new FlxButton(100, 402, 100, 40, "RETRY", clickRetry);
btnRetry.setLabelFormat("RETRY",Fonts.lest, 26, 0xFFe14c4c, "center");
btnResume = new FlxButton(286, 402, 100, 40, "RESUME", clickResume);
btnResume.setLabelFormat("RESUME",Fonts.lest, 26, 0xFFe14c4c, "center");

pauseText = new FlxText(104, 88, 100, "PAUSE", false);
pauseText.setFormat(Fonts.lest, 30, 0XFF808492, "left");
scoreText = new FlxText(180, 200, 100, "SCORE", false);
scoreText.setFormat(Fonts.lest, 20, 0XFF808492, "center");
scoreVal = new FlxText(180, 220, 100, String(Reg.scoreThisLevel), false);
scoreVal.setFormat(Fonts.lest, 20, 0XFF808492, "center");

add(cornerTL);
add(cornerTR);
add(cornerBL);
add(cornerBR);

add(pauseText);
add(scoreText);
add(scoreVal);
add(btnResume);
add(btnMenu);
add(btnRetry);
add(btnOptions);

super.create();
}

public function clickMenu():void
{
FlxG.log("Menu");
this.close(TO_MENU);
FlxG.switchState(new MenuState());
}
public function clickOptions():void
{
FlxG.log("Options");
this.closeSubState();
}
public function clickResume():void
{
FlxG.log("Resume");
this.close(TO_GAME);
}
public function clickRetry():void
{
FlxG.log("Retry");
this.close(TO_GAME);
}
}
}


Any ideas? i'm nearly out of stamina for that bug :)

Thanks in advance,

Max.

smacks

  • Member
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: FlxSubState displays but doesn't update
« Reply #1 on: Tue, Mar 13, 2012 »
sry to up but still strugling with it!

Arkeus

  • Contributor
  • ****
  • Posts: 321
  • Karma: +1/-0
    • View Profile
    • I, Arkeus
Re: FlxSubState displays but doesn't update
« Reply #2 on: Tue, Mar 13, 2012 »
Can you post the entire class that the first snippet is from?

smacks

  • Member
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: FlxSubState displays but doesn't update
« Reply #3 on: Tue, Mar 13, 2012 »
It's my playstate and the first snippet is in it's update function, it's kind of big and messy for now but if you want to check there it is :p ( at the end of the update)

Code: [Select]
package
{
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;

/**
* ...
* @author Maxime GUY
*/

public class PlayState extends FlxState
{
[Embed(source = "../sound/bfxr/mp3/S_HIT1.mp3")]
protected var S_HIT1:Class;

private var shipA:Ship;
private var shipB:Ship;
private var ships:Ships;
private var beamA:Beam;
private var beamB:Beam;
private var beams:Beams;
private var chain:Chain;
private var level:Level;
private var enemy:Enemy;
private var enemies:Enemies;
private var enemyWeapon:EnemyWeapon;
private var cannons:Cannons;
private var shipWeapon:ShipWeapon;
private var mat:Materials;
private var effects:Effects;
private var explosions:Explosions;
private var hud:HUD;
private var bg:BG;
private var dText:DynamicText;
private var starfield:StarField;
private var startPosX:Array = [ -40, 0, 480, 520];
private var lastDroper:Ship;


override public function create():void
{
super.create();
FlxG.flash(0xff13151e, 1.4, null, false);
FlxG.mouse.hide();

bg = new BG();
starfield = new StarField(270);
enemyWeapon = new EnemyWeapon();
cannons = new Cannons();
shipWeapon = new ShipWeapon();
shipA = new Ship("A",80, 680);
shipB = new Ship("B", 360, 680);
ships = new Ships();

dText = new DynamicText();
level = new Level();
enemies = new Enemies();
mat = new Materials();
effects = new Effects();
explosions = new Explosions();
beamA = new Beam();
beamB = new Beam();
beams = new Beams();
chain = new Chain();
hud = new HUD();



//  Display list
add(bg);
add(starfield);
add(level);

//add(beamA);
//add(beamB);
add(enemies);
add(shipWeapon);
add(explosions);
add(chain)
add(shipA);
add(shipB);
add(ships);
add(beams);
add(effects);
add(mat);
add(dText);
add(cannons);
add(enemyWeapon);
add(hud);

ships.ships.add(shipA);
ships.ships.add(shipB);

Reg.level = level;
Reg.ships = ships;
Reg.shipA = shipA;
Reg.shipB = shipB;
Reg.effects = effects;
Reg.explosions = explosions;
Reg.mat = mat;
Reg.enemies = enemies;
Reg.hud = hud;
Reg.enemyWeapon = enemyWeapon;
Reg.shipWeapon = shipWeapon;
Reg.dText = dText;
Reg.beamA = beamA;
Reg.beamB = beamB;
Reg.beams = beams;
Reg.cannons = cannons;

level.init(Reg.currentLevel);

Reg.shipWeapon.create("LINK", 0, 1);
}

override public function update():void
{
Reg.splitDist = getDist(Reg.shipA.x, Reg.shipA.y, Reg.shipB.x, Reg.shipB.y);

if (Reg.shipA.invul == true || Reg.shipB.invul == true)
{
FlxG.overlap(Reg.ships.shields, Reg.enemies.MINIONSGroup, SHIP_SHIELD_ENNEMY);
FlxG.overlap(Reg.ships.shields, Reg.enemyWeapon.MOVINGroup, SHIP_SHIELD_ENNEMYMOVSHOOT);
FlxG.overlap(Reg.ships.shields, Reg.enemyWeapon.STATICGroup, SHIP_SHIELD_ENNEMYSTATSHOOT);
FlxG.overlap(Reg.ships.shields, Reg.beams.enemyGroup, SHIP_SHIELD_ENNEMYBEAM);
}
else
{
FlxG.overlap(Reg.ships.ships, Reg.enemyWeapon.MOVINGroup, SHIP_ENNEMYMOVSHOOT);
FlxG.overlap(Reg.ships.ships, Reg.enemyWeapon.STATICGroup, SHIP_ENNEMYSTATSHOOT);
FlxG.overlap(Reg.ships.ships, Reg.beams.enemyGroup, SHIP_ENNEMYBEAM);
FlxG.overlap(Reg.ships.ships, Reg.mat, SHIP_MATERIALS);
}
if (Reg.BOSS)
{
Reg.hud.displayTimer();
if (Reg.enemies.boss1)
{
FlxG.overlap(Reg.ships.ships, Reg.enemies.boss1, SHIP_BOSS);
FlxG.overlap(Reg.shipWeapon, Reg.enemies.boss1.collisionGroup, SHOOT_BOSS);
FlxG.overlap(chain, Reg.enemies.boss1.collisionGroup, CHAIN_BOSS);
}
else if (Reg.enemies.boss2)
{
FlxG.overlap(Reg.ships.ships, Reg.enemies.boss2, SHIP_BOSS);
FlxG.overlap(Reg.shipWeapon, Reg.enemies.boss2, SHOOT_BOSS);
FlxG.overlap(chain, Reg.enemies.boss2, CHAIN_BOSS);
}
}
else
{
Reg.hud.bossTimer.exists = false;
FlxG.overlap(Reg.ships.ships, Reg.enemies.MINIONSGroup, SHIP_ENNEMY);
FlxG.overlap(Reg.shipWeapon, Reg.enemies.MINIONSGroup, SHOOT_ENNEMY);
FlxG.overlap(chain, Reg.enemies, CHAIN_ENEMY);
FlxG.overlap(Reg.beams.shipGroup,Reg.enemies.MINIONSGroup,  BEAM_ENNEMY);
}

if (!Reg.shipA.alive || !Reg.shipB.alive)
{
chain.exists = false;
if (Reg.splitDist > 220)chain.exists = false;
}
else chain.exists = true;
if (!Reg.shipA.exists || !Reg.shipB.exists)
{
chain.exists = false;
if (Reg.splitDist > 220)chain.exists = false;
}

if (Reg.lifeA <= 0 && Reg.lifeB <= 0)
{
setSubState(new GameOverState(), onMenuClosed);
}

if (FlxG.keys.justPressed("P"))this.setSubState(new PauseState(), onMenuClosed);
if (FlxG.keys.justPressed("O")) this.setSubState(new OptionState(), onMenuClosed);


//   CHEAT
if (FlxG.keys.justPressed("I")) ++Reg.powA, ++Reg.powB, Reg.hud.addPow("A"), Reg.hud.addPow("B");


super.update();
}
private function onMenuClosed(state:FlxSubState, result:String):void
{
if (result == PauseState.TO_GAME)
{
this.setSubState(null);
}
else if (result == PauseState.TO_MENU)
{
FlxG.switchState(new MenuState());
}
}

//  SHIP

private function SHIP_ENNEMY(shipTMP:Ship,enemyTMP:Enemy):void
{
if (shipTMP.near && shipTMP.alive && !shipTMP.invul)
{
Reg.shipA.die();
Reg.shipB.die();
}
else if (!shipTMP.stick && shipTMP.alive && !shipTMP.invul) shipTMP.die();
enemyTMP.kill();
}

private function SHIP_ENNEMYMOVSHOOT(shipTMP:Ship,shootTMP:Shoot):void
{
if (shipTMP.stick && shipTMP.alive && !shipTMP.invul)
{
Reg.shipA.die();
Reg.shipB.die();
}
else if (!shipTMP.stick && shipTMP.alive && !shipTMP.invul) shipTMP.die();
shootTMP.kill();
}

private function SHIP_ENNEMYSTATSHOOT(shipTMP:Ship,shootTMP:StaticShoot):void
{
if (shipTMP.stick && shipTMP.alive && !shipTMP.invul)
{
Reg.shipA.die();
Reg.shipB.die();
}
else if (!shipTMP.stick && shipTMP.alive && !shipTMP.invul) shipTMP.die();
shootTMP.kill();
}
private function SHIP_ENNEMYBEAM(shipTMP:Ship,shootTMP:Beam):void
{
if (FlxCollision.pixelPerfectCheck(shipTMP as FlxSprite, shootTMP as FlxSprite))
{
if (shipTMP.stick && shipTMP.alive && !shipTMP.invul)
{
Reg.shipA.die();
Reg.shipB.die();
}
else if (!shipTMP.stick && shipTMP.alive && !shipTMP.invul) shipTMP.die();
shootTMP.kill();
}

}
private function SHIP_SHIELD_ENNEMY(shieldTMP:FlxSprite, enemyTMP:Enemy):void
{
if (FlxCollision.pixelPerfectCheck(shieldTMP, enemyTMP as FlxSprite))
{
enemyTMP.kill();
}
}
private function SHIP_SHIELD_ENNEMYMOVSHOOT(shieldTMP:FlxSprite, shootTMP:Shoot):void
{
if (FlxCollision.pixelPerfectCheck(shieldTMP as FlxSprite, shootTMP as FlxSprite))
{
shootTMP.kill();
}
}
private function SHIP_SHIELD_ENNEMYSTATSHOOT(shieldTMP:FlxSprite, shootTMP:StaticShoot):void
{
if (FlxCollision.pixelPerfectCheck(shieldTMP as FlxSprite, shootTMP as FlxSprite))
{
shootTMP.kill();
}
}
private function SHIP_SHIELD_ENNEMYBEAM(shieldTMP:FlxSprite, shootTMP:Beam):void
{
if (FlxCollision.pixelPerfectCheck(shieldTMP as FlxSprite, shootTMP as FlxSprite))
{
shootTMP.kill();
}
}
private function BEAM_ENNEMY(shootTMP:Beam,enemyTMP:Enemy):void
{
if (FlxCollision.pixelPerfectCheck(shootTMP as FlxSprite, enemyTMP as FlxSprite))
{
shootTMP.kill();
if (shootTMP.ship == "A") Reg.shipA.chainUpdate();
else if (shootTMP.ship == "B") Reg.shipB.chainUpdate();
enemyTMP.hit(20);
}
}
private function SHIP_BOSS(shipTMP:Ship,bossTMP:FlxObject):void
{
if (shipTMP.stick && shipTMP.alive && !shipTMP.invul)
{
Reg.shipA.die();
Reg.shipB.die();
}
else if (!shipTMP.stick && shipTMP.alive && !shipTMP.invul) shipTMP.die();
bossTMP.hurt(100);
}


private function SHOOT_ENNEMY(shootTMP:Shoot,enemyTMP:Enemy):void
{
enemyTMP.killer = shootTMP.ship;
if (FlxCollision.pixelPerfectCheck(shootTMP as FlxSprite, enemyTMP as FlxSprite))
{
shootTMP.kill();
enemyTMP.hit(20);
}
}

private function CHAIN_ENEMY(chainTMP:FlxObject,enemyTMP:Enemy):void
{
if (FlxCollision.pixelPerfectCheck(chainTMP as FlxSprite, enemyTMP as FlxSprite))
{
enemyTMP.hit(2);
}
}

private function SHOOT_BOSS(shootTMP:FlxObject,bossTMP:FlxObject):void
{
if (FlxCollision.pixelPerfectCheck(shootTMP as FlxSprite, bossTMP as FlxSprite))
{
shootTMP.kill();
bossTMP.hurt(20);
}
}
private function CHAIN_BOSS(chainTMP:FlxObject,bossTMP:FlxObject):void
{
if (FlxCollision.pixelPerfectCheck(chainTMP as FlxSprite, bossTMP as FlxSprite))
{
bossTMP.hurt(2);
}
}

//  MAT

private function SHIP_MATERIALS(shipTMP:Ship,matTMP:Material):void
{
if (FlxCollision.pixelPerfectCheck(shipTMP as FlxSprite, matTMP as FlxSprite))
{
if (shipTMP.stick)
{
if (shipTMP.tag == lastDroper.tag)
{
if (shipTMP.tag == "A")
{
if (matTMP.tag == "POW")Reg.shipB.load(false,matTMP.value),matTMP.kill(), lastDroper = Reg.shipB;
else if (matTMP.tag == "LIFE") Reg.shipB.load(true, matTMP.value), matTMP.kill(), lastDroper = Reg.shipB;
}
else if (shipTMP.tag == "B")
{
if (matTMP.tag == "POW")Reg.shipA.load(false,matTMP.value),matTMP.kill(), lastDroper = Reg.shipA;
else if (matTMP.tag == "LIFE") Reg.shipA.load(true, matTMP.value), matTMP.kill(), lastDroper = Reg.shipA;
}
}
}
else
{
if (matTMP.tag == "POW")shipTMP.load(false,matTMP.value),matTMP.kill(), lastDroper = shipTMP;
else if (matTMP.tag == "LIFE") shipTMP.load(true, matTMP.value), matTMP.kill(), lastDroper = shipTMP;
}

if (matTMP.tag == "CHUNK")matTMP.kill(),++Reg.chunkThisGame;
}
}

public function pause():void
{
//level.stop();

}

public function options():void
{

}


/* IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
* IIIIIIIIIIII -UTILS- IIIIIIIIIIIII
* IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII*/

public function getDist (x1:int, y1:int, x2:int, y2:int):int
{
var dx:int = x1 - x2;
var dy:int = y1 - y2;
var dist:int = Math.sqrt(dx*dx + dy*dy);
return dist;
}

private function randomInt(low:int, high:int):int
{
return Math.random() * (1+high-low) + low;
}
}
}

martijnreintjes

  • Member
  • **
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: FlxSubState displays but doesn't update
« Reply #4 on: Tue, Mar 27, 2012 »
nobody?
I seem to have the same problem ...

sheitman

  • New Member
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: FlxSubState displays but doesn't update
« Reply #5 on: Mon, Apr 2, 2012 »
Yeah, I'm having the same issue as well. I call the substate with isBlocking set to true, it appears, but my State doesn't pause its update function. (and my subState doesn't update).

Any update about this?

IQAndreas

  • Member
  • **
  • Posts: 35
  • Karma: +0/-0
    • View Profile
    • IQAndreas.com
Re: FlxSubState displays but doesn't update
« Reply #6 on: Fri, Aug 31, 2012 »
I am so very sorry for not answering your questions. I don't often check the Flixel forums and didn't even know this thread existed!

Do any of you still need help with FlxSubState? You guys are very welcome to ask me for help on Skype (username "IQAndreas") or you can send an email by using this contact form: http://iqandreas.github.com/contact/