1 / 18

XNA Basic

XNA Basic. Component And ServiceCollection. GameComponent. Component is a class that developer design for apportion code. There are two type of Component. GameComponent DrawableGameComponent. GameComponent. There are Initialize() ,Update() and Consturctor.

akeem-pitts
Download Presentation

XNA Basic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XNA Basic Component And ServiceCollection

  2. GameComponent • Component is a class that developer design for apportion code. • There are two type of Component. • GameComponent • DrawableGameComponent

  3. GameComponent • There are Initialize(),Update() and Consturctor. • You can add GameComponent in your solution by choosing template from Project menu.

  4. First choose project menu • Second choose Add New Item. • Third choose XNA Game Studio. • Fourth choose game component.

  5. DrawableGameComponent • There are Initialize(),Update(),LoadContent(),Draw() and Consturctor. • Unfortunately, there is not DrawableGameComponent template. • You must write it.

  6. Creating DrawableGameComponent • Choose add class in solution.Assume class’s name is MyClass. class Myclass : Microsoft.Xna.Framework.DrawableGameComponent { }

  7. Its constructor must be public MyClass(GameTime game):base(game) { }

  8. Remain is writing method. Their modifier is public but LoadContent’s modifier is protected. • You must use XNA’s Library too. • It’s called inheritance. We don’t talk detial about it but you can find more information in wiki.

  9. How to add component • You must add component in constructor. Assume my component is Getting_Input. private Getting_Input input; public Game1() { input = new Getting_Input(this); this.Component.Add(input); }

  10. How component work?

  11. How to communicate between components? • The answer is ServiceCollection. • We’ll use ServiceCollection for call property from the other component. • The most service is interface. We’ll don’t talk detail about it but you can find more information in wiki.

  12. How to create service • Assume there are component Graphic, component Display. • Component Display want model from component Graphic. • Therefor, I’ll create interface IGraphic for communicating with Display.

  13. Pseudo Code interface IGraphic { model GetModeling { get;} }; class Graphic: Microsoft.Xna.Framework.GameComponent, IGraphic {

  14. Model player; Model IGraphic.GetModeling { get { return player; } } public Graphic(GameTime game):base(game) { game.Service.Add(typeof(IGraphic),this); }

  15. How to Display using service? Class Display : Microsoft.Xna.Framework.DrawableGameComponent { IGraphic graphic; Model player;

  16. public Display(GameTime game):base(game) { graphic = (IGraphic)game.Service.GetService(typeof(Graphic)); player = graphic.GetModeling; }

  17. Let’s practice more • Let improve program changeWithSound by component and service.

  18. Vibration Keyboard Display GamePad sound This is how class work. SetVibration SetSpeedChangeColor SetSpeedChangeColor GetSound

More Related