나는 C# 및 XNA 4.0뿐만 아니라 Farseer Physics Engine (Box2D와 매우 유사)을 사용하고 있으며 OBlock, LBlock, 등은 다음기본 클래스 목록에서 파생 클래스 필드에 액세스
블록대로 :
이class Block
{
public Body m_body;
public virtual void Draw(SpriteBatch spriteBatch) { }
public virtual void RemoveBody(World world)
{
//world.RemoveBody(m_body);
}
}
내가
그래서 내 오버라이드 (override) 버전은 뭔가를 그래서 나는이 목록에 자신의 오버라이드 (override) 버전에 액세스 할 수있는 등 그 메소드, 필드, 봐 넣어 만했습니다 이렇게 : OBlock.cs
class OBlock : Block
{
private static Texture2D blockImg; //I load this in LoadContent so I don't have loads of Texture2Ds
public new Body m_body; //Is this right?
public OBlock(World world, Vector2 position)
{
m_body = BodyFactory.CreateBody(world, position); // Create the body, changing it from null
FixtureFactory.AttachRectangle(Game1.blockSide *2, Game1.blockSide *2, 1.0f, new Vector2(0, 0), m_body); //This bit changes between classes
m_body.BodyType = BodyType.Dynamic;
}
public override void RemoveBody(World world)
{
world.RemoveBody(m_body);
}
public static void LoadImage(Texture2D tex)
{
OBlock.blockImg = tex;
}
public override void Draw(SpriteBatch spriteBatch)
{
Vector2 position = m_body.Position * Game1.MetreInPixels;
Vector2 origin = new Vector2(blockImg.Width/2, blockImg.Height/2);
float rotation = m_body.Rotation;
spriteBatch.Begin();
spriteBatch.Draw(blockImg, position, null, Color.White, rotation, origin, Game1.BLOCK_SCALE, SpriteEffects.None, 1);
spriteBatch.End();
base.Draw(spriteBatch);
}
}
또한 LBlock, ZBlock 등이 모두 제가 주석 처리 한 비트와 매우 유사하게 보입니다.
내가 다음
List<Block> blocks //As a field in Game1
blocks = new List<Block>(); // In LoadContent after loading images
에 그들 모두를 난 할 노력하고있어 분명히 m_body 항상 null 관계없이
blocks[index].m_body.DOSTUFF();
를 사용하여 유형의 목록에있는 블록에 대한 액세스 m_body입니다. ..
줄에서 한 줄씩 코드를 단계별로 실행하면 개체에서 m_body를 보면서 어떻게됩니까? – SecurityMatt