您好我有这些向量:列表需要一些基础知识
Vector2 ground1p1 = new Vector2(0,430);
Vector2 ground1p2 = new Vector2(200,430);
Vector2 ground1p3 = new Vector2(0, 290);
Vector2 ground1p4 = new Vector2(280, 340);
我想将它们放在一个列表,这样,而不是这样:
if (DetectPlayerAndGround1Collision2(playerPosition,ground1p1,player,ground1) == true)
{
hasJumped = false;
velocity.Y = 0f;
}
if (DetectPlayerAndGround1Collision2(playerPosition, ground1p2, player, ground1) == true)
{
hasJumped = false;
velocity.Y = 0f;
}
这里当我在写作结束时写入“矢量”时,问题没有发生,就像我没有声明的那样:
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
bool hasJumped = true;
Vector2 velocity;
Texture2D player;
Texture2D ground1;
List<Vector2> vectors = new List<Vector2>();
Vector2 playerPosition = new Vector2(30, 300);
Vector2 ground1p1 = new Vector2(0,430);
Vector2 ground1p2 = new Vector2(200,430);
Vector2 ground1p3 = new Vector2(0, 290);
Vector2 ground1p4 = new Vector2(280, 340);
我不认为加入另一个循环将有助于XNA的性能。诚实合适的数据结构可以更好地处理这个问题。 – ChaosPandion
我知道它不会帮助大声笑:D我希望它对我来说很容易进一步写作我不想要复制粘贴100次 –