Anyone familiar with C#?
Posted: Sun Feb 07, 2010 8:07 pm
So I've been working on and off on a game for fun during downtime and I've encountered an error, probably a noob one but I keep getting an error when I compile the program.
Error 1 Inconsistent accessibility: parameter type 'New2DRPG.Tileset' is less accessible than method 'New2DRPG.Core_Components.TileEngine.TileEngine(Microsoft.Xna.Framework.Game, New2DRPG.Tileset, int, int)' Components\TileEngine.cs 53 16 New2DRPG
Here's the code for this class, the part between the ******************** is the part that's giving me the error above. I figure it's something to do with the class being public but
Error 1 Inconsistent accessibility: parameter type 'New2DRPG.Tileset' is less accessible than method 'New2DRPG.Core_Components.TileEngine.TileEngine(Microsoft.Xna.Framework.Game, New2DRPG.Tileset, int, int)' Components\TileEngine.cs 53 16 New2DRPG
Here's the code for this class, the part between the ******************** is the part that's giving me the error above. I figure it's something to do with the class being public but
namespace New2DRPG.Core_Components
{
/// <summary>
/// This is a game component that implements IUpdateable.
/// </summary>
public class TileEngine : Microsoft.Xna.Framework.DrawableGameComponent
{
SpriteBatch spriteBatch;
ContentManager Content;
static List<Rectangle> tiles = new List<Rectangle>();
KeyboardState oldState;
KeyboardState newState;
TileMap map;
List<GameComponent> childComponents = new List<GameComponent>();
static int tileWidth = 64;
static int tileHeight = 48;
static int tileMapWidth;
static int tileMapHeight;
static int screenWidth;
static int screenHeight;
static int mapWidthInPixels;
static int mapHeightInPixels;
static float cameraX;
static float cameraY;
Random random = new Random();
Camera camera = new Camera();
static Tileset tileset;
// ***********************************************************
public TileEngine(Game game, Tileset tileset, int tileMapWidth,
int tileMapHeight)
: base(game)
//**************************************************************
{
// TODO: Construct any child components here
spriteBatch =
(SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));
TileEngine.tileset = tileset;
TileEngine.tileMapWidth = tileMapWidth;
TileEngine.tileMapHeight = tileMapHeight;
TileEngine.tiles = tileset.Tiles;
map = new TileMap(tileMapWidth, tileMapHeight, game);
childComponents.Add(map);
Content =
(ContentManager)Game.Services.GetService(typeof(ContentManager));
Texture2D chest = Content.Load<Texture2D>(@"Items\chest");
ItemSprite tempItemSprite;
Vector2 position;
Random random = new Random();
for (int i = 0; i < 10; i++)
{
position = new Vector2(
random.Next(0, 10),
random.Next(0, 10));
tempItemSprite = new ItemSprite(game,
chest, position);
childComponents.Add(tempItemSprite);
}
screenWidth = game.Window.ClientBounds.Width;
screenHeight = game.Window.ClientBounds.Height;
}
public static int TileMapWidth
{
get { return tileMapWidth; }
}
public static int TileMapHeight
{
get { return tileMapHeight; }
}
public static int TileWidth
{
get { return tileWidth; }
}
public static int TileHeight
{
get { return tileHeight; }
}
public static int ScreenWidth
{
get { return screenWidth; }
}
public static int ScreenHeight
{
get { return screenHeight; }
}
public static int MapWidthInPixels
{
get { return mapWidthInPixels; }
}
public static int MapHeightInPixels
{
get { return mapHeightInPixels; }
}
public static int CameraXPosition
{
get { return (int)cameraX; }
}
public static int CameraYPosition
{
get { return (int)cameraY; }
}
public static Texture2D TileSet
{
get { return Tileset.TilesetTexture; }
}
public static List<Rectangle> Tiles
{
get { return tiles; }
}
/// <summary>
/// Allows the game component to perform any initialization it needs to before starting
/// to run. This is where it can query for any required services and load content.
/// </summary>
public override void Initialize()
{
// TODO: Add your initialization code here
base.Initialize();
}
/// <summary>
/// Allows the game component to update itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(GameTime gameTime)
{
// TODO: Add your update code here
base.Update(gameTime);
mapWidthInPixels = tileMapWidth * tileWidth;
mapHeightInPixels = tileMapHeight * tileHeight;
newState = Keyboard.GetState();
Vector2 motion = new Vector2();
if (newState.IsKeyDown(Keys.Up) || newState.IsKeyDown(Keys.NumPad8))
{
motion.Y--;
}
if (newState.IsKeyDown(Keys.Right) || newState.IsKeyDown(Keys.NumPad6))
{
motion.X++;
}
if (newState.IsKeyDown(Keys.Down) || newState.IsKeyDown(Keys.NumPad2))
{
motion.Y++;
}
if (newState.IsKeyDown(Keys.Left) || newState.IsKeyDown(Keys.NumPad4))
{
motion.X--;
}
if (newState.IsKeyDown(Keys.NumPad9))
{
motion.X++;
motion.Y--;
}
if (newState.IsKeyDown(Keys.NumPad3))
{
motion.X++;
motion.Y++;
}
if (newState.IsKeyDown(Keys.NumPad1))
{
motion.X--;
motion.Y++;
}
if (newState.IsKeyDown(Keys.NumPad7))
{
motion.X--;
motion.Y--;
}
if (motion != Vector2.Zero)
{
motion.Normalize();
}
camera.Position += motion * camera.Speed;
camera.LockCamera();
TileEngine.cameraX = camera.Position.X;
TileEngine.cameraY = camera.Position.Y;
oldState = newState;
}
public override void Draw(GameTime gameTime)
{
foreach (GameComponent child in childComponents)
{
if ((child is DrawableGameComponent) &&
((DrawableGameComponent)child).Visible)
{
((DrawableGameComponent)child).Draw(gameTime);
}
}
base.Draw(gameTime);
}
public virtual void Show()
{
Enabled = true;
Visible = true;
foreach (GameComponent child in childComponents)
{
child.Enabled = true;
if ((child is DrawableGameComponent))
((DrawableGameComponent)child).Visible = true;
}
}
public virtual void Hide()
{
Enabled = false;
Visible = false;
foreach (GameComponent child in childComponents)
{
child.Enabled = false;
if ((child is DrawableGameComponent))
((DrawableGameComponent)child).Visible = false;
}
}
public virtual void Pause()
{
Enabled = !Enabled;
foreach (GameComponent child in childComponents)
{
child.Enabled = !child.Enabled;
}
}
}
}