Skip to main content
Known Participant
August 18, 2013
Question

addChild and globaltoLocal

  • August 18, 2013
  • 0 replies
  • 273 views

I have an enemy that adds an attack movie clip. More specifically, this attack movie (We'll call it masterAttack) clip is a blank movie clip that acts like a super class, that will hold other attacks like a weak and strong attack. So when my enemy attacks using a timer, it adds the masterAttack on a global to local point. My problem is, on the first run, the masterAttack will attack the player wherever it is, then remove itself, which is good. Then the next time it runs,  the masterAttack is not hitting the player. It's as if the globaltoLocal isn't working after the first run.

Below is the Enemy timer attacking a tile the player is on:

if (Main.tileset.tileMiddle.hitTestObject(Main.player.visionPoint))

{

         this.addChild(masterAttack);

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

         masterAttack.masterEnemyAttackTimer.start();

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

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

}

And Below is the masterAttack timer:

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);

                              }

                    }

This topic has been closed for replies.