Not only am I a rusty programmer, I’m using VB and I’m completely new to Mono. Advise me against VB as much as you like, I can assure you C# ain’t going to happen to this old timer.
Anyway, I’m trying to create a class for a very simple moving sprite, but I’m a bit confused about how to do it. I’m fine with single items of texture2d, or arrays of texture2d, but how do you create a class object of a texture2d?
The textures themself you have to add to the Monogame Content Project in the Content folder of your project, make sure you build that as well.
For a moveable sprite i would recommend storing the texture itself in a central space or declaring it static so you can avoid loading it multiple times. In the class you would have a position (Vector2) and update/draw methods. In draw you would call .Draw() on the spritebatch with the previously loaded Texture2D and the position, in Update you would move the sprite by changing the position.
Yeah, as I say, I’m fine getting everything working within the Game class.
I’m trying to create a new Class of sprite object, but if I create a class that inherits texture2d I can’t assign ‘Load’ the texture in the main routine or in the class as there’s no load routine.
It must be pretty easy to create a class for a sprite? Or with Mono, does everything have to happen within the one main class Game1?
Don’t inherit texture2d? Just create a texture2d variable. Anways contact me on skype: Acrew1979. I’ll send you a book that was a GREAT learning example for me. Only problems I had from that point was collision that wasnt weird but I just use farseer physics now.
private Texture2D texture;//this <<<
public Sprite(Texture2D texture)//parameter name same as declared field
{
//this. use to tell texture from class not parameter
this.texture = texture;
}