Author Topic: Overriding in Groups  (Read 803 times)

superbany

  • Member
  • **
  • Posts: 53
  • Karma: +0/-0
  • [Please enter text here]
    • View Profile
    • Superbany's games
Overriding in Groups
« on: Tue, Feb 15, 2011 »
For my platformer game, I've made my Player object extend FlxGroup, so that I can account for different parts of the body. The var _playerBody within that group handles all the physics, with _playerEyes following it.

What I'm wondering is: Is there any way to override functions for just one of the objects? I would normally put an override function at the end of my Player class, but that would affect the entire group, which doesn't actually collide with anything. I want to do things such as override hitBottom to reset the double jump counter, but only for _playerBody, since it is the only part that actually collides against the tilemap.

I could probably figure out a way to get the desired effect another way, but I just wanted to know if this is possible. Thanks.

Billy

  • Active Member
  • ***
  • Posts: 159
  • Karma: +0/-0
  • Herper of Derps
    • View Profile
    • billy.wenge-murphy.com
Re: Overriding in Groups
« Reply #1 on: Tue, Feb 15, 2011 »
No, you'd need to create classes for these different kinds of objects, and then override the relevant method in each class. Create a Body class and then override its hitBottom method.

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Overriding in Groups
« Reply #2 on: Wed, Feb 16, 2011 »
You'd have to do this anyway, as an FlxGroup doesn't have a hitBottom, hitTop, etc methods to over-ride anyway! It's just a container for sprites.

Player extends FlxGroup
Eyes extends FlxSprite
Body extends FlxSprite

Sorted.. over-ride just the bits you need.
http://www.photonstorm.com



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

superbany

  • Member
  • **
  • Posts: 53
  • Karma: +0/-0
  • [Please enter text here]
    • View Profile
    • Superbany's games
Re: Overriding in Groups
« Reply #3 on: Wed, Feb 16, 2011 »
Oh, okay. Thanks.
I was hoping I wouldn't have to, but I guess I'll have to make a PlayerBody class for this. Thanks anyways.