Can't walk in class parameter FlxTypedGroup using FlxG.overlap
I want the player to write objects to my game using the code below, but I get:
Bug # 1034: Force Error: Unable to convert flixel :: FlxSprite @ 51e1b69 to Player.
...
FlxG.overlap(weapons, players, onPickup)
}
private function onPickup(wep:Weapon, player:Player):Void
{
//access player function
}
I have already initialized players and weapons as shown below and added to the group
players= new FlxTypedGroup<Player>();
weapons= new FlxTypedGroup<Weapon>();
Weapon
extends FlxSprite
and Player
extends FlxTypedGroup<FlxSprite>
.
I use FlxTypedGroup
it because I want the player to have multiple sprites associated with it.
Please help me to access the player class variables!
If replaced player:Player
with player:FlxSprite
, there is no error, but I can no longer access the class functions Player
.
source to share
I know this is probably a little overdue, but there are a few things you can try:
You can try FlxSpriteGroup
instead Player
instead FlxTypedGroup
. It might take some work to get it to work the way you want it to.
Also, the reason this is giving you an error is because overlap
and collide
will (by default) deploy through your groups until they reach the actual object ...
How to explain ... If you have FlxTypedGroup<Player>
and your object Player
extends FlxTypedGroup<PlayerPart>
(if PlayerPart
extends FlxSprite
or whatever) when you do FlxG.overlap(weapons, players, onPickup)
, the overlap does NOT go to pass the object Player
, it will skip the object PlayerPart
that is overlapped - in fact it will call onPickup
one times for the object EVERYONE PlayerPart
that covers the weapon - perhaps the same thing - it is update
.
You can use this behavior to your advantage, if you can figure it out - make your Player group multiple playlists, but set them all to allowCollisions = NONE
except what will be your hitbox, etc.
There are many things you can do just by figuring out the specifics. Good luck!
source to share