2012-06-22 5 views
0

나는 대학에서 나의 과정을위한 플래시 게임을 만들고 있는데, 나는 튜토리얼을 따라 왔지만 내 자신을 위해 그것을 회전시키고있다. 내가 쳤던 한 벽은 총알을 발사하면 오른쪽으로 발사 될뿐입니다. 약간의 움직임으로 위아래로 잠시 동안 고쳐 봤지만 아무것도 일어나지 않고 아무것도 작동하지 않습니다. 같은 총알이 발사하고 무엇을하지 것들로, 내 플레이어 클래스에 대한 코드의글 머리 기호는 오른쪽으로 만 발사됩니까?

패키지 {

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); 




     } 
    } 
} 

}

+0

'B.rotation = rotate;'를'B.rotation = this.rotation; '으로 바꿔보십시오. 'rotation'은 정의되지 않았으므로 그게 올바른 것입니다 (항상 0으로 설정됩니다) 'trace (rotation)'을 사용하여 런타임에 변수가 무엇인지 확인하십시오. – Waltzy

+0

나는 그것을했다. 그러나 아무것도하지 않았다, 각은 1와 -1 사이에서 머물렀다. 내가 그것을 움직이게했을 때마다 –

+0

회전은 라디안이 아니다. 시도 thisx = x + Math.cos (회전) * 속도; 및이 y = y + Math.sin (회전) * 속도; –

답변

0

당신은 라디안에있는 WizardrotationAngle에, 설정하는; 회전은 Bullet으로 전달되며 회전 각도는도 단위가됩니다. UIComponent 클래스가 해당 값을도 단위로 사용하고 도면을 회전하는 데 사용하므로 update() 끝에 this.rotation=newAngle;을 설정하는 것이 좋습니다.

관련 문제