Author Topic: FlxG.Elapsed != accurate?  (Read 902 times)

Minverva

  • Active Member
  • ***
  • Posts: 126
  • Karma: +0/-0
    • View Profile
FlxG.Elapsed != accurate?
« on: Thu, Sep 26, 2013 »
Using Flixel 2.34

I use it a lot, but it seems like the shotclock for one of my enemy types gets really screwed up.

Normally this enemy only spawns at the start of a playstate and it seems fine then, but I've been working on the boss and under some circumstances he'll spawn this enemy - and it seems like FlxG.elapsed is going faster as more of these enemies are spawned.

Any ideas?

The shotclock is basically

shotclock += FlxG.elapsed;

and that's the only time it is changed other than to reset it to zero after firing.

I'm wondering if the update function is somehow being called more frequently, but I have no idea why that would be happening. My other guess is that somehow the shotclock variable is being shared for all of these enemies and every time they are spawned the update functions collectively gets more FlxG.elapsed added per cycle.

It isn't totally game-breaking since these guys don't spawn unless the player is incorrectly trying to beat the boss, but I really would like to understand it.


Arkeus

  • Contributor
  • ****
  • Posts: 321
  • Karma: +1/-0
    • View Profile
    • I, Arkeus
Re: FlxG.Elapsed != accurate?
« Reply #1 on: Thu, Sep 26, 2013 »
Is it a static variable? If so it would be shared, and each one would be updating the same one, which would explain the behavior you're seeing.

Also make sure you aren't adding the same object each time you spawn an enemy. If you add it to the state (or any group in the state), it will have update called multiple times (one for each time it was added).

Minverva

  • Active Member
  • ***
  • Posts: 126
  • Karma: +0/-0
    • View Profile
Re: FlxG.Elapsed != accurate?
« Reply #2 on: Fri, Sep 27, 2013 »
Thanks so much.

I'm kind of learning as I go. Thanks for explaining the static variable thing to me. I'd earlier suspected that was the problem and so I changed it, but that didn't fix it.

I was unintentionally adding the same object - update was being called more frequently.

Thanks again for the help.