Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Monogame Introduction (ENG)

Aloïs Deniel
September 07, 2016

Monogame Introduction (ENG)

A quick introduction to game development through Monogame cross platform framework.

Aloïs Deniel

September 07, 2016
Tweet

More Decks by Aloïs Deniel

Other Decks in Programming

Transcript

  1. Technical Leader Xamarin My job Aloïs DENIEL [email protected] @aloisdeniel Why?

    That was my first experience with C# Different from common UI development Based sur Xamarin Adapted to different needs Where? Orange Applications for Business Rennes
  2. The framework MONOGAME Xamarin .NET DirectX OpenGL SharpDX SDL2 Open-source

    and cross-platform re-implementation of the XNA framework, abandonned by Microsoft few years ago. It is mainly used in game industry, for 2D games.
  3. Outils et APIs MONOGAME Xamarin / .NET C# Visual Studio

    Xamarin Studio Monogame Content Pipeline PNG WAV MP3 Font
  4. Main cycle Main class: Game public class Game : Idisposable

    { // … protected virtual void Initialize (); protected virtual void LoadContent (); protected virtual void Update (GameTime time); protected virtual void Draw (GameTime time); }
  5. protected override void Draw (GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(SpriteSortMode.Immediate); spriteBatch.Draw(this.texture,

    this.position1, Color.White); spriteBatch.Draw(this.texture, this.position2, Color.White); spriteBatch.Draw(this.texture, this.position3, Color.White); spriteBatch.End(); Spritebatch Begin Draw Draw Draw End
  6. Tiles 1 2 3 1 1 1 2 3 3

    Image portions
  7. Tiles var source = new Rectangle(50,0,50,50); var destination = new

    Rectangle(150,0,50,50); spriteBatch.Draw(this.tiles, sourceRectangle: source, destinationRectangle: destination); Source 2 Destination tiles.png Image portions
  8. Camera Var transform = Matrix.CreateTranslation(new Vector3(-100,0,0)) * Matrix.CreateRotationZ(0.05f) * Matrix.CreateScale(new

    Vector3(2,2,1)); spriteBatch.Begin(transformMatrix: transform); Matrix maths Ecran
  9. User inputs var state = Mouse.GetState(); state.X , state.Y, state.LeftButton,

    state.RightButton, … var state = Keyboard.GetState(); state.IsKeyDown(Key.A), … var state = GamePad.GetState(PlayerIndex.One); state.IsButtonDown(Buttons.A), state.ThumbSticks.Left, … var state = TouchPanel.GetState(); state.First().Position, state.First().Id, state.First().Pressure, …
  10. Manage irregularity update draw update draw update draw temps dt

    = 50ms dt = 20ms this.ballPosition += new Vector2(0, (float)gameTime.ElapsedTime.TotalSeconds * Ball.Speed)
  11. Physics origine destination théorique destination obstacle collision AABB Collisions origine

    Moves / Gravity A = M * (0, 9.8) V += A * delta P += 0.5 * V * delta * delta Simulate a world
  12. Entity/Component/System Commonly used (i.e Unity3D) Player int X { get;

    set; } int Y { get; set; } Texture2D Texture { get; set; } float Health { get; set; } void Update(int time); void Draw(); Development pattern Entity int X { get; set; } int Y { get; set; } PositionComponent float Health { get; set; } HealthComponent string Texture { get; set; } Rectangle Source { get; set; } Rectangle Destination{ get; set; } SpriteComponent RenderSystem RulesSystem void Draw(); void Update(int time); Int Identifier { get; set; }
  13. Solutions Tiled + TiledSharp Map tile manager Entitas Entity/Component/System Framework

    Farseer Advanced physics simulation Monocle Engine Engine (by Matt Thorson, Towerfall creator) Frameworks Other platforms Unity Advanced tools (licences) https://github.com/aloisdeniel/awesome-monogame
  14. Start! Different project architecture from UI projects Expand your horizons:

    maths, physics, draw, audio, video, code Start from simple APIs and grow with your own logic Be creative Start simple