2012-04-16 4 views
0

왼쪽 및 오른쪽 키를 누르면 화면 아래쪽에서 왼쪽에서 오른쪽으로 이동하는 스프라이트가 있습니다.스프라이트 촬영

나는 화면 맨 아래로 움직이는 스프라이트에서 무언가 (원하는 스프라이트를 원한다)를 쏘아서 그 스프라이트를 바로 위로 올리길 원한다.

어떻게하면됩니까?

+0

촬영 버튼을 사용하면의 좌표에서 새로운 총알 객체를 생성해야 누르면 플레이어가 원하는 방향으로 속도를 줄 수 있습니다. –

+0

더 자세히 설명해 주시겠습니까? 아니면 자습서가 있습니까? 방금 XNA를 배우기 시작했고 그게 우둔한 이유입니다. 나는 그것을 봤고 예를 들어 현재 일반적으로 그들이 다른 클래스와 함께 일한 적이 있거나 현재 프로젝트를 보여줍니다. 스프라이트를로드하고 싶을 때 스페이스 바를 누르면 스프라이트가 움직이는 스프라이트의 위치에 나타나게되고 스프라이트가 움직여 화면에 도달 할 때까지 스프라이트가 올라간다. – Claud

+0

자, 먼저 사용자가 스페이스 바를 눌렀다는 것을 알아야합니다. 그걸 멀리 봤어? –

답변

1

당신이 그 클래스를 나눌 때 다음과 같이 보일 것 복사 정확히 붙여 넣기 만하지 마십시오

namespace SpaceInvadersGame 
{ 
    class Player : Microsoft.Xna.Framework.Game 
    { 
     Texture2D PlayerTexture; 
     Vector2 PlayerPosition; 

     public Player() 
     { 

     } 

     protected override void LoadContent() 
     { 
      PlayerTexture = Content.Load<Texture2D>(@"Images/freshman2");; 
      PlayerPosition = Vector2.Zero; 
      base.LoadContent(); 
     } 

     public Vector2 GetPosition() 
     { 
      return this.PlayerPosition; 
     } 

     public void Update() 
     { 
      KeyboardState keyboardState = Keyboard.GetState(); 
      if (keyboardState.IsKeyDown(Keys.Left)) 
       freshamPos.X -= freshmanSpeed; 
      if (keyboardState.IsKeyDown(Keys.Right)) 
       freshamPos.X += freshmanSpeed; 
      if(keyboardState.IsKeyDown(Keys.Space)) 
       theBullet = new Bullet(this); 
     } 

     public void Draw(SpriteBatch SpriteBatch) 
     { 

     } 
    } 
} 

namespace SpaceInvadersGame 
{ 
    class Bullet : Microsoft.Xna.Framework.Game 
    { 
     Texture2D BulletTexture; 
     Vector2 BulletPosition; 
     Player thePlayer; 

     public Bullet(Player player) 
     { 
      this.thePlayer = player; 
     } 

     protected override void LoadContent() 
     { 
      BulletTexture = Content.Load<Texture2D>(@"Images/bullet");; 
      BulletPosition = thePlayer.GetPosition(); 
      base.LoadContent(); 
     } 

     public void Update() 
     { 
      //in here is where you would just do something like: 
      //BulletPosition.Y += 1; 
     } 

     public void Draw(SpriteBatch SpriteBatch) 
     { 

     } 
    } 
}