Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3597294
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:05:58+00:00 2026-05-18T20:05:58+00:00

The tutorial I’m following ( http://www.bluerosegames.com/xna101/post/Lesson-9-Improving-the-BouncingBall-Class-Using-Properties.aspx ) private Vector2 _position; public Vector2 Position {

  • 0

The tutorial I’m following (http://www.bluerosegames.com/xna101/post/Lesson-9-Improving-the-BouncingBall-Class-Using-Properties.aspx)

private Vector2 _position;
public Vector2 Position
{
    get

    {
        return _position;
    }
    set
    {
        _position = value;
    }
}

does not use the automatic properties feature in the code. I’d like to skip most of the typing using the automatic properties but I have problems later on in the code. I’ve commented the lines below that are affected.

public Vector2 Position { get; set; }

    public void Update()
    {
        Position = Position + Velocity;

        if (Position.X < 0 || Position.X > GraphicsViewport.Width - Texture.Width)
        {
            // If we get in here, we've hit a vertical wall
            Velocity.X = -Velocity.X; // doesn't work
            Position.X = Position.X + Velocity.X; // doesn't work
        }
        if (Position.Y < 0 || Position.Y > GraphicsViewport.Height - Texture.Height)
        {
            // If we get in here, we've hit a horizontal wall
            Velocity.Y = -Velocity.Y; // doesn't work
            Position.Y = Position.Y + Velocity.Y; // doesn't work
        } 
    }

The error that I get in Visual Studio states that “Cannot modify the return value of WindowsGame1.BouncingBall.Position’ because it is not a variable.” So how can I get the code to work with the automatic properties?

Thank you!
John

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:05:59+00:00Added an answer on May 18, 2026 at 8:05 pm

    Your exact question has already been asked and answered:

    This code isn’t trying to do what you
    think it’s trying to do…

    Vector2 is a struct, so your call in
    Update first copies Position onto
    the stack, adds velocity.X to the new
    Vector2’s ‘X’ and then throws it away.
    The original value was never modified.

    The C# compiler catches your mistake
    in this case (phew!). You instead need
    to do:

    Position = new
    Vector2(Position.X+velocity.X,
    Position.Y);

    The difference between value and
    reference types is fundamental in C# –
    the C# specification describes that
    difference immediately after “hello,
    world”

    See section 8.2 of the C#
    specification for more information:

    http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf

    Alun Harford

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The tutorial I'm following ( http://www.bluerosegames.com/xna101/post/Lesson-9-Improving-the-BouncingBall-Class-Using-Properties.aspx ) private Vector2 _position; public Vector2 Position {
I'm following this tutorial: http://www.javascripttoolbox.com/jquery/ And I'm trying to get table rows that are
ajax tutorial on w3school at http://www.w3schools.com/ajax/ajax_database.asp In this function (function GetXmlHttpObject()), it creates a
I have followed a tutorial on http://www.codeproject.com/KB/IP/beginningtcp_cpp.aspxt which teaches how to use winsockets with
Following StockWatcher tutorial, http://code.google.com/webtoolkit/doc/latest/tutorial/debug.html When I run the app in debug mode, my Safari
I'm using this tutorial to get internal messages working on my site: http://www.novawave.net/public/rails_messaging_tutorial.html But,
I am following a tutorial to create a class: using System; using System.Collections.Generic; using
I am following the tutorial i found in this page http://javahunter.wordpress.com/2010/09/25/integrating-captcha-in-jsf-2-0/ to integrate a
I followed the tutorial exactly: http://github.com/binarylogic/authlogic_example But I am wondering how can I get
Is there a good tutorial on using regular expressions, especially with grep ? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.