• Create Account

### #ActualBCullis

Posted 12 June 2012 - 09:37 AM

I'm still going to post to see if there is a better way to do this?

Yes, define a default (and possibly custom) constructor for your "objects" class, instead of using the default that's silently written for you (under the hood).
Something like this would suffice:

		public objects()
{
this.position = new Vector2(0,0);
}

public objects(Vector2 position, Texture2D spriteImage)
{
this.position = position;
this.spriteImage = spriteImage;
}

That provides you both the default (with no arguments) and a constructor that would let you define position and texture at the time of creation (a bit more flexible).

IMHO, it's a good practice to get into to define your constructor(s) for every class you write. Even if it's empty, having one in place gives you somewhere to add code when/if you need to.

### #2BCullis

Posted 12 June 2012 - 09:35 AM

I'm still going to post to see if there is a better way to do this?

Yes, define a custom constructor for your "objects" class, instead of using the default that's silently written for you (under the hood).

IMHO, it's a good practice to get into to define your constructors for every class you write. Something like this would suffice:

	    public objects()
{
this.position = new Vector2(0,0);
}

public objects(Vector2 position, Texture2D spriteImage)
{
this.position = position;
this.spriteImage = spriteImage;
}

That provides you both the default (with no arguments) and a constructor that would let you define position and texture at the time of creation (a bit more flexible).

### #1BCullis

Posted 12 June 2012 - 09:34 AM

I'm still going to post to see if there is a better way to do this?

Yes, define a custom constructor for your "objects" class, instead of using the default that's silently written for you (under the hood).

IMHO, it's a good practice to get into to define your constructors for every class you write. Something like this would suffice:

public objects()
{
this.position = new Vector2(0,0);