I'm converting over an old project I did in GSE Beta 1 where a class (specifically, my 'background image' class) had its own Texture2D.
Here's exactly how I went about loading the texture in my old Beta1 version:
Vector2 location, offscreen;
Texture2D bg;
public Background(GraphicsDevice Device)
{
location = new Vector2(0,0);
offscreen = new Vector2(0,480);
bg = Texture2D.FromFile(Device,"resources\\background.png");
}
Now obviously this doesn't work any longer. As such, I've been trying to convert this over to 1.0 compliant code. I can get my code to compile without any problems, but I can't get the silly thing to run.
The error I keep getting is as follows:
Error loading "background". GraphicsDevice component not found.
So, I've been dinking around trying to send the constructor my graphics device and whatnot, but I'm not exactly sure what I've got to do to get this working correctly.
Here's the current state of the code:
Vector2 location, offscreen;
Texture2D bg;
public Background(GraphicsDeviceManager Device, ContentManager content)
{
location = new Vector2(0,0);
offscreen = new Vector2(0,480);
bg = content.Load<Texture2D>("background");
}
There's probably some really easy fix for this, so thanks ahead to whoever gives me a quick bit of help.

Probably an easy one: I'd like a class to have its own textures.
osamaT
Here's the entire class. It's pretty small, so it'll be easy to see how everything works:
class Background
{
Vector2 location, offscreen;
Texture2D bg;
public Background(GraphicsDeviceManager Device, ContentManager content)
{
location = new Vector2(0,0);
offscreen = new Vector2(0,480);
bg = content.Load<Texture2D>("background");//bg = Texture2D.FromFile(Device,"resources\\background.png");
}
public void Scroll()
{
//blue border is visible here, and if I change it to (-1,-1), you can see the blue
//border on the bottom and right of the screen as well, as it's not drawing itself
//to the ends.
//location.Y= location.Y % 480;
}
public void Draw(SpriteBatch Batch)
{
//Draw the background at its current location
//another copy of it above so that it fills in the gap.
{
Batch.Draw(bg, location - offscreen, Color.White);
}
}
}
digioz
Novice in C&#35;
Kamii47
What are the dimensions of the Texture2D you get from loading the background image You can check this in the debugger. Maybe your background image height and width is off by one
--Stephen
chilakaluri
Since the code is compiling and the program is working again, it does bring up another quick question that I'd rather not open another topic for.
Why is it that even though I've got my background drawing to (0,0), I can still see a 1 pixel border on the top and left of my screen
My Game1 Draw function clears the GraphicsDevice like so: graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
And when running my program, the blue border can clearly be seen even though I've got my background drawing to the absolute top left (0,0).
Here's some images showing what I mean:
http://img407.imageshack.us/img407/7572/testnm2.jpg
http://img99.imageshack.us/img99/8051/testfa1.jpg
Now, it looks like the actual green background image is only partially opaque at the edge, as you can see where the darker parts of it continue onto the cornflower blue border. Any ideas how to resolve this
Thanks again.
AndyJ_PS
Rei Miyasaka
Steve Thornton
Srilatha
I create the background instance in my Game1 constructor. Here's the code where it's being created:
GraphicsDeviceManager graphics;
ContentManager content;
Background background;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
content = new ContentManager(Services);
background = new Background(graphics,content);
}
From there my code is pretty much identical to the XNA scrolling background example.
coco250
//this draws the background
backBatch.Begin();
backBatch.End();
And the Draw() method in my Background class looks like this:
public void Draw(SpriteBatch Batch)
{
Batch.Draw(bg, location, Color.White);
if (location.Y > 0)
{
Batch.Draw(bg, location - offscreen, Color.White);
}
}
me&#42;