2013-10-10 46 views
1

當我在代碼下面運行時,我的預期輸出是玩家應該連續進行動畫製作,並且當用戶點擊屏幕時,玩家應該跳躍。我的球員的框架是不同的,跳轉框架是不同的。我在鼠標左鍵點擊時調用框架。所有幀都被處理,但速度太快,所以動畫不可見。單擊鼠標按鈕後動畫不正確

private void OnUpdate(object sender, GameTimerEventArgs e) 
    { 
     float elapsed = (float)e.ElapsedTime.TotalSeconds; 
     timer5 -= elapsed; 

     TouchPanel.EnabledGestures = GestureType.Tap; 
     TouchCollection touches = TouchPanel.GetState(); 

     MouseState mousestate = Mouse.GetState(); 

     //Texture.position += velocity; 
     //if (rect.Contains(new Microsoft.Xna.Framework.Point(mousestate.X, mousestate.Y)) && mousestate.LeftButton == ButtonState.Pressed) 

     if (mousestate.LeftButton==ButtonState.Pressed) 
     { 
      for (int i = 0; i < 32; i++) 
      { 

       jump(); 
       jumpframe++; 
       if (jumpframe > 24) 
       { 
        jumpframe = 0; 
       } 
       System.Diagnostics.Debug.WriteLine("currentframe:"+ jumpframe); 
      } 
     } 

     if (timer5 <= 0) 
     { 
      playerr(); 
      currentframe++; 
      if (currentframe > 24) 
      { 
       currentframe = 0; 
      } 
      timer5 = TIME_BET_FRAME; 
     } 
    } 

    private void OnDraw(object sender, GameTimerEventArgs e) 
    { 
     SharedGraphicsDeviceManager.Current.GraphicsDevice.Clear(Color.CornflowerBlue); 
     spriteBatch.Begin(); 

     //level.Draw(spriteBatch); 
     rect2 = new Rectangle(0, 0, 960, 620); 
     rect = new Rectangle(0, 0, 420, 300); 

     spriteBatch.Draw(Texture.player[currentframe], Texture.position, Color.White); 
     spriteBatch.Draw(Texture.jumpplayer[jumpframe], Texture.jumpposition,     Color.White); 
     spriteBatch.Draw(Texture.jumpbtn, Texture.rect, Color.White); 
     spriteBatch.DrawString(font, "Score", new Vector2(10, 0), Color.Gold); 
     spriteBatch.End(); 
    } 

    public void jump() 
    { 
     Texture.jumpposition.X = 10; 
     Texture.jumpposition.Y = 243; 
     Texture.position.X = -400; 
     Texture.position.Y = 243;  
    } 

    public void playerr() 
    { 
     Texture.position.X = 10; 
     Texture.position.Y = 243; 
     Texture.jumpposition.X = -400; 
     Texture.jumpposition.Y = 243; 
    } 
+1

你已經說過這個問題 - 「太快了」。通過創建計時器分配作業來減慢速度 – Sinatr

+0

@Sinatr我已經使用timer5播放器.......所以現在我可以使用相同的jumpplayer ??? ... thnx作出迴應 – pravin

+2

也使用一些更易於理解的變量名稱(而不是timer5,rect2 ,東西2000),一個月後你會失去項目的成長。 –

回答

2

我看到的是循環

for(int i=0;i<32;i++){...} 

這是在OnUpdate一次繪製完整的跳躍動畫。

你能做什麼,而不是:

​​

這應當執行的OnUpdate速度(頻率)跳躍的動畫。

+0

矩形相交法的問題 – pravin