Author Topic: Resize Sprites according to its animation  (Read 1501 times)

cloudcamaleoniv

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Resize Sprites according to its animation
« on: Mon, Aug 1, 2011 »
Hello there, I did a little search here and on google but haven't found a way to resize the sprite effectively.

Well, the problem is simple (or not, dont know):

I have a spritesheet of a guy standing, jumping, falling, walking and running, every frame has the same width/height, it works brilliantly. But now I decided that this guy is going to get down when I press the Down Arrow. Okay, I added the "down graphic" in my spritesheet, it has the same width, but THE HEIGHT IS DIFFERENT. Now the guy is supposedly able to pass under tight gaps, but his height (his bouding box height) stays the same. I don't know what to do.

I changed the property "height" but his "y" property went crazy. I changed the frameHeight and... it went crazy again, I hope you guys can help. Thanks.

mightiest_hero

  • Member
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: Resize Sprites according to its animation
« Reply #1 on: Tue, Aug 2, 2011 »
try change offset.y

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Resize Sprites according to its animation
« Reply #2 on: Tue, Aug 2, 2011 »
Change his height and adjust his offset.y to compensate (visually), then swap it back again when he stands up again.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

ExpertNovice

  • Active Member
  • ***
  • Posts: 124
  • Karma: +0/-0
  • Now we're cookin' with bacon!
    • View Profile
Re: Resize Sprites according to its animation
« Reply #3 on: Tue, Aug 2, 2011 »
Yeah offset is what collides, not the sprite.

I usually just leave a big alpha gap above the guy so he fits in with the spritesheet and into the game with simpler code.

cloudcamaleoniv

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Resize Sprites according to its animation
« Reply #4 on: Tue, Aug 2, 2011 »
Thanks guys... but I don't know where I'm doing it wrong. In fact, I did what I was looking for (using the offset.y + height combination), but I did in a way that I suspect that can cause some unwanted problems after... I posted a parte of my code here

If you guys could see it for me...

private var _player:FlxSprite;
override public function update():void
{
     etc etc etc
     etc etc etc
     etc etc etc

     if (FlxG.keys.DOWN)
     {
        _player.play("down");
        if (_player.height != 15) // Here begins the wtf
        {
           _player.offset.y = 7;
           _player.height = 15;
           _player.y += 7;
        }
     }
     else
     {
        if (_player.height != 22) // Here begins the wtf too
        {
           _player.offset.y = 0;
                  _player.height = 22;
           _player.y -= 7;
        }
     }
}

Ok, this is it, my animation flows good, but I fear to see some problem ahead, you guys think it's good enough? Thanks in advance

ExpertNovice

  • Active Member
  • ***
  • Posts: 124
  • Karma: +0/-0
  • Now we're cookin' with bacon!
    • View Profile
Re: Resize Sprites according to its animation
« Reply #5 on: Wed, Aug 3, 2011 »
You shouldn't have to move the player's position.  That's all I'd work about.

Bounding box size should shrink, and then be offset accordingly.

The sprite should be ducking so that he/she drops to the ground there.
Empty space above.  Don't center the ducking graphics, just move it to the bottom.

Moving the object should work but I get the same bad feeling lol.


I didn't spot any problems, but I'm pretty new.  Is it causing any problems?

cloudcamaleoniv

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Resize Sprites according to its animation
« Reply #6 on: Thu, Aug 4, 2011 »
I did it.