2013-09-01 2 views
0

나는 Xna를 처음 접했고 나는 그것을 눌렀을 때 mi 코드의 다른 gamestate로 이동하여 검색을하고 내가 말한 문제를 발견 할 때 도움이 필요하다.Windows Phone 이미지로 버튼

public class MainFile : Microsoft.Xna.Framework.Game 
{ 
    GraphicsDeviceManager graphics; 
    SpriteBatch spriteBatch; 
    ScreenStates screentState; 

    Rectangle TouchS_Y_X; 

    Logo logo; 
    Menu0 menu; 
    Choose_Pets choose_pets; 
    ScreenStates.CurrentGameState GameState; 

    public MainFile() 
    { 
     graphics = new GraphicsDeviceManager(this); 
     Content.RootDirectory = "Content"; 

     // Frame rate is 30 fps by default for Windows Phone. 
     TargetElapsedTime = TimeSpan.FromTicks(333333); 

     // Extend battery life under lock. 
     InactiveSleepTime = TimeSpan.FromSeconds(1); 

    } 


    protected override void Initialize() 
    { 
     // TODO: Add your initialization logic here 
     screentState = new ScreenStates(); 
     logo = new Logo(); 
     menu = new Menu0(); 
     choose_pets = new Choose_Pets(); 
     base.Initialize(); 

    } 


    protected override void LoadContent() 
    { 
     TouchS_Y_X = new Rectangle(0, 0, 1, 1); 
     // Create a new SpriteBatch, which can be used to draw textures. 
     spriteBatch = new SpriteBatch(GraphicsDevice); 
     GameState = ScreenStates.CurrentGameState.Logo; 

     this.logo.Load(this.Content, this.GraphicsDevice); 
     this.menu.Load_Menu(GraphicsDevice, Content); 
     this.choose_pets.Load_ChoosePet(Content, GraphicsDevice); 

     base.LoadContent(); 
    } 


    protected override void UnloadContent() 
    { 
     // TODO: Unload any non ContentManager content here 
     //this.logo.Unload_logo(Content); 
    } 

    protected override void Update(GameTime gameTime) 
    { 
     // Allows the game to exit 
     if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) 
      this.Exit(); 

     #region Games States 

     switch (GameState) 
     { 
      case ScreenStates.CurrentGameState.Logo: 
        logo.Update_logo(gameTime); 

        if (logo.FadeOut_logo == true) 
         GameState = ScreenStates.CurrentGameState.Menu; 
        break; 

      case ScreenStates.CurrentGameState.Menu: 
       menu.Update_Menu(gameTime); 

       if (menu.IsPlayClicked == true) 
        GameState = ScreenStates.CurrentGameState.CharactersChooser; 

       break; 

      case ScreenStates.CurrentGameState.CharactersChooser: 
        choose_pets.Update_petchoose(gameTime); 
       break; 
     } 
     #endregion 

     // TODO: Add your update logic here 
     base.Update(gameTime); 
    } 


    protected override void Draw(GameTime gameTime) 
    { 
     GraphicsDevice.Clear(Color.Black); 
     spriteBatch.Begin(); 
     #region GameStateDraw 



     switch(GameState) 
     { 
      case ScreenStates.CurrentGameState.Logo:   
      logo.Draw(spriteBatch);  
      break; 

       //Menu Draw State 
      case ScreenStates.CurrentGameState.Menu: 
      menu.Draw_Menu(spriteBatch); 
      break; 

      case ScreenStates.CurrentGameState.CharactersChooser: 
       choose_pets.Draw_petChoose(spriteBatch); 
      break; 
     } 

     #endregion 

     spriteBatch.End(); 
     base.Draw(gameTime); 
    } 
} 
:이 시도하지만 버튼 아무것도 IsPlayClicked 내가 여기 내 maincode에 전화를 공공 부울 입니다 일어나지 누를 때 늘 일이

 TouchLocation tl; 
    TouchCollection touchCollection = TouchPanel.GetState(); 


     if (tl.State == TouchLocationState.Pressed) 
     { 

      if (tl.State == TouchLocationState.Pressed) 
       if (ButtonRecPlay.Contains(new Point((int)tl.Position.X, (int)tl.Position.Y))) 
       { 
        IsPlayClicked = true; 
       } 
     } 

