Moving Character in C# XNA Not working
- by Matthew Stenquist
I'm having trouble trying to get my character to move for a game I'm making in my sparetime for the Xbox. However, I can't seem to figure out what I'm doing wrong , and I'm not even sure if I'm doing it right. I've tried googling tutorials on this but I haven't found any helpful ones. Mainly, ones on 3d rotation on the XNA creators club website.
My question is : How can I get the character to walk towards the right in the MoveInput() function? What am I doing wrong? Did I code it wrong?
The problem is : The player isn't moving. I think the MoveInput() class isn't working.
Here's my code from my character class :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Jumping
{
class Character
{
Texture2D texture;
Vector2 position;
Vector2 velocity;
int velocityXspeed = 2;
bool jumping;
public Character(Texture2D newTexture, Vector2 newPosition)
{
texture = newTexture;
position = newPosition;
jumping = true;
}
public void Update(GameTime gameTime)
{
JumpInput();
MoveInput();
}
private void MoveInput()
{
//Move Character right
GamePadState gamePad1 = GamePad.GetState(PlayerIndex.One);
velocity.X = velocity.X + (velocityXspeed * gamePad1.ThumbSticks.Right.X);
}
private void JumpInput()
{
position += velocity;
if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed && jumping == false)
{
position.Y -= 1f;
velocity.Y = -5f;
jumping = true;
}
if (jumping == true)
{
float i = 1.6f;
velocity.Y += 0.15f * i;
}
if (position.Y + texture.Height >= 1000)
jumping = false;
if (jumping == false)
velocity.Y = 0f;
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, position, Color.White);
}
}
}