When I add a new file by "Project->Add Class->Visual C# items->Add class It opens a new file with the name I supply. Then I add the code below.
`using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Input;
namespace MultiFile
{
///
/// A general class to build a Game Hero
///
public class Hero
{
#region Fields
Texture2D sprite;
Rectangle DrawRectangle;
#endregion
#region Constructors
/// <summary>
///
/// </summary>
/// <param name="contentManager"></param>
/// <param name="spriteName"></param>
/// <param name="x"></param>
/// <param name="y"></param>
public Hero(ContentManager contentManager, string spriteName, int x, int y)
{
LoadContent(contentManager, spriteName, x, y);
}
#endregion
}
}`
When I call it from the main game class like this
` protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
hero = new Hero(Content, (@"idle"), graphics.PreferredBackBufferWidth / 2,
graphics.PreferredBackBufferHeight / 2);
It does NOT show any errors BUT when I call
` protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
hero.Draw(spriteBatch);
spriteBatch.End();
// TODO: Add your drawing code here
base.Draw(gameTime);
}`
an error is thrown saying
Error CS1061
âHeroâ does not contain a definition for âDrawâ and no extension method âDrawâ accepting a first argument of type âHeroâ could be found (are you missing a using directive or an assembly reference?)
MultiFile D:\C#\MY APPS\MultiFile\MultiFile\Game1.cs
92 Active
I am very new to C# and Visual studio.
Also I have noticed that in some classes the word âpublicâ is colored blue but in mine it is grey.