내 게임에서 기본적으로 내 게임의 모든 AI의 링크 된 목록 인 Ai 클래스가 있습니다. 이 같은 클래스는 모든 AI에 대한 기본 텍스처를 보유하고 있으며, 모든 AI의 개별 클래스는이 클래스에서 상속받습니다. 즉, AI 클래스에 의해 이미로드 된 기본 텍스처를 상속받을 수 있습니다. 그러나, 나는 이것에 문제가있는 것 같다. 내 게임은 도망 갔을 때 gui를로드하지 않으며 디버깅을 통해 지나가는 텍스처에 게임에 문제가있는 것처럼 보입니다. 단일 텍스처를로드하고 동일한 텍스처를 다른 오브젝트에 전달하여 사용할 수 있습니까?Xna - 동일한 텍스처를 공유하는 객체
AI 클래스 :
class AIs
{
private GraphicsDevice graphics;
private ContentManager content;
private SpriteBatch spriteBatch;
private LinkedList<object> ais;
private LinkNode<object> current;
//Default Textures
private Texture2D robotTexture
// Default Color Datas
private Color[] robotColorData;
public AIs()
{
}
public void Load(ContentManager content, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
this.spriteBatch = spriteBatch;
this.graphics = graphics;
this.content = content;
// Loading Default Textures
robotTexture = content.Load<Texture2D>("robot");
// Loading Default Color Data
robotColorData = new Color[robotTexture.Width * robotTexture.Height];
robotTexture.GetData(robotColorData);
}
public void Update()
{
current = ais.getHead();
while (current.getNext() != null)
{
if (current.getData() is Robot)
{
((Robot)current.getData()).Update();
}
}
}
public void Draw()
{
current = ais.getHead();
while (current.getNext() != null)
{
if (current.getData() is Robot)
{
((Robot)current.getData()).Draw();
}
}
}
public addRobot(float spawnX, float spawnY)
{
Robot temp = new Robot(spawnX, spawnY);
temp.Load(content, graphics, spriteBatch);
ais.add(temp);
}
public Texture2D getRobotTexture()
{
return robotTexture;
}
public Color[] getRobotColorData()
{
return robotColorData;
}
}
로봇 등급 :
class Robot : AIs
{
private GraphicsDevice graphics;
private ContentManager content;
private SpriteBatch spriteBatch;
private Texture2D robotTexture;
private Color[] robotColorData;
private Rectangle robotRectangle;
private Vector2 robotPosition = Vector2.Zero;
public Robot(float spawnX, float spawnY)
{
robotPosition = new Vector2(spawnX, spawnY);
}
new public void Load(ContentManager content, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
this.spriteBatch = spriteBatch;
this.graphics = graphics;
this.content = content;
robotTexture = getRobotTexture();
robotColorData = getRobotColorData();
}
new public void Update()
{
robotRectangle = new Rectangle((int)robotPosition.X, (int)robotPosition.Y, robotTexture.Width, robotTexture.Height);
}
new public void Draw()
{
spriteBatch.Draw(robotTexture, robotPosition, Color.White);
}
}
예, 동일한 텍스처를 여러 객체에 사용할 수 있습니다. 문제와 관련된 코드를 게시 할 수 있습니까? 사람들이 당신을 도울 수 있도록 더 많은 통찰력을 제공합니다. – jgallant
하지만 조금 걱정이되며 어떤 코드를 보여야할까요. – user2375782
나는 그것에 가깝게 만들 것입니다. 나는 그것을 만들었을 때 그것을 올려 놓을 것입니다. – user2375782