我剛剛開始在C#/ XNA中編碼 我在XNA中製作了一個非常簡單的小程序,它是一個繪製的矩形,內有3個隨機生成的球, 球在自己的類中定義和我已經使用以下用鼠標點擊添加2D精靈
INT ballCount = 3本教程生成 http://www.bluerosegames.com/brg/xna101.aspx
球;
,什麼我想要做的就是讓這麼一個鼠標點擊將增加1整型,加入另一球到屏幕
我的代碼看起來是這樣,但我不知道這是否是正確的/可能
mouseStateCurrent = Mouse.GetState();
if (mouseStateCurrent.LeftButton == ButtonState.Pressed &&
mouseStatePrevious.LeftButton == ButtonState.Released)
{
ballCount = ballCount+1;
}
mouseStatePrevious = mouseStateCurrent;
任何幫助的建議將是有益的:)
我使用一個代碼來繪製球已經看起來像這樣
spriteBatch.Begin();
spriteBatch.Draw(debugColor, TextBox, Color.White);
spriteBatch.Draw(background, backgroundRectangle, Color.White);
foreach (BouncingBall ball in balls)
{
ball.Draw(spriteBatch);
}
spriteBatch.End();
base.Draw(gameTime);
是否可以編輯這個來獲得「點擊添加球」效果?