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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:17:17+00:00 2026-05-20T03:17:17+00:00

I was doing some things with a viewport yesterday in XNA, and couldn’t figure

  • 0

I was doing some things with a viewport yesterday in XNA, and couldn’t figure out why the sprite I’m using moves faster than my viewport when changing the positions. I had a feeling that it may have something to do with the different value types (int vs. float), but would someone care to elaborate on this?

Here’s the code I was using…

    Viewport myViewport;
    Texture2D t;
    SpriteFont f;
    Vector2 point = new Vector2(0, 0);  

    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();
        Keys[] pressedKeys = Keyboard.GetState().GetPressedKeys();
        for (int i = 0; i < pressedKeys.Length; i++)
        {
            if (pressedKeys[i] == Keys.W)
            {
                point.Y--;
            }
            else if (pressedKeys[i] == Keys.A)
            {
                point.X--;
            }
            else if (pressedKeys[i] == Keys.S)
            {
                point.Y++;
            }
            else if (pressedKeys[i] == Keys.D)
            {
                point.X++;
            }
        }
        myViewport.X = (int)point.X;
        myViewport.Y = (int)point.Y;
        GraphicsDevice.Viewport = myViewport;
        // TODO: Add your update logic here

        base.Update(gameTime);
    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.White);
        spriteBatch.Begin();
        spriteBatch.Draw(t, new Vector2(point.X, point.Y), Color.White);
        spriteBatch.End();
        // TODO: Add your drawing code here

        base.Draw(gameTime);
    }
  • 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-20T03:17:18+00:00Added an answer on May 20, 2026 at 3:17 am

    First of all, you should probably be setting the Viewport in your Draw function. Second of all you should ensure that your Viewport bounds always remain on screen!

    Anyway, the reason it moves like that is because SpriteBatch’s coordinate system is in client space in terms of the Viewport.

    In other words, the position (0,0), according to SpriteBatch, is the top left corner of the GraphicsDevice.Viewport.

    This is why your sprite moves at twice the speed you expect, because you’re effectively doing two different operations modifying its rendering position.

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

Sidebar

Related Questions

I am interested in doing some development with XNA. One of the things that
I'm doing some things with a facebook widget. They cache the css files, and
I'm doing things considered horrible by some lately, but I personally enjoy this kind
I'm doing some graphics programming using the Gosu gem. The thing is, when I
I'm new to Fortran and just doing some simple things for work. And as
I am learning c++, and I am having issues doing some newbie things. I
I'm doing some pretty unholy things with JavaScript, and I've run into a weird
I am doing some COM related things with directshow such as: typedef CComPtr<IBaseFilter> AutoIBaseFilterPtr;
I'll say up front that I am doing some really scary things with linq
I come from a C/C++ background and am having trouble doing some things in

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.