0
我有劍(認爲他們是子彈),英雄投擲,當它擊中地圖時劍(子彈)殺死使用kill()
方法。 但意外的事情發生了。當使用kill()
時,exists = false或visible = false所有組都不見了(死亡或不可見)。
這些都是一些片段:在FlxG.collide()回調函數:殺死一個物品從一個組中殺死組的其餘部分
Sword.as(base class for all swords) shoot function :
public function shoot(playerPosition:FlxPoint, direction:uint):void{
if(!alive || !exists){
revive();
}
x = playerPosition.x;
y = playerPosition.y;
if(direction == FlxObject.RIGHT) {
angularVelocity = 900;
velocity.x = 400;
} else {
angularVelocity = 900;
velocity.x = -400;
}
}
的Sword(BasicSword)
子類只有劍圖形所以它不值得一提。
PlayState.as
create (only part of it):
for(var i:int = 0; i < 15;i++) {
sword = new BasicSword(-200, -200);
swords.add(sword);
}
add(swords);
更新:
override public function update():void{
if(FlxG.keys.justPressed("X")) {
(swords.recycle(BasicSword) as BasicSword).shoot(new FlxPoint(player.x,
player.y),player.facing);
}
super.update();
FlxG.collide(level, player);//make the player stand on the level.
FlxG.collide(level, swords, swordsHitLevel);
}
swordsHitLevel(callback function):
public function swordsHitLevel(level:FlxTilemap, sword:FlxSprite):void {
sword.kill();
}
您是否找到了解決方案? – yannicuLar