Joe
Joe

Reputation: 33

Get / Set problems

Asteroids class

public Vector2 AsteroidPosition
{
    get { return asteroidPosition; }
    set { asteroidPosition = value; }
}

Set is called from Update method in Asteroids class

AsteroidPosition = new Vector2(spritePosition.X, spritePosition.Y);

Game class, collision detection method

Asteroids asteroid = new Asteroids();
Rectangle asteroidRectangle = new Rectangle(
    (int)asteroid.AsteroidPosition.X,
    (int)asteroid.AsteroidPosition.Y, 
    asteroidTexture.Width, 
    asteroidTexture.Height);

And this method is called in the Update method of Game class.

I add a break breakpoint at Set to check 'value' has a value and it does, so why does it keep return (0, 0)?

Upvotes: 0

Views: 217

Answers (2)

pyCoder
pyCoder

Reputation: 501

Ther's not Property set after Asteroids asteroid = new Asteroids(); . So it's get default value.

Upvotes: 0

Jackson Pope
Jackson Pope

Reputation: 14640

The asteroid instance is created on the first line of the collision detection method, and then used immediately on the second, so the values will be 0 unless you set them to something inside the constructor of the struct.

Upvotes: 2

Related Questions