I'm having some issues in XNA. I have a Player class and I would like to call a foreach function from a list which has been declared in the Game1 main class, which is below:
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
// Player
Player player;
// Landscape
public List<Tile> tiles = new List<Tile>();
The following is the code I'm using and within it is the foreach:
if (isJumping == true)
{
foreach (Tile tile in tiles)
{
if (recTopBot.Intersects(tile.rectangle))
{
position.Y += velocity.Y * curTime;
velocity.Y += gravity * curTime;
}
else
{
position.Y = 320 - texture.Height;
velocity.Y = 0;
isJumping = false;
}
}
}
It says that the name "tiles" does not exist in the current context. Now, I understand why it doesn't work, but what's the best way to fix it without modifying the classes and ruining my algorithms?
That chunk is used for detecting bottom collision for the tiles that are added in my world to make jumping + gravity work as intended.
Thank you very much!
I understand why it doesn't work
, why don't you tell us your understanding, maybe then we'll see your question. \$\endgroup\$