1

In Flixel, you cannot add a FlxSprite to another one, like you could with Flash API (Sprites were subclasses of DisplayObject). So if you want 2 Sprites to behave like parent and child, you still have to animate them separately. This can become a nightmare if you use Tweens too.

For example, imagine a rotating spaceship that has attached thrusters, or a moving character that wears an armor, hat, shield etc.

Is there a way to have a 'child' Sprite acting like it was added into a 'parent' one, so that it updates automatically its position, scale and rotation accordingly? For example, during their FlxGroup's update() function?

I'm interested in HaxeFlixel 3.3.1, although it doesn't really matter, as this applies for all versions and ports of Flixel.

Edit: I noticed that HaxeFlixel features FlxSpriteGroup, which is supposed to handle the multiple Sprites. But this is a new feature, and I'm pretty sure that flixel developers are using different approaches for the rest of the flixel ports.

Gama11
  • 31,714
  • 9
  • 78
  • 100
yannicuLar
  • 3,083
  • 3
  • 32
  • 50

2 Answers2

1

There's a limited version of this available using: http://api.haxeflixel.com/flixel/addons/display/FlxNestedSprite.html

martyman
  • 867
  • 8
  • 14
  • true, but as you said it's limited. I have issues working with the scaling : https://groups.google.com/forum/embed/?place=forum/haxeflixel&showsearch=true&showpopout=true&showtabs=true&parenturl=http://haxeflixel.com/forum/&afterlogin&pli=1#!topic/haxeflixel/AY5RhvKOI3k – yannicuLar Mar 04 '15 at 06:54
1

HaxeFlixel provides FlxSpriteGroup and FlxNestedSprite which both can be used to have some sprites behaving as a group. In both approaches, I had a problem updating the angle and scale properties, however updating the position seems to work fine.

If you are not interested to animate the sprites separately, and painting one sprite over another is what you're after, FlxSprite's stamp() function could be what you need (e.g. draw a helmet over your character)

yannicuLar
  • 3,083
  • 3
  • 32
  • 50
  • Did you open any issues about the angle/scale? I'm running into a problem with scale as well for `FlxSpriteGroup`. `FlxNestedSprite` doesn't seem to exist. – ashes999 Apr 04 '15 at 20:53
  • 1) FlxNestedSprite is an extra library you can import: flixel-addons https://github.com/HaxeFlixel/flixel-addons – yannicuLar Apr 04 '15 at 22:22
  • 2) But FlxNestedSprite had the same issues, so i opened a issue https://github.com/HaxeFlixel/flixel-addons/issues/156 – yannicuLar Apr 04 '15 at 22:25
  • 3) I shared a fix, not merged yet : https://github.com/HaxeFlixel/flixel-addons/pull/157 – yannicuLar Apr 04 '15 at 22:27