HaxeFlixel / flixel-addons

Additional classes for HaxeFlixel
170 stars 139 forks source link

FlxNestedSprite show flixel default icon when no image loaded #413

Closed itulau closed 10 months ago

itulau commented 10 months ago

I've noticed FlxNestedSprite shows the Flixel default icon when there isn't an image nor graphic loaded which seems to be the default behavior of draw() inherited from FlxSprite. So every FlxNestedSprite that itself doesn't render anything but contains children will have a default icon hidden within it by default. Screenshot from 2023-12-19 16-30-16

flixel-addons: 3.2.1 flixel:5.5.0

Geokureli commented 10 months ago

is this happening on flixel 5.5.0 or are you using the dev github branch, or an older version of flixel?

itulau commented 10 months ago

Edited the description, but I'm on flixel 5.5.0

itulau commented 10 months ago

Could reproduce in latest dev version of flixel/flixel-addons

Geokureli commented 10 months ago

thanks for clarifying. Truthfully FlxNestedSprite is not actively maintained, or well-understood by the current team, so we tend to recommend FlxSpriteGroup as a substitute. In fact, it would be very helpful to hear why you chose it, and how you're using it. I've thought about deprecating this class, since it seems so niche and problematic

if you wanted to make a PR to fix this, I think it makes sense, and (in my limited knowledge of FlxNestedSprite) seems like an easy change

itulau commented 10 months ago

Hi, I've noticed that FlxNestedSprite works better for the use-case I need right now: a group of sprites that represents a character where one sprite acts as the collider and the rest of the sprites are just visual and do not interact with the collisions. To my limited knowledge from my testings, it seems that FlxSpriteGroup was not designed for this because when collision occurs, the rest of the sprites simply ignore this. With FlxNestedSprite I could get, more or less, the result I was looking for with practically the same code.

FlxSpriteGroup:

Peek 2023-12-20 15-34

FlxNestedSprite:

Peek 2023-12-20 15-36

And for a solution, yes, I've already found one, by simply guarding the call for drawing of the current FlxNestedSprite with a null check for _frame (the same variable that's used for adding the default png) the problem goes away.. now the thing is that I'm not experienced enough with Flixel to be sure if this solution might have unintended side-effects by not allowing the draw() call to occur anyway.

I wouldn't mind opening a PR if this is not an issue.

image

Geokureli commented 10 months ago

I wouldn't mind opening a PR if this is not an issue.

Yes, please!

I've noticed that FlxNestedSprite works better for the use-case I need right now: a group of sprites that represents a character where one sprite acts as the collider and the rest of the sprites are just visual and do not interact with the collisions. To my limited knowledge from my testings, it seems that FlxSpriteGroup was not designed for this because when collision occurs, the rest of the sprites simply ignore this.

Yeah FlxSpriteGroups collide as groups, which is kind of annoying. I almost added the ability for spritegroups to collide as if it was a single sprite but I wasn't entirely happy with it and plan to revisit it later.

itulau commented 10 months ago

Closed by https://github.com/HaxeFlixel/flixel-addons/pull/415