【问题标题】:globaltoLocal in addchildaddchild 中的 globaltoLocal
【发布时间】:2013-08-20 16:53:07
【问题描述】:

我有一个添加了攻击影片剪辑的敌人。更具体地说,这个攻击影片(我们称之为masterAttack)剪辑是一个空白影片剪辑,它的作用就像一个超类,它将持有其他攻击,如弱攻击和强攻击。因此,当我的敌人使用计时器进行攻击时,它会将 masterAttack 添加到全局到本地点。

下面是敌人计时器攻击玩家所在的瓷砖:

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 在第一次运行后不起作用。

【问题讨论】:

    标签: actionscript-3 flash addchild


    【解决方案1】:
    this.addChild(masterAttack);
    
    var pt:Point = this.enemymagic.globalToLocal(new Point(Main.tileset[k].x, Main.tileset[k].y));
    

    您将 masterAttack 添加到此,但您使用enemymagic 的 globalToLocal 获得了 pt

    所以这样改行

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

    【讨论】:

    • 糟糕,抱歉。我将其更改为 masterAttack 只是为了举例。第一个代码在敌人中,通过计时器运行。
    • 所以我从 pt var 中删除了enemymagic/masterAttack。我会试一试。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2014-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-20
    • 1970-01-01
    相关资源
    最近更新 更多