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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:21:49+00:00 2026-06-01T12:21:49+00:00

Creating a simple RPG game, first time using XNA. Trying to get my character

  • 0

Creating a simple RPG game, first time using XNA.

Trying to get my character to face different ways whenever i move in different directions.

The problem is that when i start up i cant even see my texture, the weird thing is that when i walk over a specific position in the game the whole spritesheet becomes visible, same thing for my AI NPC:s.. It’s like they’re laying there behind the background and the rectangle i’m moving is transparant (so i can see through the background with it).

FrameWidth and FrameHeight is sent in when i create an instance of the class. (height = 0 (starting from the top of the spritesheet), width = spritesheetwidth / 4 (to get that single sprite out).)

Velocity is the speed of which the character moves.

    public override void Update(GameTime gameTime)
    {
        ObjectRectangle = new Rectangle(CurrentFrame * FrameWidth, 0, FrameWidth, FrameHeight);
        Origin = new Vector2(ObjectRectangle.Width / 2, ObjectRectangle.Height / 2);
        Position += Velocity;

        ObjectRectangleX = (int)PositionX;
        ObjectRectangleY = (int)PositionY;

        #region movement
        if (Keyboard.GetState().IsKeyDown(Keys.D) && Pastkey.IsKeyUp(Keys.A) && Pastkey.IsKeyUp(Keys.W) && Pastkey.IsKeyUp(Keys.S))
        {
            AnimateRight(gameTime);
            VelocityX = 2;
        }
        else if (Keyboard.GetState().IsKeyDown(Keys.A) && Pastkey.IsKeyUp(Keys.D) && Pastkey.IsKeyUp(Keys.W) && Pastkey.IsKeyUp(Keys.S))
        {
            AnimateLeft(gameTime);
            VelocityX = -2;
        }
        else if (Keyboard.GetState().IsKeyDown(Keys.W) && Pastkey.IsKeyUp(Keys.A) && Pastkey.IsKeyUp(Keys.D) && Pastkey.IsKeyUp(Keys.S))
        {
            AnimateUp(gameTime);
            VelocityY = -2;
        }
        else if (Keyboard.GetState().IsKeyDown(Keys.S) && Pastkey.IsKeyUp(Keys.A) && Pastkey.IsKeyUp(Keys.W) && Pastkey.IsKeyUp(Keys.D))
        {
            AnimateDown(gameTime);
            VelocityY = 2;
        }
        else
        {
            Velocity = Vector2.Zero;
        }

        Pastkey = Keyboard.GetState();

        #endregion
    }

    #region Animations

    public void AnimateDown(GameTime gameTime)
    {
        CurrentFrame = 2;
    }
    public void AnimateRight(GameTime gameTime)
    {
        CurrentFrame = 3;
    }
    public void AnimateLeft(GameTime gameTime)
    {
        CurrentFrame = 1;
    }
    public void AnimateUp(GameTime gameTime)
    {
        CurrentFrame = 0;
    }

    #endregion

}

Draw method looks like:

    public virtual void Draw(SpriteBatch spriteBatch)
    {

        spriteBatch.Draw(ObjectTexture, Position, ObjectRectangle, Color.White, 0f, Origin, 1.0f, SpriteEffects.None, 0f);
        GameList.Add(this);
    }

(Ignore the List.Add)

So what i need help with is “locking” the texture to the rectangle.

  • 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-01T12:21:51+00:00Added an answer on June 1, 2026 at 12:21 pm

    These lines look unneccessary

    ObjectRectangleX = (int)PositionX;
    ObjectRectangleY = (int)PositionY;
    

    One thing you might look at is the final parameter in the .Draw call. You have it as 0f right now, that is the layer depth and if that value is lower than your terrain then the terrain will be drawn on top…I think, depends on your spritebatch.begin() arguments. You can read a bit more here where a few more bits are explained about layer depth.
    https://gamedev.stackexchange.com/questions/23619/2d-layerdepth-not-working-xna-4-0

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

Sidebar

Related Questions

I'm creating a simple game using HTML and CSS. I have a background image
Im creating a simple vehicle and projectile simulation game in WPF using C#. I
I am creating a simple application using the MVC design pattern where my model
I'm looking for help/advice with creating simple JSP website using equivalent of PHP include+switch
I have seen several methods for creating simple fixed width single column layout using
I am creating simple blog web application using play framework and i want to
I am creating simple chess board game in java, and they are running smoothly,
Creating a simple TCP server based on examples but still do not get how
Creating simple app using GAE / Django-nonrel (I don't think the problem is specific
I am creating a simple word doc, using the openXml SDK. It is working

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.