Author Topic: Lag fixes when game is minimized then restored..?  (Read 1230 times)

Powster

  • New Member
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Sometimes when I test my project in flash develop it runs perfectly. But.. sometimes when I test it it runs insanely slow. It ruins the game completely when it runs that slow but if I minimize the flash window then restore the flash window it runs perfectly.

Does anyone have any idea why that would be happening? I already put the flash/flixel refresh rates at 30 since I thought maybe that was the problem.

Honestly I do not know why the game would be lagging at all. I have one object/class (not sure what you call it) that consists of a lot of buttons. A few flxtext numbers that get updated in the playstate, 3 flxdelay timers (and 3 flxbars to show the progress of the flxdelay timers). Then.. three flxsprites that move, and one flxsprite that follows the mouse's y coordinate and a flxsprite bullet that shoots towards the 3 sprites that do not move. I do not even create multiple bullets just one bullet for the whole game which should make it run even better.....

Code: [Select]
override public function update():void
{
//track the mouse Y
var num:Number = FlxG.mouse.y;
//have the bow follow mouse Y
bow.y = num - 30;
//if bullet hits shield then nothing..
if (FlxCollision.pixelPerfectCheck(arrow, shield))
{
arrow.x = 26;
arrow.exists = false;
changeX = changeXBase;

trace("blocked bullet");

}
//if bullet hits body
if (FlxCollision.pixelPerfectCheck(arrow, enemyBody))
{
score += 1;
trace(score);
//reset arrow's x position and set it to not exist
arrow.x = 26;
arrow.exists = false;
//reset power charging of bow
changeX = changeXBase;
trace("body hit")

//change body to hit body pic
enemyBody.loadGraphic(ebodyHitPic);
//start delay till hit body pic is reset to the normal body pic
hitPicChangeDelay.start();
}

if (FlxCollision.pixelPerfectCheck(arrow, enemyHead))
{
score += 5;
//reset power charging of bow
changeX = changeXBase;
//move the body, head, and shield up if the head is hit
var moveNum:int = FlxMath.rand( -30, -10);
enemyBody.y += moveNum;
enemyHead.y += moveNum;
shield.y += moveNum;
trace("head hit");
//reset arrow's x position and set it to not exist
arrow.x = 26;
arrow.exists = false;
//show enemy head hit pic
enemyHead.loadGraphic(eheadHitPic);
//start delay till head hit pic is reset to the normal head pic
hitPicChangeDelay.start();
}

//when the delay timer expires then restore the original body and head pics
if (hitPicChangeDelay.hasExpired)
{
enemyBody.loadGraphic(ebodyPic);
enemyHead.loadGraphic(eheadPic);
}


var justReleased:Boolean = FlxG.mouse.justReleased();

var pressed:Boolean = FlxG.mouse.pressed();

//make sure charge, charging bar, and bullet's y position reset when nothing is happening
if (arrow.exists == false && pressed==false && justReleased==false)
{
changeX = changeXBase;
arrow.y = num - 6;
powerBar.percent = 0;
}
else
{
// if bullet is flying then keep flying unless it goes out of bounds
arrow.x += power;
arrow.y -= power;
if (arrow.x > 500 || arrow.y>350)
{
arrow.x = 26;
arrow.exists = false;
}
}

//if mouse is pressed down then raise the charging of the bow
if (pressed == true)
{
if (changeX < 12)
{
changeX += 1;
powerBar.percent += 20

}
}

//when mouse is released shoot the bullet, only allow one bullet to be shot at a time
if (justReleased == true && arrow.exists == true)
{
powerBar.percent = 0;
power = changeX;

changeX = changeXBase;
arrow.reset(26, num-6);
}
else if (justReleased == true && arrow.exists==false)
{
powerBar.percent = 0;
power = changeX;

changeX = changeXBase;
arrow.reset(26, num-6);
}
super.update();
}

DaSjieb

  • Member
  • **
  • Posts: 9
  • Karma: +0/-0
    • View Profile
    • My personal website
Re: Lag fixes when game is minimized then restored..?
« Reply #1 on: Wed, Dec 18, 2013 »
That's really odd indeed, no idea why that would happen. You could always check the debug info by pressing "\", see the memory usage and the time it takes to draw and update (D and  U respectively). See if there's any changes there. The way you describe your setup, lags shouldn't be happening indeed. But what's insanely slow? Just a short span of low framerates or occasional hickups? Or "grinding to a screeching" halt slow that persists unless you minimize and restore your window again?

Some generic advice: make sure your flashplayer is up-to-date and use the latest version of flixel. But that's just generic advice ;)
I'm a webdeveloper that also makes games, and I love to listen and play underground house. If you also like underground housemusic I recommend checking out my soundcloud at http://soundcloud.com/louieg

Powster

  • New Member
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Lag fixes when game is minimized then restored..?
« Reply #2 on: Wed, Dec 18, 2013 »
By insanely slow I meant the FPS was multiple times slower than it should be. When I minimized the window and restored the game would run smoothly which was something like 5 times faster than it was with the lag.

After updating my flash player it seems the problem was fixed though.