mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-25 08:22:15 +00:00
demos are at least compiling again
This commit is contained in:
@@ -50,7 +50,7 @@ namespace Demo.Features.Demos
|
||||
var fireballTexture = Content.Load<Texture2D>("Animations/fireball");
|
||||
var fireballAtlas = TextureAtlas.Create("Animations/fireball-atlas", fireballTexture, 130, 50);
|
||||
_animation = new SpriteSheetAnimation("fireballAnimation", fireballAtlas.Regions.ToArray()) { FrameDuration = 0.2f };
|
||||
_fireballSprite = new Sprite(_animation.CurrentFrame) { Position = new Vector2(-150, 100) };
|
||||
_fireballSprite = new Sprite(_animation.CurrentFrame);// { Position = new Vector2(-150, 100) };
|
||||
|
||||
var motwTexture = Content.Load<Texture2D>("Animations/motw");
|
||||
var motwAtlas = TextureAtlas.Create("Animations/fireball-atlas", motwTexture, 52, 72);
|
||||
@@ -60,7 +60,7 @@ namespace Demo.Features.Demos
|
||||
motwAnimationFactory.Add("walkWest", new SpriteSheetAnimationData(new[] { 12, 13, 14, 13 }, isLooping: false));
|
||||
motwAnimationFactory.Add("walkEast", new SpriteSheetAnimationData(new[] { 24, 25, 26, 25 }, isLooping: false));
|
||||
motwAnimationFactory.Add("walkNorth", new SpriteSheetAnimationData(new[] { 36, 37, 38, 37 }, isLooping: false));
|
||||
_motwSprite = new AnimatedSprite(motwAnimationFactory) { Position = new Vector2(20, 20) };
|
||||
_motwSprite = new AnimatedSprite(motwAnimationFactory);// { Position = new Vector2(20, 20) };
|
||||
_motwSprite.Play("walkSouth").IsLooping = true;
|
||||
}
|
||||
|
||||
@@ -124,12 +124,12 @@ namespace Demo.Features.Demos
|
||||
|
||||
_spriteBatch.Begin(transformMatrix: Camera.GetViewMatrix(), samplerState: SamplerState.PointClamp);
|
||||
_zombie.Draw(_spriteBatch);
|
||||
_spriteBatch.Draw(_fireballSprite);
|
||||
//_spriteBatch.Draw(_fireballSprite);
|
||||
_spriteBatch.End();
|
||||
|
||||
_spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: Camera.GetViewMatrix());
|
||||
|
||||
_spriteBatch.Draw(_motwSprite);
|
||||
//_spriteBatch.Draw(_motwSprite);
|
||||
_spriteBatch.End();
|
||||
|
||||
base.Draw(gameTime);
|
||||
@@ -151,15 +151,16 @@ namespace Demo.Features.Demos
|
||||
private readonly AnimatedSprite _sprite;
|
||||
private float _direction = -1.0f;
|
||||
private ZombieState _state;
|
||||
private Transform2D _transform;
|
||||
|
||||
public RectangleF BoundingBox => _sprite.BoundingRectangle;
|
||||
public RectangleF BoundingBox => _sprite.GetBoundingRectangle(_transform.Position, _transform.Rotation, _transform.Scale);
|
||||
public bool IsOnGround { get; private set; }
|
||||
public bool IsReady => State != ZombieState.Appearing && State != ZombieState.Dying;
|
||||
|
||||
public Vector2 Position
|
||||
{
|
||||
get { return _sprite.Position; }
|
||||
set { _sprite.Position = value; }
|
||||
get { return _transform.Position; }
|
||||
set { _transform.Position = value; }
|
||||
}
|
||||
|
||||
public ZombieState State
|
||||
@@ -198,6 +199,7 @@ namespace Demo.Features.Demos
|
||||
public Zombie(SpriteSheetAnimationFactory animations)
|
||||
{
|
||||
_sprite = new AnimatedSprite(animations);
|
||||
_transform = new Transform2D();
|
||||
|
||||
State = ZombieState.Appearing;
|
||||
IsOnGround = false;
|
||||
@@ -215,7 +217,7 @@ namespace Demo.Features.Demos
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
spriteBatch.Draw(_sprite);
|
||||
//spriteBatch.Draw(_sprite);
|
||||
}
|
||||
|
||||
public void Walk(float direction)
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Demo.Features.Demos
|
||||
private Texture2D[] _backgroundHills;
|
||||
private Texture2D _backgroundSky;
|
||||
private BitmapFont _bitmapFont;
|
||||
private Camera2D _camera;
|
||||
private OrthographicCamera _camera;
|
||||
|
||||
private float _cloudsOffset;
|
||||
private SpriteBatch _spriteBatch;
|
||||
@@ -31,7 +31,7 @@ namespace Demo.Features.Demos
|
||||
protected override void LoadContent()
|
||||
{
|
||||
var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
|
||||
_camera = new Camera2D(viewportAdapter);
|
||||
_camera = new OrthographicCamera(viewportAdapter);
|
||||
|
||||
_bitmapFont = Content.Load<BitmapFont>("Fonts/montserrat-32");
|
||||
_backgroundSky = Content.Load<Texture2D>("Textures/hills-sky");
|
||||
|
||||
@@ -32,13 +32,13 @@ namespace Demo.Features.Demos
|
||||
protected GraphicsDevice GraphicsDevice => _game.GraphicsDevice;
|
||||
protected GameComponentCollection Components => _game.Components;
|
||||
|
||||
protected Camera2D Camera { get; private set; }
|
||||
protected OrthographicCamera Camera { get; private set; }
|
||||
protected ViewportAdapter ViewportAdapter { get; private set; }
|
||||
|
||||
protected virtual void Initialize()
|
||||
{
|
||||
ViewportAdapter = _game.ViewportAdapter;
|
||||
Camera = new Camera2D(ViewportAdapter);
|
||||
Camera = new OrthographicCamera(ViewportAdapter);
|
||||
}
|
||||
|
||||
protected virtual void LoadContent() { }
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Demo.Features.Demos
|
||||
private SpriteBatch _spriteBatch;
|
||||
private ViewportAdapter _viewportAdapter;
|
||||
private Texture2D _backgroundTexture;
|
||||
private Camera2D _camera;
|
||||
private OrthographicCamera _camera;
|
||||
private GuiSystem _guiSystem;
|
||||
|
||||
public GuiDemo(GameMain game) : base(game)
|
||||
@@ -32,7 +32,7 @@ namespace Demo.Features.Demos
|
||||
IsMouseVisible = false;
|
||||
|
||||
_viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
|
||||
_camera = new Camera2D(_viewportAdapter);
|
||||
_camera = new OrthographicCamera(_viewportAdapter);
|
||||
|
||||
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
_backgroundTexture = Content.Load<Texture2D>("Textures/colored_castle");
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace Demo.Features.Demos
|
||||
{
|
||||
public override string Name => "GUI Layouts";
|
||||
|
||||
private Camera2D _camera;
|
||||
private OrthographicCamera _camera;
|
||||
private GuiSystem _guiSystem;
|
||||
|
||||
public GuiLayoutDemo(GameMain game) : base(game)
|
||||
@@ -97,7 +97,7 @@ namespace Demo.Features.Demos
|
||||
protected override void LoadContent()
|
||||
{
|
||||
var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
|
||||
_camera = new Camera2D(viewportAdapter);
|
||||
_camera = new OrthographicCamera(viewportAdapter);
|
||||
|
||||
var skin = GuiSkin.FromFile(Content, @"Raw/adventure-gui-skin.json");
|
||||
var guiRenderer = new GuiSpriteBatchRenderer(GraphicsDevice, _camera.GetViewMatrix);
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Demo.Features.Demos
|
||||
private bool _isCursorVisible = true;
|
||||
private const float _cursorBlinkDelay = 0.5f;
|
||||
private float _cursorBlinkDelta = _cursorBlinkDelay;
|
||||
private Camera2D _camera;
|
||||
private OrthographicCamera _camera;
|
||||
|
||||
public InputListenersDemo(GameMain game) : base(game)
|
||||
{
|
||||
@@ -88,7 +88,7 @@ namespace Demo.Features.Demos
|
||||
protected override void LoadContent()
|
||||
{
|
||||
var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
|
||||
_camera = new Camera2D(viewportAdapter);
|
||||
_camera = new OrthographicCamera(viewportAdapter);
|
||||
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
|
||||
_backgroundTexture = Content.Load<Texture2D>("Textures/vignette");
|
||||
|
||||
@@ -26,7 +26,8 @@ namespace Demo.Features.Demos
|
||||
|
||||
private SpriteBatch _spriteBatch;
|
||||
private Sprite _sprite;
|
||||
private Camera2D _camera;
|
||||
private Transform2D _transform;
|
||||
private OrthographicCamera _camera;
|
||||
private ParticleEffect _particleEffect;
|
||||
private Texture2D _particleTexture;
|
||||
|
||||
@@ -35,13 +36,11 @@ namespace Demo.Features.Demos
|
||||
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
|
||||
var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
|
||||
_camera = new Camera2D(viewportAdapter);
|
||||
_camera = new OrthographicCamera(viewportAdapter);
|
||||
|
||||
var logoTexture = Content.Load<Texture2D>("Textures/logo-square-128");
|
||||
_sprite = new Sprite(logoTexture)
|
||||
{
|
||||
Position = viewportAdapter.Center.ToVector2()
|
||||
};
|
||||
_sprite = new Sprite(logoTexture);
|
||||
_transform = new Transform2D {Position = viewportAdapter.Center.ToVector2()};
|
||||
|
||||
_particleTexture = new Texture2D(GraphicsDevice, 1, 1);
|
||||
_particleTexture.SetData(new[] {Color.White});
|
||||
@@ -65,7 +64,7 @@ namespace Demo.Features.Demos
|
||||
if (keyboardState.IsKeyDown(Keys.Escape))
|
||||
Exit();
|
||||
|
||||
_sprite.Rotation += deltaTime;
|
||||
_transform.Rotation += deltaTime;
|
||||
|
||||
_particleEffect.Update(deltaTime);
|
||||
|
||||
@@ -83,7 +82,7 @@ namespace Demo.Features.Demos
|
||||
|
||||
_spriteBatch.Begin(blendState: BlendState.AlphaBlend, transformMatrix: _camera.GetViewMatrix());
|
||||
_spriteBatch.Draw(_particleEffect);
|
||||
_spriteBatch.Draw(_sprite);
|
||||
_spriteBatch.Draw(_sprite, _transform.Position, _transform.Rotation, _transform.Scale);
|
||||
_spriteBatch.End();
|
||||
|
||||
base.Draw(gameTime);
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Demo.Features.Demos
|
||||
public override string Name => "Scene Graphs";
|
||||
|
||||
private BitmapFont _bitmapFont;
|
||||
private Camera2D _camera;
|
||||
private OrthographicCamera _camera;
|
||||
private SceneNode _carNode;
|
||||
private SceneNode _hoveredNode;
|
||||
private SceneNode _leftWheelNode;
|
||||
@@ -36,7 +36,7 @@ namespace Demo.Features.Demos
|
||||
_bitmapFont = Content.Load<BitmapFont>("Fonts/montserrat-32");
|
||||
|
||||
var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
|
||||
_camera = new Camera2D(viewportAdapter)
|
||||
_camera = new OrthographicCamera(viewportAdapter)
|
||||
{
|
||||
Zoom = 2.0f
|
||||
};
|
||||
@@ -48,13 +48,13 @@ namespace Demo.Features.Demos
|
||||
var carWheelSprite = new Sprite(carWheelTexture);
|
||||
|
||||
_carNode = new SceneNode("car-hull", viewportAdapter.Center.ToVector2());
|
||||
_carNode.Entities.Add(carHullSprite);
|
||||
_carNode.Entities.Add(new SpriteEntity(carHullSprite));
|
||||
|
||||
_leftWheelNode = new SceneNode("left-wheel", new Vector2(-29, 17));
|
||||
_leftWheelNode.Entities.Add(carWheelSprite);
|
||||
_leftWheelNode.Entities.Add(new SpriteEntity(carWheelSprite));
|
||||
|
||||
_rightWheelNode = new SceneNode("right-wheel", new Vector2(40, 17));
|
||||
_rightWheelNode.Entities.Add(carWheelSprite);
|
||||
_rightWheelNode.Entities.Add(new SpriteEntity(carWheelSprite));
|
||||
|
||||
_carNode.Children.Add(_rightWheelNode);
|
||||
_carNode.Children.Add(_leftWheelNode);
|
||||
|
||||
@@ -39,24 +39,24 @@ namespace Demo.Features.Demos
|
||||
_axeSprite = new Sprite(axeTexture)
|
||||
{
|
||||
Origin = new Vector2(243, 679),
|
||||
Position = new Vector2(400, 0),
|
||||
Scale = Vector2.One * 0.5f
|
||||
//Position = new Vector2(400, 0),
|
||||
//Scale = Vector2.One * 0.5f
|
||||
};
|
||||
|
||||
var spikeyBallTexture = Content.Load<Texture2D>("Textures/spike_ball");
|
||||
_spikeyBallSprite = new Sprite(spikeyBallTexture)
|
||||
{
|
||||
Position = new Vector2(400, 340)
|
||||
//Position = new Vector2(400, 340)
|
||||
};
|
||||
|
||||
var particleTexture = Content.Load<Texture2D>("Textures/particle");
|
||||
_particleSprite0 = new Sprite(particleTexture)
|
||||
{
|
||||
Position = new Vector2(600, 340)
|
||||
//Position = new Vector2(600, 340)
|
||||
};
|
||||
_particleSprite1 = new Sprite(particleTexture)
|
||||
{
|
||||
Position = new Vector2(200, 340)
|
||||
//Position = new Vector2(200, 340)
|
||||
};
|
||||
_particleOpacity = 0.0f;
|
||||
}
|
||||
@@ -77,10 +77,10 @@ namespace Demo.Features.Demos
|
||||
if (keyboardState.IsKeyDown(Keys.Escape))
|
||||
Exit();
|
||||
|
||||
_axeSprite.Rotation = MathHelper.ToRadians(180) + MathHelper.PiOver2 * 0.8f * (float)Math.Sin(gameTime.TotalGameTime.TotalSeconds);
|
||||
//_axeSprite.Rotation = MathHelper.ToRadians(180) + MathHelper.PiOver2 * 0.8f * (float)Math.Sin(gameTime.TotalGameTime.TotalSeconds);
|
||||
|
||||
_spikeyBallSprite.Rotation -= deltaTime * 2.5f;
|
||||
_spikeyBallSprite.Position = new Vector2(mouseState.X, mouseState.Y);
|
||||
//_spikeyBallSprite.Rotation -= deltaTime * 2.5f;
|
||||
//_spikeyBallSprite.Position = new Vector2(mouseState.X, mouseState.Y);
|
||||
|
||||
_particleOpacity = 0.5f + (float)Math.Sin(gameTime.TotalGameTime.TotalSeconds);
|
||||
_particleSprite0.Color = Color.White * _particleOpacity;
|
||||
@@ -112,10 +112,10 @@ namespace Demo.Features.Demos
|
||||
{
|
||||
_spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp);
|
||||
_spriteBatch.Draw(_backgroundTexture, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
|
||||
_spriteBatch.Draw(_axeSprite);
|
||||
_spriteBatch.Draw(_spikeyBallSprite);
|
||||
_spriteBatch.Draw(_particleSprite0);
|
||||
_spriteBatch.Draw(_particleSprite1);
|
||||
//_spriteBatch.Draw(_axeSprite);
|
||||
//_spriteBatch.Draw(_spikeyBallSprite);
|
||||
//_spriteBatch.Draw(_particleSprite0);
|
||||
//_spriteBatch.Draw(_particleSprite1);
|
||||
|
||||
// clipping test
|
||||
_spriteBatch.Draw(_clippingTextureRegion, new Rectangle(50, 50, 128, 128), Color.White, clippingRectangle: null);
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Demo.Features.Demos
|
||||
public override string Name => "Tiled Maps";
|
||||
|
||||
private BitmapFont _bitmapFont;
|
||||
private Camera2D _camera;
|
||||
private OrthographicCamera _camera;
|
||||
private SpriteBatch _spriteBatch;
|
||||
private TiledMapRenderer _mapRenderer;
|
||||
private ViewportAdapter _viewportAdapter;
|
||||
@@ -36,8 +36,7 @@ namespace Demo.Features.Demos
|
||||
protected override void Initialize()
|
||||
{
|
||||
_viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 1024, 768);
|
||||
_camera = new Camera2D(_viewportAdapter);
|
||||
_mapRenderer = new TiledMapRenderer(GraphicsDevice);
|
||||
_camera = new OrthographicCamera(_viewportAdapter);
|
||||
|
||||
Window.AllowUserResizing = true;
|
||||
|
||||
@@ -70,6 +69,7 @@ namespace Demo.Features.Demos
|
||||
var name = _availableMaps.Dequeue();
|
||||
_map = Content.Load<TiledMap>($"TiledMaps/{name}");
|
||||
_availableMaps.Enqueue(name);
|
||||
_mapRenderer = new TiledMapRenderer(GraphicsDevice, _map);
|
||||
return _map;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace Demo.Features.Demos
|
||||
var deltaSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds;
|
||||
var keyboardState = Keyboard.GetState();
|
||||
|
||||
_mapRenderer.Update(_map, gameTime);
|
||||
_mapRenderer.Update(gameTime);
|
||||
|
||||
if (keyboardState.IsKeyDown(Keys.Escape))
|
||||
Exit();
|
||||
@@ -170,7 +170,7 @@ namespace Demo.Features.Demos
|
||||
var viewMatrix = _camera.GetViewMatrix();
|
||||
var projectionMatrix = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0f, -1f);
|
||||
|
||||
_mapRenderer.Draw(_map, ref viewMatrix, ref projectionMatrix, _customEffect);
|
||||
_mapRenderer.Draw(ref viewMatrix, ref projectionMatrix, _customEffect);
|
||||
|
||||
DrawText();
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@ namespace Demo.Features.Demos
|
||||
public class TweeningDemo : DemoBase
|
||||
{
|
||||
public override string Name => "Tweening";
|
||||
|
||||
private readonly Game _game;
|
||||
private SpriteBatch _spriteBatch;
|
||||
private Sprite _sprite;
|
||||
private Camera2D _camera;
|
||||
private Transform2D _transform;
|
||||
private OrthographicCamera _camera;
|
||||
|
||||
public TweeningDemo(GameMain game) : base(game)
|
||||
{
|
||||
@@ -38,16 +38,19 @@ namespace Demo.Features.Demos
|
||||
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
|
||||
var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
|
||||
_camera = new Camera2D(viewportAdapter);
|
||||
_camera = new OrthographicCamera(viewportAdapter);
|
||||
|
||||
var logoTexture = Content.Load<Texture2D>("Textures/logo-square-128");
|
||||
|
||||
_sprite = new Sprite(logoTexture)
|
||||
{
|
||||
Position = viewportAdapter.Center.ToVector2(),
|
||||
Scale = Vector2.One * 0.5f,
|
||||
Color = new Color(Color.White, 0.0f)
|
||||
};
|
||||
_transform = new Transform2D
|
||||
{
|
||||
Position = viewportAdapter.Center.ToVector2(),
|
||||
Scale = Vector2.One * 0.5f
|
||||
};
|
||||
|
||||
CreateTweenThing();
|
||||
|
||||
@@ -55,7 +58,7 @@ namespace Demo.Features.Demos
|
||||
|
||||
private void CreateTweenThing()
|
||||
{
|
||||
_sprite.CreateTweenChain(CreateTweenThing)
|
||||
_transform.CreateTweenChain(CreateTweenThing)
|
||||
.Rotate(MathHelper.Pi, 1.0f, EasingFunctions.BounceOut)
|
||||
.Scale(new Vector2(1.1f), 1.0f, EasingFunctions.BounceOut);
|
||||
}
|
||||
@@ -71,7 +74,7 @@ namespace Demo.Features.Demos
|
||||
|
||||
if (mouseState.LeftButton == ButtonState.Pressed)
|
||||
{
|
||||
_sprite
|
||||
_transform
|
||||
.CreateTweenGroup()
|
||||
.MoveTo(new Vector2(mouseState.X, mouseState.Y), 1.0f, EasingFunctions.BounceOut);
|
||||
}
|
||||
@@ -87,7 +90,7 @@ namespace Demo.Features.Demos
|
||||
GraphicsDevice.Clear(Color.Black);
|
||||
|
||||
_spriteBatch.Begin(blendState: BlendState.AlphaBlend, transformMatrix: _camera.GetViewMatrix());
|
||||
_spriteBatch.Draw(_sprite);
|
||||
_spriteBatch.Draw(_sprite, _transform.Position, _transform.Rotation, _transform.Scale);
|
||||
_spriteBatch.End();
|
||||
|
||||
base.Draw(gameTime);
|
||||
|
||||
@@ -17,7 +17,8 @@ namespace Demo.NuclexGui
|
||||
private readonly GraphicsDeviceManager _graphicsDeviceManager;
|
||||
private SpriteBatch _spriteBatch;
|
||||
private Sprite _sprite;
|
||||
private Camera2D _camera;
|
||||
private Transform2D _transform;
|
||||
private OrthographicCamera _camera;
|
||||
|
||||
private readonly InputListenerComponent _inputManager;
|
||||
private readonly GuiManager _gui;
|
||||
@@ -178,10 +179,11 @@ namespace Demo.NuclexGui
|
||||
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
|
||||
var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
|
||||
_camera = new Camera2D(viewportAdapter);
|
||||
_camera = new OrthographicCamera(viewportAdapter);
|
||||
|
||||
var logoTexture = Content.Load<Texture2D>("logo-square-128");
|
||||
_sprite = new Sprite(logoTexture)
|
||||
_sprite = new Sprite(logoTexture);
|
||||
_transform = new Transform2D
|
||||
{
|
||||
Position = viewportAdapter.Center.ToVector2()
|
||||
};
|
||||
@@ -203,7 +205,7 @@ namespace Demo.NuclexGui
|
||||
_inputManager.Update(gameTime);
|
||||
_gui.Update(gameTime);
|
||||
|
||||
_sprite.Rotation += deltaTime * _rotateDirection;
|
||||
_transform.Rotation += deltaTime * _rotateDirection;
|
||||
|
||||
base.Update(gameTime);
|
||||
}
|
||||
@@ -214,7 +216,7 @@ namespace Demo.NuclexGui
|
||||
|
||||
_spriteBatch.Begin(blendState: BlendState.AlphaBlend, transformMatrix: _camera.GetViewMatrix());
|
||||
|
||||
_spriteBatch.Draw(_sprite);
|
||||
_spriteBatch.Draw(_sprite, _transform);
|
||||
_spriteBatch.End();
|
||||
|
||||
// Draw GUI on top of everything
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Demo.Platformer.Entities.Systems
|
||||
[EntitySystem(GameLoopType.Draw, Layer = 0)]
|
||||
public class SpriteSystem : EntityProcessingSystem
|
||||
{
|
||||
private Camera2D _camera;
|
||||
private OrthographicCamera _camera;
|
||||
private SpriteBatch _spriteBatch;
|
||||
private Texture2D _pixelTexture;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Demo.Platformer.Entities.Systems
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_camera = Game.Services.GetService<Camera2D>();
|
||||
_camera = Game.Services.GetService<OrthographicCamera>();
|
||||
_spriteBatch = Game.Services.GetService<SpriteBatch>();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Demo.Platformer
|
||||
private readonly GraphicsDeviceManager _graphicsDeviceManager;
|
||||
|
||||
private SpriteBatch _spriteBatch;
|
||||
private Camera2D _camera;
|
||||
private OrthographicCamera _camera;
|
||||
private TiledMap _map;
|
||||
private TiledMapRenderer _mapRenderer;
|
||||
private EntityComponentSystem _ecs;
|
||||
@@ -49,22 +49,37 @@ namespace Demo.Platformer
|
||||
base.LoadContent();
|
||||
|
||||
var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
|
||||
_camera = new Camera2D(viewportAdapter);
|
||||
_camera = new OrthographicCamera(viewportAdapter);
|
||||
Services.AddService(_camera);
|
||||
|
||||
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
Services.AddService(_spriteBatch);
|
||||
|
||||
_map = Content.Load<TiledMap>("level-1");
|
||||
_mapRenderer = new TiledMapRenderer(GraphicsDevice);
|
||||
_mapRenderer = new TiledMapRenderer(GraphicsDevice, _map);
|
||||
_entityFactory = new EntityFactory(_ecs, Content);
|
||||
|
||||
MapLayers.BackgroundLayer = _map.Layers.IndexOf(_map.GetLayer("background"));
|
||||
MapLayers.SolidsLayer = _map.Layers.IndexOf(_map.GetLayer("solids"));
|
||||
MapLayers.DecorationsLayer = _map.Layers.IndexOf(_map.GetLayer("decorations"));
|
||||
MapLayers.Decorations2Layer = _map.Layers.IndexOf(_map.GetLayer("decorations2"));
|
||||
MapLayers.DeadliesLayer = _map.Layers.IndexOf(_map.GetLayer("deadlies"));
|
||||
|
||||
var service = new TiledObjectToEntityService(_entityFactory);
|
||||
var spawnPoint = _map.GetLayer<TiledMapObjectLayer>("entities").Objects.Single(i => i.Type == "Spawn").Position;
|
||||
|
||||
service.CreateEntities(_map.GetLayer<TiledMapObjectLayer>("entities").Objects);
|
||||
}
|
||||
|
||||
private static class MapLayers
|
||||
{
|
||||
public static int BackgroundLayer { get; set; }
|
||||
public static int SolidsLayer { get; set; }
|
||||
public static int DecorationsLayer { get; set; }
|
||||
public static int Decorations2Layer { get; set; }
|
||||
public static int DeadliesLayer { get; set; }
|
||||
}
|
||||
|
||||
protected override void Update(GameTime gameTime)
|
||||
{
|
||||
var keyboardState = Keyboard.GetState();
|
||||
@@ -87,22 +102,15 @@ namespace Demo.Platformer
|
||||
|
||||
// painter's algorithm; just draw things in the expected order
|
||||
|
||||
var backgroundLayer = _map.GetLayer("background");
|
||||
_mapRenderer.Draw(backgroundLayer, ref viewMatrix, ref projectionMatrix);
|
||||
|
||||
var solidsLayer = _map.GetLayer("solids");
|
||||
_mapRenderer.Draw(solidsLayer);
|
||||
|
||||
var decorationsLayer = _map.GetLayer("decorations");
|
||||
_mapRenderer.Draw(decorationsLayer, ref viewMatrix, ref projectionMatrix);
|
||||
_mapRenderer.Draw(MapLayers.BackgroundLayer, ref viewMatrix, ref projectionMatrix);
|
||||
_mapRenderer.Draw(MapLayers.SolidsLayer);
|
||||
_mapRenderer.Draw(MapLayers.DecorationsLayer, ref viewMatrix, ref projectionMatrix);
|
||||
|
||||
_ecs.Draw(gameTime);
|
||||
|
||||
var decorations2Layer = _map.GetLayer("decorations2");
|
||||
_mapRenderer.Draw(decorations2Layer, ref viewMatrix, ref projectionMatrix);
|
||||
_mapRenderer.Draw(MapLayers.Decorations2Layer, ref viewMatrix, ref projectionMatrix);
|
||||
_mapRenderer.Draw(MapLayers.DeadliesLayer, ref viewMatrix, ref projectionMatrix);
|
||||
|
||||
var deadliesLayer = _map.GetLayer("deadlies");
|
||||
_mapRenderer.Draw(deadliesLayer, ref viewMatrix, ref projectionMatrix);
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Demo.SpaceGame
|
||||
private readonly GraphicsDeviceManager _graphicsDeviceManager;
|
||||
private Texture2D _backgroundTexture;
|
||||
private BulletFactory _bulletFactory;
|
||||
private Camera2D _camera;
|
||||
private OrthographicCamera _camera;
|
||||
private SpriteSheetAnimationFactory _explosionAnimations;
|
||||
private BitmapFont _font;
|
||||
private MeteorFactory _meteorFactory;
|
||||
@@ -58,7 +58,7 @@ namespace Demo.SpaceGame
|
||||
_viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
|
||||
_font = Content.Load<BitmapFont>("Fonts/montserrat-32");
|
||||
|
||||
_camera = new Camera2D(_viewportAdapter);
|
||||
_camera = new OrthographicCamera(_viewportAdapter);
|
||||
_explosionAnimations = Content.Load<SpriteSheetAnimationFactory>("explosion-animations");
|
||||
|
||||
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace MonoGame.Extended.SceneGraphs
|
||||
{
|
||||
public class SceneEntityCollection : Collection<IRectangularF>
|
||||
public class SceneEntityCollection : Collection<SceneEntity>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,23 @@ using MonoGame.Extended.Sprites;
|
||||
|
||||
namespace MonoGame.Extended.SceneGraphs
|
||||
{
|
||||
public abstract class SceneEntity : Transform2D, IRectangularF
|
||||
{
|
||||
public abstract RectangleF BoundingRectangle { get; }
|
||||
}
|
||||
|
||||
public class SpriteEntity : SceneEntity
|
||||
{
|
||||
private readonly Sprite _sprite;
|
||||
|
||||
public SpriteEntity(Sprite sprite)
|
||||
{
|
||||
_sprite = sprite;
|
||||
}
|
||||
|
||||
public override RectangleF BoundingRectangle => _sprite.GetBoundingRectangle(Position, Rotation, Scale);
|
||||
}
|
||||
|
||||
public class SceneNode : Transform2D
|
||||
{
|
||||
public SceneNode(string name)
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace MonoGame.Extended.Tiled
|
||||
{
|
||||
public sealed class TiledMapEllipseObject : TiledMapObject
|
||||
{
|
||||
public TiledMapEllipseObject(int identifier, string name, Size2 size, Vector2 position, float rotation = 0, float opacity = 1, bool isVisible = true)
|
||||
: base(identifier, name, size, position, rotation, opacity, isVisible)
|
||||
public TiledMapEllipseObject(int identifier, string name, Size2 size, Vector2 position, float rotation = 0, float opacity = 1, bool isVisible = true, string type = null)
|
||||
: base(identifier, name, size, position, rotation, opacity, isVisible, type)
|
||||
{
|
||||
Radius = new Vector2(size.Width / 2.0f, size.Height / 2.0f);
|
||||
Center = new Vector2(position.X + Radius.X, position.Y);
|
||||
@@ -13,6 +13,5 @@ namespace MonoGame.Extended.Tiled
|
||||
|
||||
public Vector2 Center { get; }
|
||||
public Vector2 Radius { get; }
|
||||
public override TiledMapObjectType Type => TiledMapObjectType.Ellipse;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace MonoGame.Extended.Tiled
|
||||
{
|
||||
public abstract class TiledMapObject
|
||||
{
|
||||
protected TiledMapObject(int identifier, string name, Size2 size, Vector2 position, float rotation = 0, float opacity = 1, bool isVisible = true)
|
||||
protected TiledMapObject(int identifier, string name, Size2 size, Vector2 position, float rotation = 0, float opacity = 1, bool isVisible = true, string type = null)
|
||||
{
|
||||
Identifier = identifier;
|
||||
Name = name;
|
||||
@@ -13,12 +13,13 @@ namespace MonoGame.Extended.Tiled
|
||||
Position = position;
|
||||
Size = size;
|
||||
Opacity = opacity;
|
||||
Type = type;
|
||||
Properties = new TiledMapProperties();
|
||||
}
|
||||
|
||||
public int Identifier { get; }
|
||||
public string Name { get; set; }
|
||||
public abstract TiledMapObjectType Type { get; }
|
||||
public string Type { get; set; }
|
||||
public bool IsVisible { get; set; }
|
||||
public float Opacity { get; set; }
|
||||
public float Rotation { get; set; }
|
||||
|
||||
@@ -4,13 +4,12 @@ namespace MonoGame.Extended.Tiled
|
||||
{
|
||||
public sealed class TiledMapPolygonObject : TiledMapObject
|
||||
{
|
||||
public TiledMapPolygonObject(int identifier, string name, Point2[] points, Size2 size, Vector2 position, float rotation = 0, float opacity = 1, bool isVisible = true)
|
||||
: base(identifier, name, size, position, rotation, opacity, isVisible)
|
||||
public TiledMapPolygonObject(int identifier, string name, Point2[] points, Size2 size, Vector2 position, float rotation = 0, float opacity = 1, bool isVisible = true, string type = null)
|
||||
: base(identifier, name, size, position, rotation, opacity, isVisible, type)
|
||||
{
|
||||
Points = points;
|
||||
}
|
||||
|
||||
public Point2[] Points { get; }
|
||||
public override TiledMapObjectType Type => TiledMapObjectType.Polygon;
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,12 @@ namespace MonoGame.Extended.Tiled
|
||||
{
|
||||
public sealed class TiledMapPolylineObject : TiledMapObject
|
||||
{
|
||||
public TiledMapPolylineObject(int identifier, string name, Point2[] points, Size2 size, Vector2 position, float rotation = 0, float opacity = 1, bool isVisible = true)
|
||||
: base(identifier, name, size, position, rotation, opacity, isVisible)
|
||||
public TiledMapPolylineObject(int identifier, string name, Point2[] points, Size2 size, Vector2 position, float rotation = 0, float opacity = 1, bool isVisible = true, string type = null)
|
||||
: base(identifier, name, size, position, rotation, opacity, isVisible, type)
|
||||
{
|
||||
Points = points;
|
||||
}
|
||||
|
||||
public Point2[] Points { get; }
|
||||
public override TiledMapObjectType Type => TiledMapObjectType.Polyline;
|
||||
}
|
||||
}
|
||||
@@ -63,37 +63,63 @@ namespace MonoGame.Extended.Tiled
|
||||
|
||||
|
||||
|
||||
private static TiledMapTileset ReadTileset(ContentReader input, TiledMap map)
|
||||
private static TiledMapTileset ReadTileset(ContentReader reader, TiledMap map)
|
||||
{
|
||||
var textureAssetName = input.GetRelativeAssetName(input.ReadString());
|
||||
var texture = input.ContentManager.Load<Texture2D>(textureAssetName);
|
||||
var firstGlobalIdentifier = input.ReadInt32();
|
||||
var tileWidth = input.ReadInt32();
|
||||
var tileHeight = input.ReadInt32();
|
||||
var tileCount = input.ReadInt32();
|
||||
var spacing = input.ReadInt32();
|
||||
var margin = input.ReadInt32();
|
||||
var columns = input.ReadInt32();
|
||||
var explicitTileCount = input.ReadInt32();
|
||||
var textureAssetName = reader.GetRelativeAssetName(reader.ReadString());
|
||||
var texture = reader.ContentManager.Load<Texture2D>(textureAssetName);
|
||||
var firstGlobalIdentifier = reader.ReadInt32();
|
||||
var tileWidth = reader.ReadInt32();
|
||||
var tileHeight = reader.ReadInt32();
|
||||
var tileCount = reader.ReadInt32();
|
||||
var spacing = reader.ReadInt32();
|
||||
var margin = reader.ReadInt32();
|
||||
var columns = reader.ReadInt32();
|
||||
var explicitTileCount = reader.ReadInt32();
|
||||
|
||||
var tileset = new TiledMapTileset(texture, firstGlobalIdentifier, tileWidth, tileHeight, tileCount, spacing, margin, columns);
|
||||
|
||||
for (var tileIndex = 0; tileIndex < explicitTileCount; tileIndex++)
|
||||
{
|
||||
var localTileIdentifier = input.ReadInt32();
|
||||
var animationFramesCount = input.ReadInt32();
|
||||
var localTileIdentifier = reader.ReadInt32();
|
||||
var animationFramesCount = reader.ReadInt32();
|
||||
var tilesetTile = animationFramesCount <= 0
|
||||
? new TiledMapTilesetTile(localTileIdentifier, input)
|
||||
: new TiledMapTilesetAnimatedTile(tileset, input, localTileIdentifier, animationFramesCount);
|
||||
? ReadTiledMapTilesetTile(reader, map, objects => new TiledMapTilesetTile(localTileIdentifier, objects))
|
||||
: ReadTiledMapTilesetTile(reader, map, objects => new TiledMapTilesetAnimatedTile(localTileIdentifier, ReadTiledMapTilesetAnimationFrames(reader, tileset, animationFramesCount)));
|
||||
|
||||
ReadProperties(input, tilesetTile.Properties);
|
||||
ReadProperties(reader, tilesetTile.Properties);
|
||||
tileset.Tiles.Add(tilesetTile);
|
||||
}
|
||||
|
||||
ReadProperties(input, tileset.Properties);
|
||||
ReadProperties(reader, tileset.Properties);
|
||||
return tileset;
|
||||
}
|
||||
|
||||
private static TiledMapTilesetTileAnimationFrame[] ReadTiledMapTilesetAnimationFrames(ContentReader reader, TiledMapTileset tileset, int animationFramesCount)
|
||||
{
|
||||
var animationFrames = new TiledMapTilesetTileAnimationFrame[animationFramesCount];
|
||||
|
||||
for (var i = 0; i < animationFramesCount; i++)
|
||||
{
|
||||
var localTileIdentifierForFrame = reader.ReadInt32();
|
||||
var frameDurationInMilliseconds = reader.ReadInt32();
|
||||
var tileSetTileFrame = new TiledMapTilesetTileAnimationFrame(tileset, localTileIdentifierForFrame, frameDurationInMilliseconds);
|
||||
animationFrames[i] = tileSetTileFrame;
|
||||
}
|
||||
|
||||
return animationFrames;
|
||||
}
|
||||
|
||||
private static TiledMapTilesetTile ReadTiledMapTilesetTile(ContentReader reader, TiledMap map, Func<TiledMapObject[], TiledMapTilesetTile> createTile)
|
||||
{
|
||||
var objectCount = reader.ReadInt32();
|
||||
var objects = new TiledMapObject[objectCount];
|
||||
|
||||
for (var i = 0; i < objectCount; i++)
|
||||
objects[i] = ReadTiledMapObject(reader, map);
|
||||
|
||||
return createTile(objects);
|
||||
}
|
||||
|
||||
private static void ReadLayers(ContentReader reader, TiledMap map)
|
||||
{
|
||||
var layerCount = reader.ReadInt32();
|
||||
@@ -179,7 +205,7 @@ namespace MonoGame.Extended.Tiled
|
||||
switch (objectType)
|
||||
{
|
||||
case TiledMapObjectType.Rectangle:
|
||||
mapObject = new TiledMapRectangleObject(identifier, name, size, position, rotation, opacity, isVisible);
|
||||
mapObject = new TiledMapRectangleObject(identifier, name, size, position, rotation, opacity, isVisible, type);
|
||||
break;
|
||||
case TiledMapObjectType.Tile:
|
||||
var globalTileIdentifierWithFlags = reader.ReadUInt32();
|
||||
@@ -187,17 +213,16 @@ namespace MonoGame.Extended.Tiled
|
||||
var tileset = map.GetTilesetByTileGlobalIdentifier(tile.GlobalIdentifier);
|
||||
var localTileIdentifier = tile.GlobalIdentifier - tileset.FirstGlobalIdentifier;
|
||||
var tilesetTile = tileset.Tiles.FirstOrDefault(x => x.LocalTileIdentifier == localTileIdentifier);
|
||||
mapObject = new TiledMapTileObject(identifier, name, tileset, tilesetTile, size, position, rotation, opacity, isVisible);
|
||||
mapObject = new TiledMapTileObject(identifier, name, tileset, tilesetTile, size, position, rotation, opacity, isVisible, type);
|
||||
break;
|
||||
case TiledMapObjectType.Ellipse:
|
||||
mapObject = new TiledMapEllipseObject(identifier, name, size, position, rotation, opacity, isVisible);
|
||||
break;
|
||||
case TiledMapObjectType.Polygon:
|
||||
mapObject = new TiledMapPolygonObject(identifier, name, ReadPoints(reader), size, position, rotation, opacity, isVisible);
|
||||
mapObject = new TiledMapPolygonObject(identifier, name, ReadPoints(reader), size, position, rotation, opacity, isVisible, type);
|
||||
break;
|
||||
case TiledMapObjectType.Polyline:
|
||||
var points = ReadPoints(reader);
|
||||
mapObject = new TiledMapPolylineObject(identifier, name, ReadPoints(reader), size, position, rotation, opacity, isVisible);
|
||||
mapObject = new TiledMapPolylineObject(identifier, name, ReadPoints(reader), size, position, rotation, opacity, isVisible, type);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
@@ -206,7 +231,7 @@ namespace MonoGame.Extended.Tiled
|
||||
foreach (var property in properties)
|
||||
mapObject.Properties.Add(property.Key, property.Value);
|
||||
|
||||
throw new ArgumentOutOfRangeException();
|
||||
return mapObject;
|
||||
}
|
||||
|
||||
private static Point2[] ReadPoints(ContentReader reader)
|
||||
|
||||
@@ -4,11 +4,9 @@ namespace MonoGame.Extended.Tiled
|
||||
{
|
||||
public sealed class TiledMapRectangleObject : TiledMapObject
|
||||
{
|
||||
public TiledMapRectangleObject(int identifier, string name, Size2 size, Vector2 position, float rotation = 0, float opacity = 1, bool isVisible = true)
|
||||
: base(identifier, name, size, position, rotation, opacity, isVisible)
|
||||
public TiledMapRectangleObject(int identifier, string name, Size2 size, Vector2 position, float rotation = 0, float opacity = 1, bool isVisible = true, string type = null)
|
||||
: base(identifier, name, size, position, rotation, opacity, isVisible, type)
|
||||
{
|
||||
}
|
||||
|
||||
public override TiledMapObjectType Type => TiledMapObjectType.Rectangle;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ namespace MonoGame.Extended.Tiled
|
||||
public sealed class TiledMapTileObject : TiledMapObject
|
||||
{
|
||||
public TiledMapTileObject(int identifier, string name, TiledMapTileset tileset, TiledMapTilesetTile tile,
|
||||
Size2 size, Vector2 position, float rotation = 0, float opacity = 1, bool isVisible = true)
|
||||
: base(identifier, name, size, position, rotation, opacity, isVisible)
|
||||
Size2 size, Vector2 position, float rotation = 0, float opacity = 1, bool isVisible = true, string type = null)
|
||||
: base(identifier, name, size, position, rotation, opacity, isVisible, type)
|
||||
{
|
||||
Tileset = tileset;
|
||||
Tile = tile;
|
||||
@@ -14,6 +14,5 @@ namespace MonoGame.Extended.Tiled
|
||||
|
||||
public TiledMapTilesetTile Tile { get; }
|
||||
public TiledMapTileset Tileset { get; }
|
||||
public override TiledMapObjectType Type => TiledMapObjectType.Tile;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
|
||||
namespace MonoGame.Extended.Tiled
|
||||
{
|
||||
public class TiledMapTilesetAnimatedTile : TiledMapTilesetTile
|
||||
{
|
||||
private readonly List<TiledMapTilesetTileAnimationFrame> _animationFrames =
|
||||
new List<TiledMapTilesetTileAnimationFrame>();
|
||||
|
||||
private TimeSpan _timer = TimeSpan.Zero;
|
||||
private int _frameIndex;
|
||||
private TimeSpan _timer;
|
||||
|
||||
public ReadOnlyCollection<TiledMapTilesetTileAnimationFrame> AnimationFrames { get; }
|
||||
public TiledMapTilesetTileAnimationFrame CurrentAnimationFrame { get; private set; }
|
||||
|
||||
internal TiledMapTilesetAnimatedTile(TiledMapTileset tileset, ContentReader input, int localTileIdentifier, int animationFramesCount)
|
||||
: base(localTileIdentifier,input)
|
||||
public TiledMapTilesetAnimatedTile(int localTileIdentifier, TiledMapTilesetTileAnimationFrame[] frames, TiledMapObject[] objects = null)
|
||||
: base(localTileIdentifier, objects)
|
||||
{
|
||||
AnimationFrames = new ReadOnlyCollection<TiledMapTilesetTileAnimationFrame>(_animationFrames);
|
||||
_timer = TimeSpan.Zero;
|
||||
if (frames.Length == 0) throw new InvalidOperationException("There must be at least one tileset animation frame");
|
||||
|
||||
for (var i = 0; i < animationFramesCount; i++)
|
||||
{
|
||||
var localTileIdentifierForFrame = input.ReadInt32();
|
||||
var frameDurationInMilliseconds = input.ReadInt32();
|
||||
var tileSetTileFrame = new TiledMapTilesetTileAnimationFrame(tileset, localTileIdentifierForFrame, frameDurationInMilliseconds);
|
||||
_animationFrames.Add(tileSetTileFrame);
|
||||
CurrentAnimationFrame = AnimationFrames[0];
|
||||
}
|
||||
AnimationFrames = new ReadOnlyCollection<TiledMapTilesetTileAnimationFrame>(frames);
|
||||
CurrentAnimationFrame = AnimationFrames[0];
|
||||
}
|
||||
|
||||
public void Update(GameTime gameTime)
|
||||
{
|
||||
if (_animationFrames.Count == 0)
|
||||
return;
|
||||
|
||||
_timer += gameTime.ElapsedGameTime;
|
||||
|
||||
if (_timer <= CurrentAnimationFrame.Duration)
|
||||
return;
|
||||
|
||||
|
||||
@@ -1,49 +1,18 @@
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MonoGame.Extended.Tiled
|
||||
{
|
||||
public class TiledMapTilesetTile
|
||||
{
|
||||
internal TiledMapTilesetTile(int localTileIdentifier, ContentReader input)
|
||||
public TiledMapTilesetTile(int localTileIdentifier, TiledMapObject[] objects = null)
|
||||
{
|
||||
var objectCount = input.ReadInt32();
|
||||
|
||||
var objects = new TiledMapObject[objectCount];
|
||||
|
||||
for (var i = 0; i < objectCount; i++)
|
||||
{
|
||||
TiledMapObject @object;
|
||||
|
||||
var objectType = (TiledMapObjectType)input.ReadByte();
|
||||
switch (objectType)
|
||||
{
|
||||
case TiledMapObjectType.Rectangle:
|
||||
@object = new TiledMapRectangleObject(input);
|
||||
break;
|
||||
case TiledMapObjectType.Ellipse:
|
||||
@object = new TiledMapEllipseObject(input);
|
||||
break;
|
||||
case TiledMapObjectType.Polygon:
|
||||
@object = new TiledMapPolygonObject(input);
|
||||
break;
|
||||
case TiledMapObjectType.Polyline:
|
||||
@object = new TiledMapPolylineObject(input);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
objects[i] = @object;
|
||||
}
|
||||
|
||||
Objects = objects;
|
||||
LocalTileIdentifier = localTileIdentifier;
|
||||
Objects = objects != null ? new List<TiledMapObject>(objects) : new List<TiledMapObject>();
|
||||
Properties = new TiledMapProperties();
|
||||
}
|
||||
|
||||
public int LocalTileIdentifier { get; set; }
|
||||
public int LocalTileIdentifier { get; }
|
||||
public TiledMapProperties Properties { get; }
|
||||
public TiledMapObject[] Objects { get; set; }
|
||||
public List<TiledMapObject> Objects { get; }
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,11 @@ namespace MonoGame.Extended.Sprites
|
||||
|
||||
public Color Color { get; set; }
|
||||
|
||||
public RectangleF GetBoundingRectangle(Transform2D transform)
|
||||
{
|
||||
return GetBoundingRectangle(transform.Position, transform.Rotation, transform.Scale);
|
||||
}
|
||||
|
||||
public RectangleF GetBoundingRectangle(Vector2 position, float rotation, Vector2 scale)
|
||||
{
|
||||
var corners = GetCorners(position, rotation, scale);
|
||||
|
||||
@@ -11,6 +11,11 @@ namespace MonoGame.Extended.Sprites
|
||||
Draw(spriteBatch, sprite, position, rotation, scale);
|
||||
}
|
||||
|
||||
public static void Draw(this SpriteBatch spriteBatch, Sprite sprite, Transform2D transform)
|
||||
{
|
||||
Draw(spriteBatch, sprite, transform.Position, transform.Rotation, transform.Scale);
|
||||
}
|
||||
|
||||
public static void Draw(this SpriteBatch spriteBatch, Sprite sprite, Vector2 position, float rotation, Vector2 scale)
|
||||
{
|
||||
if (sprite == null) throw new ArgumentNullException(nameof(sprite));
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace MonoGame.Extended.Tests
|
||||
{
|
||||
var graphicsDevice = TestHelper.CreateGraphicsDevice();
|
||||
var viewportAdapter = new DefaultViewportAdapter(graphicsDevice);
|
||||
var camera = new Camera2D(viewportAdapter);
|
||||
var camera = new OrthographicCamera(viewportAdapter);
|
||||
|
||||
camera.LookAt(new Vector2(100, 200));
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace MonoGame.Extended.Tests
|
||||
public void Camera2D_GetBoundingFrustum_Test()
|
||||
{
|
||||
var graphicsDevice = TestHelper.CreateGraphicsDevice();
|
||||
var camera = new Camera2D(graphicsDevice);
|
||||
var camera = new OrthographicCamera(graphicsDevice);
|
||||
var boundingFrustum = camera.GetBoundingFrustum();
|
||||
var corners = boundingFrustum.GetCorners();
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace MonoGame.Extended.Tests
|
||||
{
|
||||
var graphicsDevice = TestHelper.CreateGraphicsDevice();
|
||||
var viewport = new DefaultViewportAdapter(graphicsDevice);
|
||||
var camera = new Camera2D(viewport);
|
||||
var camera = new OrthographicCamera(viewport);
|
||||
camera.Move(new Vector2(2, 0));
|
||||
camera.Move(new Vector2(0, 3));
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace MonoGame.Extended.Tests
|
||||
public void Camera2D_ContainsPoint_Test()
|
||||
{
|
||||
var graphicsDevice = TestHelper.CreateGraphicsDevice();
|
||||
var camera = new Camera2D(graphicsDevice);
|
||||
var camera = new OrthographicCamera(graphicsDevice);
|
||||
|
||||
Assert.AreEqual(ContainmentType.Contains, camera.Contains(new Point(1, 1)));
|
||||
Assert.AreEqual(ContainmentType.Contains, camera.Contains(new Point(799, 479)));
|
||||
@@ -71,7 +71,7 @@ namespace MonoGame.Extended.Tests
|
||||
public void Camera2D_ContainsVector2_Test()
|
||||
{
|
||||
var graphicsDevice = TestHelper.CreateGraphicsDevice();
|
||||
var camera = new Camera2D(graphicsDevice);
|
||||
var camera = new OrthographicCamera(graphicsDevice);
|
||||
|
||||
Assert.AreEqual(ContainmentType.Contains, camera.Contains(new Vector2(799.5f, 479.5f)));
|
||||
Assert.AreEqual(ContainmentType.Contains, camera.Contains(new Vector2(0.5f, 0.5f)));
|
||||
@@ -87,7 +87,7 @@ namespace MonoGame.Extended.Tests
|
||||
public void Camera2D_ContainsRectangle_Test()
|
||||
{
|
||||
var graphicsDevice = TestHelper.CreateGraphicsDevice();
|
||||
var camera = new Camera2D(graphicsDevice);
|
||||
var camera = new OrthographicCamera(graphicsDevice);
|
||||
|
||||
Assert.AreEqual(ContainmentType.Intersects, camera.Contains(new Rectangle(-50, -50, 100, 100)));
|
||||
Assert.AreEqual(ContainmentType.Contains, camera.Contains(new Rectangle(50, 50, 100, 100)));
|
||||
|
||||
@@ -15,12 +15,9 @@ namespace MonoGame.Extended.Tests.Sprites
|
||||
{
|
||||
var graphicsDevice = TestHelper.CreateGraphicsDevice();
|
||||
var texture = Substitute.For<Texture2D>(graphicsDevice, 50, 200);
|
||||
var sprite = new Sprite(texture)
|
||||
{
|
||||
Position = new Vector2(400, 240)
|
||||
};
|
||||
var sprite = new Sprite(texture);
|
||||
|
||||
Assert.AreEqual(new RectangleF(375, 140, 50, 200), sprite.BoundingRectangle);
|
||||
Assert.AreEqual(new RectangleF(375, 140, 50, 200), sprite.GetBoundingRectangle(new Vector2(400, 240), 0, Vector2.One));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -28,12 +25,9 @@ namespace MonoGame.Extended.Tests.Sprites
|
||||
{
|
||||
var graphicsDevice = TestHelper.CreateGraphicsDevice();
|
||||
var texture = Substitute.For<Texture2D>(graphicsDevice, 50, 200);
|
||||
var sprite = new Sprite(texture)
|
||||
{
|
||||
OriginNormalized = new Vector2(1.0f, 1.0f)
|
||||
};
|
||||
var sprite = new Sprite(texture) { OriginNormalized = new Vector2(1.0f, 1.0f) };
|
||||
|
||||
Assert.AreEqual(new RectangleF(-50, -200, 50, 200), sprite.BoundingRectangle);
|
||||
Assert.AreEqual(new RectangleF(-50, -200, 50, 200), sprite.GetBoundingRectangle(Vector2.Zero, 0, Vector2.One));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -41,12 +35,9 @@ namespace MonoGame.Extended.Tests.Sprites
|
||||
{
|
||||
var graphicsDevice = TestHelper.CreateGraphicsDevice();
|
||||
var texture = Substitute.For<Texture2D>(graphicsDevice, 50, 200);
|
||||
var sprite = new Sprite(texture)
|
||||
{
|
||||
Scale = Vector2.One * 2.0f
|
||||
};
|
||||
var sprite = new Sprite(texture);
|
||||
|
||||
Assert.AreEqual(new RectangleF(-50, -200, 100, 400), sprite.BoundingRectangle);
|
||||
Assert.AreEqual(new RectangleF(-50, -200, 100, 400), sprite.GetBoundingRectangle(Vector2.Zero, 0, Vector2.One * 2.0f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -54,12 +45,9 @@ namespace MonoGame.Extended.Tests.Sprites
|
||||
{
|
||||
var graphicsDevice = TestHelper.CreateGraphicsDevice();
|
||||
var texture = Substitute.For<Texture2D>(graphicsDevice, 50, 200);
|
||||
var sprite = new Sprite(texture)
|
||||
{
|
||||
Rotation = MathHelper.ToRadians(90)
|
||||
};
|
||||
var sprite = new Sprite(texture);
|
||||
|
||||
AssertExtensions.AreApproximatelyEqual(new RectangleF(-100, -25, 200, 50), sprite.BoundingRectangle);
|
||||
AssertExtensions.AreApproximatelyEqual(new RectangleF(-100, -25, 200, 50), sprite.GetBoundingRectangle(Vector2.Zero, MathHelper.ToRadians(90), Vector2.One * 2.0f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in New Issue
Block a user