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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:28:58+00:00 2026-06-18T08:28:58+00:00

Coding in c# and using the XNA 4.0 framework I am trying to develop

  • 0

Coding in c# and using the XNA 4.0 framework I am trying to develop for both keyboard and game controller input when it comes to player control.

My code for the game controller input is as follows;

GamePadState gamepadState = GamePad.GetState(PlayerIndex.One); 

if(gamepadState.ThumbSticks.Left.X != 0 || gamepadState.ThumbSticks.Left.Y != 0) 
{   
     //Handles rotation
     angle += thumbsticksMove(gamepadState); //handles Left.X and Left.Y input
     normalize(); //normalizes angle and sets normalizedAngle = angle
     this.Rotate(normalizedAngle); //takes value and passes it through Math helper
     //atan and pi*2
     //Ends handles rotation

     pos += (angle * speed);

     //Implementing framerate adjustment just for this class
     timeSinceLastFrame += (float)gameTime.ElapsedGameTime.Milliseconds;
     if (timeSinceLastFrame > millisecondsPerFrame)
     {
          timeSinceLastFrame -= millisecondsPerFrame;
          Animation();
     }
}

This moves the player as expected and the sprite flips to the proper direction, but the animation piece does not work. The sprite is supposed to animate with player movement upon input. This works great when taking in input from the keyboard, see below;

if (Keyboard.GetState().IsKeyDown(Keys.Right))
{
       input = Vector2.Zero;
       input.X = 1;

       //Handles rotation
       angle.X = input.X;
       normalize();
       this.Rotate(normalizedAngle);
       //Ends handles rotation

       pos += (input * speed);
       //Implementing framerate adjustment just for this class
       timeSinceLastFrame += (float)gameTime.ElapsedGameTime.Milliseconds;
       if (timeSinceLastFrame > millisecondsPerFrame)
       {
       timeSinceLastFrame -= millisecondsPerFrame;
       Animation();
       }
}

I’m having a hard time figuring out why it works for the keyboard input but not the game controller input. It almost looks as if it’s trying to animate but never quite makes it past the 3rd animation cell or animates so fast to the point of looking as if it’s barely animating. Any help would be hugely appreciated!

  • 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-18T08:29:00+00:00Added an answer on June 18, 2026 at 8:29 am

    I ended up adding

    if (gamepadState.IsConnected){//Gamepad code}
    
    if (!gamepadState.IsConnected){//Keyboard code}
    

    Reading the inputs separately seems to have fixed the issue.

    Thanks for everyone’s help though.

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

Sidebar

Related Questions

I'm coding in c# using the XNA 4.0 framework. I have noticed that when
I'm a novice programmer and I'm trying to learn Android coding using Eclipse. This
I'm coding in VS2008 using C#. On my form, I have a ListView control.
I'm trying to create a GUI using Java by hand-coding it (without using GUI
I have decided to start coding using OOP and a PHP framework. I have
recently I have been trying my hand at coding a game in C#. I'm
I´m starting (trying at least) to do coding using TDD principles and I have
I followed the article to code a hanffman coding method using stl's priority_queue, however
I'm using XNA and creating a bunch of forms that roll their own 'game
I'm trying to understand shaders using libgdx, coming from an XNA/HLSL background. I'm trying

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.