0
试图在这里制作2D侧滚动器XNA 3.1 - 不确定如何在敌人类中添加矩形
我对编程颇为陌生。我试图按照指南和教程没有太多的运气。我知道这很简单,但我无法弄清楚。
我对游戏中的所有不同角色都有多个类。
我对玩家将控制的主精灵角色有一个矩形。
但问题是我想在敌方精灵周围添加矩形,这样我就可以将碰撞添加到游戏中。
public class enemyRocks
{
public Texture2D texture;
public Vector2 position;
public Vector2 velocity;
public Rectangle rockRectangle;
public bool isVisible = true;
Random random = new Random();
int randX;
public enemyRocks(Texture2D newTexture, Vector2 newPosition)
{
texture = newTexture;
position = newPosition;
randX = -5;
velocity = new Vector2(randX, 0);
}
public void Update(GraphicsDevice graphics)
{
position += velocity;
if (position.X < 0 - texture.Width)
isVisible = false;
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, position, Color.White);
}
}
我真的尝试了很多方法,但它似乎并没有工作。
我迄今为止所做的一切都给了我一个“nullreferenceexception was unhandled”错误。
我会采取任何需要改进的批评。
谢谢你的帮助。
你从哪里得到NullReferenceException? – pinckerman