14_ Component Game development Component mode

Source: Internet
Author: User

# component different programs need to be kept separate from each other, we don't want AI physics to render sounds, and so on, and so on, like this.// Badif(Collidingwithfloor () && (getrenderstate ()! =INVISIBLE)) {PlaySound (Hit_floor);} "An entity can be isolated across multiple domains, in different domains (componentclass), Entity==container of component (container of components) # # When-to-use1one object uses multiple functions, you want different functions to isolate each other2A class becomes very large and more and more difficult to use3just want to use a function of the base class, you need to make that feature into a build. You don't have to inherit it. ##### problem Building Communication Performance Lower # # # # #classgraphicscomponent{ Public:  voidUpdate (bjorn& Bjorn, graphics&graphics) {Sprite* Sprite = &Spritestand_; if(Bjorn.velocity <0) {Sprite= &Spritewalkleft_; }    Else if(Bjorn.velocity >0) {Sprite= &Spritewalkright_; } Graphics.draw (*Sprite, bjorn.x, BJORN.Y); }Private: Sprite spritestand_;  Sprite Spritewalkleft_; Sprite Spritewalkright_;};classphysicscomponent{};classinputcomponent{}classPlayerinputcomponent: Publicinputcomponent {}classbjorn{ Public:  intVelocity; intx, y; Bjorn (Inputcomponent* Input, Physicscomponent *phys, Graphicscomponent *graph): input_ (Input), Physics_ (Phys), Graphics_ (graph) {}voidUpdate (world& World, graphics&graphics) {Input_->update (* This); Physics_.update (* This, World); Graphics_.update (* This, graphics); }Private: Inputcomponent*Input_;  Physicscomponent Physics_; Graphicscomponent Graphics_;}; Gameobject*Createbjorn () {return NewGameobject (Newplayerinputcomponent (),Newbjornphysicscomponent (),Newbjorngraphicscomponent ());} "' # # # How DoWhat is the communicate with each of the other?1by modifying the state of the container object (the container object is complex, the implementation of the state)2contains direct references (fast, but component instances are coupled)3By sending messages (complex, decoupled, container objects Simple)

14_ Component Game development Component mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.