View Full Version : [AS2] Teleporting
Bobthedwarf
08-30-2008, 11:58 PM
I'm trying to make a game that revolves around teleporting between enemies to assassinate them, but I have no idea how to script teleporting like that. Does anyone have any ideas? Would it just have to do with telling flash to move the player's location when they teleport? If so, how would I tell flash to teleport behind an enemy? :confused:
syruplord
08-31-2008, 01:46 AM
You'll just need to refer to the enemy's x-coordinates.
Like to make the hero appear behind an enemy, you might do
hero._x = enemy._x+25;
to make him appear 25 pixels to the right of the enemy.
Bobthedwarf
08-31-2008, 02:54 AM
Thanks, syrup. Is there a way for the same script to refer to different enemies, though? Like if I have enemy1 moving on one platform and enemy2 moving on a different platform.
Also, another script that I just can't find anywhere on the internet or figure out in flash is how to make the camera follow the hero. Any help would be greatly appreciated!
Bobthedwarf
08-31-2008, 03:40 AM
I would also like to know if there is any way to click (or target in any way) an enemy with the mouse to specify the enemy being teleported behind
neilmmm
08-31-2008, 02:45 PM
does this
var targetX:Number;
var targetY:Number;
var time:Number;
function targetRef() {
targetX = this._x;
targetY = this._y;
time = setTimeout(delay, 500);
}
function delay() {
hero.onEnterFrame = function() {
hero._alpha -= 5;
if (hero._alpha<=0) {
delete hero.onEnterFrame;
hero._x = targetX-((Math.random()*100)-50);
hero._y = targetY-((Math.random()*100)-50);
hero.onEnterFrame = function() {
hero._alpha += 5;
if (hero._alpha>=100) {
delete hero.onEnterFrame;
}
};
}
};
}
for (i=0; i<5; i++) {
var target:MovieClip = this.attachMovie("enemy", "enemy"+i, this.getNextHighestDepth());
target._x = Math.floor(Math.random()*(Stage.width-target._width));
target._y = Math.floor(Math.random()*(Stage.height-target._height));
target.inner_txt.text = "E "+i;
target.onRelease = targetRef;
}
var hero:MovieClip = this.attachMovie("hero", "hero", this.getNextHighestDepth());
hero._x = Math.floor(Math.random()*(Stage.width-hero._width));
hero._y = Math.floor(Math.random()*(Stage.height-target._height));
hero.inner_txt.text = "Hero";
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.