无法使用FlxG.overlap传入FlxTypedGroup类参数

时间:2014-12-15 07:33:14

标签: haxe haxeflixel

我希望玩家使用下面的代码在游戏中拾取物品,但我得到了:

  

错误#1034:类型强制失败:无法将flixel :: FlxSprite @ 51e1b69转换为播放器。

    ...
    FlxG.overlap(weapons, players, onPickup)
}

private function onPickup(wep:Weapon, player:Player):Void
{ 
    //access player function 
}

我已经如下所述初始化了玩家和武器,并添加到了小组

players= new FlxTypedGroup<Player>();
weapons= new FlxTypedGroup<Weapon>();

Weapon延伸FlxSpritePlayer延伸FlxTypedGroup<FlxSprite>

我使用FlxTypedGroup,因为我希望播放器有多个与之相关的精灵。

请帮忙,以便我可以访问播放器类变量!

如果我将player:Player替换为player:FlxSprite,则表示没有错误,但我无法再访问Player类函数。

1 个答案:

答案 0 :(得分:2)

我知道这可能有点晚了,但你可以尝试一些事情:

您可以尝试使用Player代替FlxTypedGroup代替overlap。要让它以您想要的方式工作可能需要一些工作。

此外,它给你一个错误的原因是因为collideFlxTypedGroup<Player>将(默认情况下)向下钻取你的群组,直到找到一个实际的对象......

如何解释...如果您有Player并且FlxTypedGroup<PlayerPart>对象延伸PlayerPart(如果FlxSprite延伸FlxG.overlap(weapons, players, onPickup)或其他内容),则何时你做Player,重叠不会传递PlayerPart对象,它会传递重叠的onPickup对象 - 实际上,它会调用PlayerPart一次每个update对象重叠武器 - 可能是相同的 - allowCollisions = NONE

如果你能搞清楚,你可以利用这种行为 - 让你的玩家组包含多个玩家组,但将所有玩家组都设置为So "Wide String" = "Wide String" and: "Multi-line string here" will be truncated to "Multi-line string here" as you have experienced. ,除了你的命中箱等等。

你可以做很多事情,它只是搞清楚具体细节。祝你好运!