Sunday, 18 August 2013

globaltoLocal in addchild

globaltoLocal in addchild

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.
Below is the Enemy timer attacking a tile the player is on:
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.masterAttackx = (pt.x);
this.enemymagic.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);
}
}
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.

No comments:

Post a Comment