감사합니다. advance ... 다음의 적 클래스를 사용할 때 적들은 무대의 중심을 향해 정확한 각도로 오지 않습니다. 그렇다면 코드를 더 정확하게 수정하기 위해 어떤 변화를해야합니까? 당신이 (X2, Y2)에 x1, y1 지점에서 각도를해야하는 경우적의 위치에서 무대의 중심을 향해 접근하는 적
{
import flash.display.MovieClip;
import flash.events.*;
import flash.display.Stage;
public class Enemy1 extends MovieClip
{
private var BG:MovieClip;
private var speed:Number = 0.5;
public function Enemy1(BG:MovieClip) : void
{
var RandomX:Array = new Array(100,200,300,400,800,900,1000,1100);
var RandomY:Array = new Array(100,200,300,600,700,800);
var r:int = (Math.random() * 8);
var s:int = (Math.random() * 6);
x = RandomX[r];
y = RandomY[s];
this.BG = BG;
addEventListener(Event.ENTER_FRAME, moveEnemy); //false, 0, true);.
}
private function moveEnemy(e:Event):void
{
if (this.x > 660)
{
this.x -= speed;
this.rotation = 180;
}
if (this.x < 540)
{
this.x += speed;
this.rotation = 0;
}
if (this.y > 510)
{
this.y -= speed;
this.rotation = 270;
}
if (this.y < 390)
{
this.y += speed;
this.rotation = 90;
}
if (this.x > 660 && this.y > 510)
{
this.x -= speed;
this.y -= speed;
this.rotation = 225;
}
if (this.x < 540 && this.y < 390)
{
this.x += speed;
this.y += speed;
this.rotation = 45;
}
if (this.x < 540 && this.y > 510)
{
this.x += speed;
this.y -= speed;
this.rotation = 315;
}
if (this.x > 660 && this.y < 390)
{
this.x -= speed;
this.y += speed;
this.rotation = 135;
}
}
}
변경 ... 감사를 제안하십시오 ..
그들은 중심을 가리키고 있지 않거나 물리적으로 움직이지 않고 있습니까? 또한 'BG'는 적의 모양입니까? BG를지나 변수로 설정했지만 표시 목록에 추가하거나 아무것도하지 않는 것이 좋습니다. – Scott
예 .. 그들은 중심쪽으로 움직이고 있지만 특정 방향 유형 (즉, 대각선, 수직 또는 수평)으로 여행하고 있습니다. 그러나 이제 나는 그들이 특정 방향으로뿐만 아니라 회전에 따라 적절한 방향으로 움직여야한다. 위. – MSV