Why can't I compare two Texture2D's?
Posted
by
Fiona
on Game Development
See other posts from Game Development
or by Fiona
Published on 2012-12-16T22:40:39Z
Indexed on
2012/12/16
23:22 UTC
Read the original article
Hit count: 276
c#
I am trying to use an accessor, as it seems to me that that is the only way to accomplish what I want to do. Here is my code:
Game1.cs
public class GroundTexture
{
private Texture2D dirt;
public Texture2D Dirt
{
get
{
return dirt;
}
set
{
dirt = value;
}
}
}
public class Main : Game
{
public static Texture2D texture = tile.Texture;
GroundTexture groundTexture = new GroundTexture();
public static Texture2D dirt;
protected override void LoadContent()
{
Tile tile = (Tile)currentLevel.GetTile(20, 20);
dirt = Content.Load<Texture2D>("Dirt");
groundTexture.Dirt = dirt;
Texture2D texture = tile.Texture;
}
protected override void Update(GameTime gameTime)
{
if (texture == groundTexture.Dirt)
{
player.TileCollision(groundBounds);
}
base.Update(gameTime);
}
}
I removed irrelevant information from the LoadContent and Update functions.
On the following line:
if (texture == groundTexture.Dirt)
I am getting the error
Operator '==' cannot be applied to operands of type 'Microsoft.Xna.Framework.Graphics.Texture2D' and 'Game1.GroundTexture'
Am I using the accessor correctly? And why do I get this error? "Dirt" is Texture2D, so they should be comparable.
This using a few functions from a program called Realm Factory, which is a tile editor. The numbers "20, 20" are just a sample of the level I made below:
tile.Texture returns the sprite, which here is the content item Dirt.png
Thank you very much!
(I posted this on the main Stackoverflow site, but after several days didn't get a response. Since it has to do mainly with Texture2D, I figured I'd ask here.)
© Game Development or respective owner