我正在製作2D空間射擊遊戲,我遇到了一個屏蔽電源問題。盾牌使得玩家在敵人船隻碰撞一段時間後無敵。當玩家碰撞加電時,玩家離開加電位置一段時間後立即無敵,加電從屏幕上移除,一切正常。然而,我所遇到的問題是玩家仍然可以與其進行碰撞,即使它被從畫面中移出,這意味着玩家可以簡單地呆在那個地方,永遠無敵。所以一旦玩家與盾牌發生碰撞,我就會喜歡它,所以玩家不能再次與它碰撞。我嘗試過在線搜索,但沒有發現任何特別有用的東西。 我也想再次使用這個功能。在未來,我計劃在我的滾動背景中「隨機」添加它們。不知道這是否會添加任何內容只是想我會包括它。非繪製雪碧仍然活躍xna
game1.cs
public double counterPower = 0;
public bool powerUpCollision = false;
public bool invincibility = false;
Sprite shieldPower;
bool isVisible = true;
protected override void Initialize()
{
shieldPower = new Sprite();
}
protected override void LoadContent()
{
if (isVisible == true)
{
shieldPower.LoadContent(this.Content, "powerUpShield");
shieldPower.Position.X = 300;
shieldPower.Position.Y = 300;
}
}
protected override void Update(GameTime theGameTime)
{
powerUps(theGameTime);
}
public void powerUps (GameTime theGameTime)
{
if (mPlayer.boundingBox.Intersects(shieldPower.boundingBoxShieldPower))
{
if (shieldPower.isVisible == true)
{
Console.WriteLine("collision working");
powerUpCollision = true;
invincibility = true;
isVisible = false;
if (powerUpCollision == true && invincibility == true)
{
lives = lives - 0;
}
counterPower = 0;
}
}
counterPower += theGameTime.ElapsedGameTime.TotalSeconds;
{
Console.WriteLine(counterPower);
if (counterPower > 7)
{
powerUpCollision = false;
invincibility = false;
}
}
protected override void Draw(GameTime theGameTime)
{
spriteBatch.Begin();
if (isVisible == true)
{
shieldPower.Draw(this.spriteBatch);
}
}
spriteBatch.End();
在精靈類是開機的邊框,這工作正常。 我有更多的代碼和類,但我相當肯定它有很多與這個問題無關,我也不想浪費你的時間。
任何幫助將不勝感激。 謝謝。
找不出如何修改的信息(我是新來的#1),但我也想再次使用這個權力了。在未來,我計劃在我的滾動背景中「隨機」添加它們。不知道這是否會添加任何內容只是想我會包括它。 – Anonymous5642
您可以使用標籤下方的「編輯」鏈接(評論部分上方)編輯帖子。 –
謝謝,Ben N. – Anonymous5642