2013-08-18 34 views
0

我有一個敵人,增加了一個攻擊影片剪輯。更具體地說,這個攻擊影片(我們稱它爲masterAttack)是一個空白的影片剪輯,它像一個超級類似的行爲,可以進行其他攻擊,如弱和強烈的攻擊。所以當我的敵人使用定時器進行攻擊時,它會在全局到本地點上添加masterAttack。globaltoLocal in addchild

下面是敵人計時器攻擊拼貼的球員是:

if (Main.tileset[k].tileMiddle.hitTestObject(Main.player.visionPoint)) 
{ 
     this.addChild(masterAttack); 
     var pt:Point = this.enemymagic.globalToLocal(new Point(Main.tileset[k].x, Main.tileset[k].y)); 
     masterAttack.masterEnemyAttackTimer.start(); 

     this.masterAttack.x = (pt.x); 
     this.masterAttack.y = (pt.y); 
} 

而且下面是masterAttack定時器:

function mastertimer(event:TimerEvent) { 
        addChild(sludgeball); //This is one of the many attacks pickable by the masterAttack 
           sludgeball.enemyattackTimer.start(); 
           if (this.sludgeball.currentLabel == "End") { 
             this.sludgeball.gotoAndPlay(1); 
             masterEnemyAttackTimer.stop(); 

           if (masterEnemyAttackTimer.running == false) 
           { 
             attackStop = true; 
             this.parent.removeChild(this); 
             removeChild(sludgeball); 
           } 
        } 

我的問題是,在第一次運行時,masterAttack會在任何地方攻擊玩家,然後移除自己,這很好。然後下一次運行時,masterAttack不會擊中玩家。就好像globaltoLocal在第一次運行後不工作。

回答

0
this.addChild(masterAttack); 

var pt:Point = this.enemymagic.globalToLocal(new Point(Main.tileset[k].x, Main.tileset[k].y)); 

您添加masterAttack到這一點,但您使用enemymagic的globalToLocal

所以改變這樣

var pt:Point = this.globalToLocal(new Point(Main.tileset[k].x, Main.tileset[k].y)); 
+0

行哎呀對不起了PT。爲了舉例,我將它改爲masterAttack。第一個代碼在敵人身上,通過計時器運行。 – Bindlestick

+0

我已經編輯了答案 – Pan

+0

所以我從pt var中移除敵方魔法師/ masterAttack。我會試一試。謝謝。 – Bindlestick