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

Monogame Introduction (ENG)

27704a8146ddc18a760150aba2f9e92c?s=47 Aloïs Deniel
September 07, 2016

Monogame Introduction (ENG)

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

27704a8146ddc18a760150aba2f9e92c?s=128

Aloïs Deniel

September 07, 2016
Tweet

More Decks by Aloïs Deniel

Other Decks in Programming

Transcript

  1. MONOGAME Cross-Platform Native Mobile Development in Paris Aloïs DENIEL @aloisdeniel

    07/09/2016
  2. Technical Leader Xamarin My job Aloïs DENIEL alois.deniel@orange.com @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
  3. 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.
  4. Renowned productions Cross-platform games Towerfall FEZ Bastion Infinite Flight Transistor

    Mercenary Kings
  5. Outils et APIs MONOGAME Xamarin / .NET C# Visual Studio

    Xamarin Studio Monogame Content Pipeline PNG WAV MP3 Font
  6. Main cycle Draw Update Initialize LoadContent Real time rendering Inputs

  7. 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); }
  8. None
  9. ContentPipeline Packaging resources

  10. ContentManager Resource container this.Content.RootDirectory = "Content"; protected override void LoadContent()

    { this.ballTexture = this.Content.Load<Texture2D>("assets"); }
  11. None
  12. protected override void LoadContent() { this.texture = Content.Load<Texture2D>("assets"); } Load

    textures From images
  13. 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
  14. Tiles 1 2 3 1 1 1 2 3 3

    Image portions
  15. 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
  16. Animations t=1 t=2 Changing the source dynamically

  17. Camera Ecran Ecran Rotation Translation Zoom

  18. Camera Ecran Ecran Translation 1 Matrix.CreateTranslation(-100,0,0) Translation

  19. Camera Ecran Ecran Translation 2 Matrix.CreateRotationZ(0.05f) Rotation

  20. Camera Ecran Ecran Zoom 2 Matrix.CreateScale(2) Zoom

  21. 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
  22. this.font = Content.Load<SpriteFont>("font"); Polices de caractères Chargement et affichage spriteBatch.DrawString(this.font,"Hello

    World", new Vector2(20,20));
  23. None
  24. MediaPlayer MediaPlayer.Play(song); MediaPlayer.IsRepeating = true; MediaPlayer.Pause(); Musics this.song = Content.Load<Song>("music");

  25. SoundEffect Sounds this.jumpSound.Play(volume,pitch,pan); this.jumpSound = Content.Load<SoundEffect>("jump");

  26. None
  27. 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, …
  28. Manage irregularity update draw update draw update draw temps dt

    = 50ms dt = 20ms this.ballPosition += new Vector2(0, (float)gameTime.ElapsedTime.TotalSeconds * Ball.Speed)
  29. 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
  30. 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; }
  31. http://goo.gl/oeYUyq

  32. None
  33. 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
  34. 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
  35. Thanks Contact me @aloisdeniel alois.deniel@orange.com