0
\$\begingroup\$

So I made a new project, Loaded up the player sprite(16x16)

but the player is too small(as compared to the level) How should I fix this? Here the code which loads the sprites and the levels(I am using monogame extended)

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGame.Extended;
using MonoGame.Extended.Tiled;
using MonoGame.Extended.Tiled.Renderers;
using MonoGame.Extended.ViewportAdapters;

namespace Dungeon
{
    public class Game1 : Game
    {
        private GraphicsDeviceManager _graphics;
        private SpriteBatch _spriteBatch;
        private TiledMap map;
        private TiledMapRenderer mapRenderer;
        private OrthographicCamera cam;
        private Texture2D player;
        private Vector2 playerPos;
        private InputManager manager;
        public Game1()
        {
            _graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            IsMouseVisible = true;
        }

        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            manager = new InputManager();
            playerPos = new Vector2(0,0);
            mapRenderer = new TiledMapRenderer(GraphicsDevice);
            var viewportAdapter = new BoxingViewportAdapter(Window,GraphicsDevice,800,400);
            cam = new OrthographicCamera(viewportAdapter);
            base.Initialize();
        }

        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);
            map = Content.Load<TiledMap>("Dungeon");
            mapRenderer.LoadMap(map);
            player = Content.Load<Texture2D>("player");
            // TODO: use this.Content to load your game content here
        }

        protected override void Update(GameTime gameTime)
        {
            
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();
            mapRenderer.Update(gameTime);
            // TODO: Add your update logic here
           
            float move = 2;
           
                playerPos =manager.moveVertical(playerPos,move);
            playerPos = manager.moveHorizontal(playerPos,move);
           
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            mapRenderer.Draw();
            var transformMatrix = cam.GetViewMatrix();

            _spriteBatch.Begin(transformMatrix:transformMatrix);
            _spriteBatch.Draw(player,playerPos,Color.White);
            _spriteBatch.End();
            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
    }
}

and the InputManager(You won't need it probably but just in case)

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using System;

public class InputManager
{
    Vector2 position;
    public InputManager()
    {
        position = new Vector2(0,0);
    }

    public Vector2 moveVertical(Vector2 pos,float move)
    {
        var keyboardState = Keyboard.GetState();
        if(keyboardState.IsKeyDown(Keys.D))
        {
            position.X += move;
        }
        if (keyboardState.IsKeyDown(Keys.A))
        {
            position.X -= move;
        }
        return position;
    }
    public Vector2 moveHorizontal(Vector2 pos, float move)
    {
        var keyboardState = Keyboard.GetState();
        if (keyboardState.IsKeyDown(Keys.S))
        {
            position.Y += move;
        }
        if (keyboardState.IsKeyDown(Keys.W))
        {
            position.Y -= move;
        }
        return position;
    }
}

The level

player sprite Enter the gungeon

\$\endgroup\$
2
  • \$\begingroup\$ Please do not delete and re-post the same question. Instead, you should focus on editing your question so that it can be re-opened. Deleting and re-posting can look to our automated systems like an attempt to circumvent moderation, which an cause those systems to apply restrictions to your account. \$\endgroup\$
    – DMGregory
    Sep 2, 2020 at 11:09
  • \$\begingroup\$ If an answer solves your question, mark it as accepted instead of editing your question title. \$\endgroup\$
    – user35344
    Sep 3, 2020 at 8:37

1 Answer 1

1
\$\begingroup\$

Either use a larger sprite, or use a different Spritebatch.draw() overload that allows you to change the sprite's scale.

for example:

Vector2 origin = new Vector2(playerPos.x, playerPos.y);  
float scale = 1; //1 = default, 2 = twice the size
_spriteBatch.Draw(player,playerPos, null, Color.White, 0, origin, scale, SpriteEffects.None, 0);

Personally, I do not recommend sprite scaling through spritebatch, because that can cause the sprite to look blurry. If possible, change the sprite to a larger sprite instead.

\$\endgroup\$
2
  • \$\begingroup\$ thanks it worked \$\endgroup\$ Sep 3, 2020 at 8:32
  • \$\begingroup\$ @SankhayanBhattacharjee please consider marking this answer as accepted to show other users that this worked to solve the issue! \$\endgroup\$
    – Vaillancourt
    Sep 3, 2020 at 11:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .