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 4021720
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:23:12+00:00 2026-05-20T10:23:12+00:00

i just got into game development and XNA and was following a tutorial and

  • 0

i just got into game development and XNA and was following a tutorial and decided to try and add in a bound area for a floor. In the tutorial the sprite could move freely and i wanted to have a stopping point for it, so i added a statement to part of the input method

if (aCurrentKeyboardState.IsKeyDown(Keys.Down) == true)
            {
                if (this.Position.Y == 420)
                {
                    MOVE_DOWN = 0;
                    mDirection.Y = MOVE_DOWN;
                }

                else
                {
                    mSpeed.Y = PLAYER_SPEED;
                    MOVE_DOWN = 1;
                    mDirection.Y = MOVE_DOWN;
                }


            }

MOVE_DOWN is my variable for the y change, if it = 0, there is no movement, 1 it moves down, -1 it moves up.
this worked only if the position of the bounds(420) was equal to the position that my sprite started out at, other than that it doesnt work.

i think its because the position isnt updating correctly. i dont know ive tried a lot of things and am pretty new with XNA and game development. Any help would be greatly appreciated.

Here is the update method for my player sprite

 public void Update(GameTime theGameTime)

    {

        KeyboardState aCurrentKeyboardState = Keyboard.GetState();



        UpdateMovement(aCurrentKeyboardState);




        mPreviousKeyboardState = aCurrentKeyboardState;



        base.Update(theGameTime, mSpeed, mDirection);

    }

and here is the update for the base class

public void Update(GameTime theGameTime, Vector2 theSpeed, Vector2 theDirection)
    {
        Position += theDirection * theSpeed * (float)theGameTime.ElapsedGameTime.TotalSeconds;
    }
  • 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-20T10:23:13+00:00Added an answer on May 20, 2026 at 10:23 am

    If ‘Position’ is a Vector2, then it is using floats of the X & Y components.

    For practical purposes, a float will rarely equal a whole number due to floating point rounding errors.

    if (this.Position.Y == 420)//will never return true
    

    should be changed to:

    if (this.Position.Y < 420)
    {
       this.Position = 420;
       //other stuff you have
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just got into web development 2 months ago for a personal project. I
I just got into python very recently and now I'm practicing by (what I
I've recently been doing a lot of Objective-C programming, and just got back into
I am running into a problem that just doesn't seem right. I've got a
I just got into a debate with one of my coworkers about checking for
I just got into a new company and much of the code base uses
I've just got into using Omniauth for logging in with Twitter and Facebook and
I just got into somewhat complex databases (complex for me) and I have been
I just recently got into using vim, and am having great fun adding load
So i just recently got into canvas and decide to play around with it

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.