Jump to content
  • Advertisement
Sign in to follow this  
pokoto

SDL.NET Primitives / C# Properties

This topic is 3782 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am making a Pong clone to get familiar with Primitves and SDL.NET in general. My paddles are SdlDotNet.Graphics.Primitives.Box objects, and I am trying to get them to move using this code: paddle.Location.Y -= 2; This would be done whenever the up arrow is hit. It gives an error on compile, saying "Cannot modify the return value of 'SdlDotNet.Graphics.Primitives.Box.Location' because it is not a variable." So I tried this code to try to figure out what was going wrong (Location is a Point property, by the way): Point testPoint = new Point(0,0); testPoint.Y -= 2; It compiled fine. Why doesn't the first code work?

Share this post


Link to post
Share on other sites
Advertisement
Because Paddle.Location returns a Point, which is a value type (struct). When structs are returned, they are copied, so when you do Paddle.Location.Y you are accessing the "Y" property of the temporary copy of the struct, something which is virtually always an error so the compiler doesn't allow it.

Either do:
paddle.Location = new Point(paddle.Location.X, paddle.Location.Y - 2);

or look for (or add) an X, Y property on the paddle object that modify the field backing the Location property.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!