Я делаю игру в XNA. В настоящее время я работаю над обнаружением столкновений. Я не могу решить эти 2 ошибки из моего кода:XNA - Получение ошибки C#
// Non-static variables exist once for each instance of the class
Vector2 meteorPos;
// Static variables are shared between all instances of a class
public static Texture2D meteorTexture;
public Vector2 meteorPosPub { get { return meteorPos; } }
// Line that contains the errors
public static Rectangle boundingBox = new Rectangle((int)meteorPosPub.X, (int)meteorPosPub.Y, (int)meteorTexture.Width, (int)meteorTexture.Height);
public meteorGenerator(Vector2 pos)
{
this.meteorPos = pos;
}
Вот ошибки:
An object reference is required for the non-static field, method, or property 'SpaceInvaders.meteorGenerator.meteorPosPub.get'
An object reference is required for the non-static field, method, or property 'SpaceInvaders.meteorGenerator.meteorPosPub.get'
@Charlie Ahh вам Верно. Я обновил свой ответ, чтобы исправить эту проблему. – itsme86
Я тоже об этом подумал, но как мне получить доступ к 'boundingBox' из других классов? – PowerUser
@Charlie Точно так же вы можете получить доступ к meteorPosPub. Что-то вроде 'meteorGenerator meteor = новый метеоритный генератор (Vector2.Zero); meteor.boundingBox; 'Лучшая практика заключалась бы в том, чтобы создать свойство boundingBox вместо публичного поля, но по одному вызову за раз. – itsme86