package {
import enemies.Enemy;
import flash.display.Sprite;
import flash.events.*;
public class Main extends Sprite {
// a place to store the enemy
public var enemy:Enemy;
private function handleEnterFrame(e:Event):void {
tweenIt(enemy.x, mouseX, 2);
}
private function tweenIt(variable:Number, target:Number, speed:Number):void{
if (variable < target) {
variable += speed;
}
if (variable > target) {
variable -= speed;
}
}
// this is the first code that is run in our application
public function Main():void {
addEventListener(Event.ENTER_FRAME, handleEnterFrame);
// we create the enemy and store him in our variable
enemy = new Enemy();
// we add the enemy to the stage
addChild(enemy)
enemy.x = Math.random() * stage.stageWidth;
enemy.y = Math.random() * stage.stageHeight;
}
}
}
敌人类已嵌入位图。我正在使用 FlashDevelop 进行编程。当我做像enemy.x+=1 这样的事情时,它可以工作,但是当我尝试使用我的补间脚本时,无论鼠标的位置如何,敌人都会静止不动。谢谢你,布洛布斯塔