0

I'm using the tutorial Introduction to Programming Through Game Development Using Microsoft XNA Game Studio. I'm having trouble in the section about adding resources to a project.

I copied the instructions fairly well from what I can tell, except for changing the name of the picture - Still I get 3 errors being screen saying various names don't exist in the current context. How can I resolve these?

enter image description here

enter image description here

Kara
  • 6,115
  • 16
  • 50
  • 57
  • 2
    Firstly, do not post screen shots, always provide code with question in proper format. – MUT Oct 03 '16 at 04:47
  • 1
    Possible duplicate of [The name 'controlname' does not exist in the current context](http://stackoverflow.com/questions/706603/the-name-controlname-does-not-exist-in-the-current-context) – 4444 Oct 05 '16 at 21:30

1 Answers1

1

Both your texture and your rectangle are defined, initialized and disposed in your Init-Method. They are not accessible outside of that method. What you have to do is either pass them as method-parameters (not possible in in the Drawing-Method of XNA) or to make them "more public" and define them outside of your Init-Method:

private Texture2D starPic600Texture;
private Rectangle starPic600Rect;

protected override void LoadContent()
{
    spriteBatch = new SpriteBatch(GraphicsDevice);

    starPic600Rect = new Rectangle(30,20,600,600);
    starPic600Texture = this.Content.Load<Texture2D>("starPic600");
}

PS: Next time add your code-samples to your Question as code instead of Pictures. This would make it a Little bit easier to copy-paste and addapt your samples.

Marcel B
  • 508
  • 2
  • 9
  • 1
    You're a lifesaver, that had been driving me up the wall! thanks for the help, and ill definitely keep that in mind for the future. – AerialsintheSky Oct 03 '16 at 05:13