을 수행하는 것은 내 주요 코드

이것은 게임 메뉴에 사용하는 광산 Menu0 파일이며

class Menu0 
    { 
    Texture2D Text2D_Background; 
    Rectangle Rec_Background; 

    Texture2D ButtonText2DPlay; 
    Rectangle ButtonRecPlay; 

    Boolean Music_playing = false; 
    public Song BackMusic; 

    TouchLocation tl; 
    TouchCollection touchCollection = TouchPanel.GetState(); 

    public bool IsPlayClicked = false; 

    MainFile main = new MainFile(); 

    public void Load_Menu(GraphicsDevice Graphics_Menu, ContentManager Content_Menu) 
    { 

     //main = new MainFile(); 

     Text2D_Background = Content_Menu.Load<Texture2D>("UI\\MenuBack"); 
     Rec_Background = new Rectangle(0, 0, Graphics_Menu.Viewport.Width, Graphics_Menu.Viewport.Height); 

     ButtonText2DPlay = Content_Menu.Load<Texture2D>("UI\\Buttons\\New Games"); 
     ButtonRecPlay = new Rectangle(350, 250, 150, 60); 

     BackMusic = Content_Menu.Load<Song>("UI\\Music_01"); 

    } 

    public void Update_Menu(GameTime Menu_GameTime) 
    { 
     if (Music_playing == false) 
     { 
      MediaPlayer.Play(BackMusic); 
      Music_playing = true; 
     } 
     MediaPlayer.Resume(); 


     if (tl.State == TouchLocationState.Pressed) 
     { 

      if (tl.State == TouchLocationState.Pressed) 
       if (ButtonRecPlay.Contains(new Point((int)tl.Position.X, (int)tl.Position.Y))) 
       { 
        IsPlayClicked = true; 
       } 
     } 
    } 

    public void Draw_Menu(SpriteBatch Spritebatch_Menu) 
    { 
     Spritebatch_Menu.Draw(Text2D_Background, Rec_Background, Color.White); 
     Spritebatch_Menu.Draw(ButtonText2DPlay, ButtonRecPlay, Color.White); 
    } 
} 

답변

0

은 당신이 할 일은 터치가 바로 해제 될 때 감지하기 위해, 이전 TouchLocationState마다주기를 얻을 수 있습니다 : 그것은 여기에 버튼을 누르해야 할 가정의 코드를 가지고있는 코드입니다. 그 순간 귀하는 gameState을 변경하거나 필요한 모든 방법을 호출하십시오.

어쨌든, 난 당신이 TouchCollection 선언 한 것으로 볼 수 있지만 당신이 그것을 사용하지 않을 :

TouchCollection touchCollection = TouchPanel.GetState(); 

당신은 그 모음을 검사하고 그 안에 모든 TouchLocation를 분석하거나, 단순히 마지막 하나가 필요

if (touchCollection.Count > 0) 
{ 
    TouchLocation tl = touchCollecion.Last(); 

    if (tl.State == TouchLocationState.Released && previousState == TouchLocationState.Pressed) 
     { 
     if (ButtonRecPlay.Contains((int)tl.Position.X, (int)tl.Position.Y)) 
      IsPlayClicked = true; 
     } 
} 
+0

당신을위한 많은 Thx 대답 지금 당장 제가 시험해 볼 것입니다. 지금 문제가 있습니다. 문제가 해결되면 작동하는지 알려 드리겠습니다. xDD – user2727653

+0

AAh! 많은 thx 그것이 작동 나는 당신에게 upvote 줄 싶었지만 담당자가 없어 내가 당신을 줄 수있는 유일한 것은 많은 thx xDDDDD^- ^/thxx입니다 !! – user2727653

+0

LOL 걱정하지 마세요. – pinckerman

관련 문제