I was looking at Tiled | MonoGame.Extended and I was making a tile map, but there was an error
Code:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGame.Extended.Tweening;
using MonoGame.Extended.Tiled;
using MonoGame.Extended.Tiled.Renderers;
namespace simple_farming_game
{
public class Game1 : Game
{
Texture2D playerTexture;
Vector2 playerPosition;
float playerSpeed;
TiledMap _tiledMap;
TiledMapRenderer _tiledMapRenderer;
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public Game1()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
playerPosition = new Vector2(_graphics.PreferredBackBufferWidth / 2,_graphics.PreferredBackBufferHeight / 2);
playerSpeed = 550f;
base.Initialize();
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
playerTexture = Content.Load<Texture2D>("player");
_tiledMap = Content.Load<TiledMap>("tile1");
_tiledMapRenderer = new TiledMapRenderer(GraphicsDevice, _tiledMap);
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
// TODO: Add your update logic here
var kstate = Keyboard.GetState();
if (kstate.IsKeyDown(Keys.W))
{
playerPosition.Y -= playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
}
if (kstate.IsKeyDown(Keys.S))
{
playerPosition.Y += playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
}
if (kstate.IsKeyDown(Keys.A))
{
playerPosition.X -= playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
}
if (kstate.IsKeyDown(Keys.D))
{
playerPosition.X += playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
}
_tiledMapRenderer.Update(gameTime);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
_spriteBatch.Begin();
_spriteBatch.Draw(
playerTexture,
playerPosition,
null,
Color.White,
0f,
new Vector2(playerTexture.Width / 2, playerTexture.Height / 2),
Vector2.One,
SpriteEffects.None,
0f
);
_spriteBatch.End();
_tiledMapRenderer.Draw();
base.Draw(gameTime);
}
}
}
Error:
E:/simple_farming_game/Content/tile1.png : error : The type ‘Microsoft.Xna.Framework.Content.Pipeline.Graphics.Texture2
DContent’ cannot be processed by TiledMapProcessor as a MonoGame.Extended.Content.Pipeline.Tiled.TiledMapContentItem! [
E:\simple_farming_game\simple_farming_game.csproj]
C:\Users\armyo.nuget\packages\monogame.content.builder.task\3.8.1.303\build\MonoGame.Content.Builder.Task.targets(142,
5): error MSB3073: “dotnet mgcb /quiet /@:“E:\simple_farming_game\Content\Content.mgcb” /platform:DesktopGL /outputDir:
“E:/simple_farming_game/Content/bin/DesktopGL/Content” /intermediateDir:“E:/simple_farming_game/Content/obj/DesktopGL/n
et6.0/Content” /workingDir:“E:/simple_farming_game/Content/”” 명령이 종료되었습니다(코드: 1). [E:\simple_farming_game\simple_farmin
g_game.csproj]