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

  • Home
  • SEARCH
  • 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 9178021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:27:20+00:00 2026-06-17T17:27:20+00:00

this is my first question and I just started coding in C# some days

  • 0

this is my first question and I just started coding in C# some days ago, so please be kind, if I’m doing something stupid. The thing is, I wanna write a small 2D-game in xna and therefore I created a 32×32 px box with texture and that should be the player. I can use the arrow-keys to move the player by writing a class for the player like

namespace MyGame
{
    class Player
    {
        public Texture2D Textur;
        public Vector2 Position { get; set; }
    }
}

and then using

KeyboardState keyboard = Keyboard.GetState();
if (keyboard.IsKeyDown(Keys.Right)) player.Position += new Vector(5,0);
//and so on

where 5 is the amount of pixels, the player moves with one keystroke.
What I’m trying is to write something like this

class Player
{
    public Texture2D Textur;
    public Vector2 Position { get; set; }
    public Vector2 UpperRightCorner = new Vector2(Position.X + 32, Position.Y);
}

But obviously it doesn’t work. Even thought I read the documentation on msdn about get; set; I do not really understand, how it works.
I need the corners, or more precisely the pixel next to the corner, to write a collision method. This method should ask everytime, when I press an arrow-key, what kind of level-block is in front of the player and then adapt the speed resp. set the movement to 0, if there is a solid block (like a wall).

Any idea, how i can write this corner-stuff IN the player class? I can call it in the main class, after instancing the player, but I would prefer to put it into the player class.

  • 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-06-17T17:27:21+00:00Added an answer on June 17, 2026 at 5:27 pm

    You’re assigning a value to UpperRightCorner when it is instantiated. This value will remain unchanged. This could be rewritten with a getter to recalculate UpperRightCorner every time it is accessed. Example:

    public Vector2 UpperRightCorner
    {
        get
        {
            return new Vector2(Position.X + 32, Position.Y);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a bit silly question, but I just started doing pretty things
I just started working on backbone a week ago, please don't mind if this
This is my first question on stackoverflow. I just wonder why my getJSON code
This is my first here in Stackoverflow. So I just want to ask question
This is just a simple question. Either way works. I prefer my first example,
This is my first question, so please be gentle. I'm trying out Apache Camel
this is my first question on stack overflow. Some quick background, this is not
First of all, this is my code (just started learning java): Queue<String> qe =
I just started learning android.Hope this isn't silly question.Here it is My FragmentAdapter has
Just started a tutorial in SQL for beginners. I'm doing some exercises now and

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.