나는 대학에서 나의 과정을위한 플래시 게임을 만들고 있는데, 나는 튜토리얼을 따라 왔지만 내 자신을 위해 그것을 회전시키고있다. 내가 쳤던 한 벽은 총알을 발사하면 오른쪽으로 발사 될뿐입니다. 약간의 움직임으로 위아래로 잠시 동안 고쳐 봤지만 아무것도 일어나지 않고 아무것도 작동하지 않습니다. 같은 총알이 발사하고 무엇을하지 것들로, 내 플레이어 클래스에 대한 코드의글 머리 기호는 오른쪽으로 만 발사됩니까?
패키지 {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class Wizard extends MovieClip {
private var dx:Number;
private var dy:Number;
private var Bulletspeed:int;
public var Angle:Number;
public var newAngle:Number;
var shotCoolDown:int;
const MAX_COOLDOWN=20;
public function Wizard() {
//constructor
//Shot cool down
shotCoolDown=MAX_COOLDOWN;
addEventListener(Event.ENTER_FRAME, update);
//set up an event listener for when the turret is added to stage
addEventListener(Event.ADDED_TO_STAGE, initialise);
}
function initialise(e:Event) {
//reduce shot cool down by one
shotCoolDown=shotCoolDown-1;
//add a click listener to the stage
stage.addEventListener(MouseEvent.CLICK, fire);
}
function fire(m:MouseEvent) {
//Able to shoot
if (shotCoolDown<=0) {
//resets cool down
shotCoolDown=MAX_COOLDOWN;
//spawn bullet
var B = new Bullet();
//set position and rotation of the bullet
B.rotation=rotation;
B.x=x;
B.y=y;
//add the bullet the the wizard
parent.addChild(B);
}
}
function update():void {
//Shot cool down
shotCoolDown--;
//Make the Wizard face the mouse
if (parent!=null) {
dx=stage.mouseX-this.x;
dy=stage.mouseY-this.y;
Math.abs(dx);
Math.abs(dy);
var Angle=Math.atan2(dy,dx);
var newAngle = Angle * (180/Math.PI);
if ((0 < newAngle) && (newAngle <= 90)) {
gotoAndPlay("Right");
} else if ((90 < newAngle) && (newAngle <= 180)) {
gotoAndPlay("Down");
} else if ((-180 < newAngle) && (newAngle <= -90)) {
gotoAndPlay("Left");
} else if ((-90 < newAngle) && (newAngle <= 0)) {
gotoAndPlay("Up");
}
this.rotation=Angle;
}
}
}
}
. 문제를 알고 있다고 생각합니다. 나머지 마법사 업데이트와 링크해야합니다. 하지만 어떻게 해야할지 모르겠다. 필요한 경우 총알 클래스가있다.
패키지 {
import flash.display.Sprite;
import flash.events.Event;
public class Bullet extends Sprite {
private var speed:int;
private var myCharacter:Wizard;
public function Bullet() {
//constructor
speed = 10;
addEventListener(Event.ENTER_FRAME, update);
}
function update (e:Event) {
//Move in the direction the bullet is facing
x=x+Math.cos(rotation/180*Math.PI)*speed;
y=y+Math.sin(rotation/180*Math.PI)*speed;
//Clears bullet once it leaves the stage
if (x<0 || x>500 || y<0 || y>500) {
//removes the update listner
removeEventListener(Event.ENTER_FRAME, update);
parent.removeChild(this);
}
}
}
}
'B.rotation = rotate;'를'B.rotation = this.rotation; '으로 바꿔보십시오. 'rotation'은 정의되지 않았으므로 그게 올바른 것입니다 (항상 0으로 설정됩니다) 'trace (rotation)'을 사용하여 런타임에 변수가 무엇인지 확인하십시오. – Waltzy
나는 그것을했다. 그러나 아무것도하지 않았다, 각은 1와 -1 사이에서 머물렀다. 내가 그것을 움직이게했을 때마다 –
회전은 라디안이 아니다. 시도 thisx = x + Math.cos (회전) * 속도; 및이 y = y + Math.sin (회전) * 속도; –