Author Topic: FlxSprites playing the same animation?[solved]  (Read 1283 times)

zez

  • Active Member
  • ***
  • Posts: 203
  • Karma: +0/-0
    • View Profile
    • Devlog
So, Im layering FlxSprites in my game to allow for some character customization, and make the different equipment a bit more appealing, and I ran into a problem.
Currently, all the possible equipment has the same animations, and (almost) the same events triggering them. I say almost, because things like velocity checks are done against the players, as the equipment isnt actually moving. The issue is that occasionally the animations dont trigger at the exact same time, and something ends up out of sync with everything else.

I tried to just say _curFrame = _player._curFrame and _curAnim = _player.curAnim, but I either get an error about an attempted access of inaccessible property error on the player, or if I assign something in the players update to set itself to that value, and then reference that, it doesn't error, but also freezes.
« Last Edit: Wed, Mar 24, 2010 by zez »

cai

  • Contributor
  • ****
  • Posts: 465
  • Karma: +0/-0
  • the illest of villains
    • View Profile
    • Brandon Cash
Re: FlxSprites playing the same animation?
« Reply #1 on: Wed, Mar 24, 2010 »
It sounds like you're using several completely separate sprites, rather than several sprites from one class.  It would be best to have several sprites inside of your Player class, and have the same code update all of the sprites at the same time.
Follow me on Twitter | Come join us at #flixel on irc.freenode.net!

zez

  • Active Member
  • ***
  • Posts: 203
  • Karma: +0/-0
    • View Profile
    • Devlog
Re: FlxSprites playing the same animation?
« Reply #2 on: Wed, Mar 24, 2010 »
huh... I umm... didnt even think to do that. Thankee.

zez

  • Active Member
  • ***
  • Posts: 203
  • Karma: +0/-0
    • View Profile
    • Devlog
Re: FlxSprites playing the same animation?
« Reply #3 on: Wed, Mar 24, 2010 »
er wait... now Im a little confused... I cant add a sprite inside of a sprite, and if I make the player some other type that isnt a sprite, how is that any different from just doing it in the playstate or something? Or am I missing something?
Never mind, I feel really dumb, I just passed the equipment to the player when I added it to the game... I once again, feel really dumb.
« Last Edit: Wed, Mar 24, 2010 by zez »

cai

  • Contributor
  • ****
  • Posts: 465
  • Karma: +0/-0
  • the illest of villains
    • View Profile
    • Brandon Cash
Re: FlxSprites playing the same animation?
« Reply #4 on: Wed, Mar 24, 2010 »
I cant add a sprite inside of a sprite

Sure you can!  Just add a variable to your Player class that is a FlxSprite:
Code: [Select]
private var childSprite:FlxSprite = new FlxSprite;

...and manipulate it as you see fit.  For instance, you'll probably want to update its X and Y coordinates to match its parent:
Code: [Select]
override public function update():void
{
childSprite.x = x;
childSprite.y = y;
}
Follow me on Twitter | Come join us at #flixel on irc.freenode.net!