Xna 碰撞时不出现爆炸?
这个项目是关于快速驾驶和躲避障碍物。我遵循了一些教程,并设法创建了一个爆炸类。无论何时发生碰撞,爆炸都会出现,但事实并非如此 没有错误,但我认为问题出在Game1.cs中。我在Game1.cs中创建了以下函数:Xna 碰撞时不出现爆炸?,xna,collision,explode,Xna,Collision,Explode,这个项目是关于快速驾驶和躲避障碍物。我遵循了一些教程,并设法创建了一个爆炸类。无论何时发生碰撞,爆炸都会出现,但事实并非如此 没有错误,但我认为问题出在Game1.cs中。我在Game1.cs中创建了以下函数: //list List <Explosion> explosionList = new List<Explosion>(); //This is in the update method foreach (Explosion ex in explosi
//list
List <Explosion> explosionList = new List<Explosion>();
//This is in the update method
foreach (Explosion ex in explosionList)
{
ex.Update(gameTime);
}
//This is a method called manage explosions
public void ManageExplosions()
{
for (int i = 0; i < explosionList.Count; i++)
{
if (explosionList[i].isVisible)
{
explosionList.RemoveAt(i);
i--;
}
}
}
//This is placed in the CheckCollision method
explosionList.Add(new Explosion(Content.Load<Texture2D>("Images/explosion3"), new Vector2(theHazard.Position.X, theHazard.Position.Y)));
Hazard.cs
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
namespace DriveFast
{
class Hazard
{
public Vector2 Position;
public bool Visible = true;
public Hazard()
{
}
}
}
首先,您需要绘制道路、汽车、危险等后的爆炸图。替换下一个代码,如下所示:
DrawRoad();
DrawHazards();
spriteBatch.Draw(mCar, mCarPosition, new Rectangle(0, 0, mCar.Width, mCar.Height), Color.White, 0, new Vector2(0, 0), 0.2f, SpriteEffects.None, 0);
// place code here
foreach (Explosion ex in explosionList)
{
ex.Draw(spriteBatch);
}
//
成管爆炸法制作!isVisible而不是isVisible:
public void ManageExplosions()
{
for (int i = 0; i < explosionList.Count; i++)
{
if (!explosionList[i].isVisible)
{
explosionList.RemoveAt(i);
i--;
}
}
}
注释下一个测试代码:
if (mCurrentState == State.Crash)
{
//DrawTextDisplayArea();
//DrawTextCentered("Crash!", 200);
//DrawTextCentered("Press 'Space' to continue driving.", 260);
}
太多的代码。如果您可以共享项目,我可以提供帮助。如何附加代码?[linkname]()没有whitespaces@Wallstrider链接有效吗?是的,我解决了问题,现在将回复新答案。你也可以删除链接。是的,请。非常感谢,我真的很感激。在你下载之后,我会删除链接,以防止下载别人的。太好了。非常感谢。
public void ManageExplosions()
{
for (int i = 0; i < explosionList.Count; i++)
{
if (!explosionList[i].isVisible)
{
explosionList.RemoveAt(i);
i--;
}
}
}
foreach (Hazard aHazard in mHazards)
{
if (CheckCollision(aHazard) == true)
{
//remove next line because it is duplicate of adding Explosion which is already added inside CheckCollision(Hazard) method
//explosionList.Add(new Explosion(Content.Load<Texture2D>("Images/explosion3"), new Vector2(aHazard.Position.X, aHazard.Position.Y)));
break;
}
MoveHazard(aHazard);
}
spriteWidth = 71;//128;
spriteHeight = 100;//128;
sourceRect = new Rectangle(currentFrame * spriteWidth, 0, spriteWidth, spriteHeight);
//origin = new Vector2(sourceRect.Width / 2, sourceRect.Height / 2);
origin = new Vector2(-(sourceRect.Width / 4), 0);
if (mCurrentState == State.Crash)
{
//DrawTextDisplayArea();
//DrawTextCentered("Crash!", 200);
//DrawTextCentered("Press 'Space' to continue driving.", 260);
}