Okay, I think I’ve got it.
The first problem I had is I wasn’t setting my environment up properly to that +y was up.
I’ll be writing a tutorial shortly that will spawn a static image in the centre of the screen, but the main focus will be setting up the world, and view.
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Collections.Generic;
using tainicom.Aether.Physics2D.Dynamics;
namespace AetherTutorial001
{
/// <summary>
/// This is the main type for your game.
/// </summary>
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
private BasicEffect _spriteBatchEffect;
private World _world;
private Matrix _projection;
private Texture2D _texture;
private Vector2 _origin;
private Vector2 _scale;
private Body _body;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
_spriteBatchEffect = new BasicEffect(graphics.GraphicsDevice);
_spriteBatchEffect.TextureEnabled = true;
_world = new World();
_texture = Content.Load<Texture2D>("Square");
_origin = new Vector2(_texture.Width / 2, _texture.Height / 2);
_scale = new Vector2(1f, 1f);
_body = _world.CreateRectangle(_scale.X, _scale.Y, 0.1f, new Vector2(0f, 0f));
_body.BodyType = BodyType.Static;
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// game-specific content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// update camera View Projection
var vp = GraphicsDevice.Viewport;
var cameraZoomFactor = 12.5f / vp.Width; // zoom out to about ~12.5 meters wide
_projection = Matrix.CreateOrthographic(vp.Width * cameraZoomFactor, vp.Height * cameraZoomFactor, 0f, -1f);
_world.Step((float)gameTime.ElapsedGameTime.TotalSeconds);
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
_spriteBatchEffect.Projection = _projection;
spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, RasterizerState.CullClockwise, _spriteBatchEffect);
spriteBatch.Draw(_texture, _body.Position, null, Color.White, _body.Rotation, _origin, _scale / new Vector2(_texture.Width, _texture.Height), SpriteEffects.FlipVertically, 0f);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
I think the above is about as basic as I can get it. I’m going to debug it over the weekend to see if I can understand it more.
With everything being rotated, and using the smaller values for positions and such, my brain is a little mumbled right now!