영웅이 던진 칼 (총알이라고 생각하십시오)을 사용하여 타일 맵에 닿으면 검 (총알)이 죽습니다 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