Four basic concepts required for getting started with cocos2d

Source: Internet
Author: User
Tags home screen

It's not too early today. Continue the translation tomorrow.

 

Cocos2d basic concepts Basic concepts of cocos2d

The following are some basic concepts of cocos2d:ProgramWhat must be mastered:

    • Scenes
    • Director
    • Layers
    • Sprites
Scenes scenario

 

The scenario is implemented by a scene object, more or less, and is part of an independent program stream. Some may call it screens screen or stages stage. Your program can have many scenarios, but only one can be activated within a given period of time.

For example, you may have a game in the following scenarios.Intro,Menu,Level 1,Cutscene 1,Level 2,Winning cutscene,Losing cutscene,High scores Screen

You can define any of them as independent applications. Each of the following scenarios is connected by a line.

 

 

A cocos2d consists of one or more layers (the layers are implemented using layer objects) and they are stacked together. The layer presents and represents a scenario. The simplest operation is to create a layered scenario.

The set of some scenario classes is called transitions and implemented through the transitionscene object. It allows you to roll back between two scenarios. For example, fade out/in, which slides from a plane.

Because the scenario is a subclass of cocosnode, they can be changed manually or using actions.

 

Director instructor

 

A mentor can be a component that can know the forward and backward scenes. The instructor is a shared, single-piece object. He knows which scenario should be active. He can process a series of scenes in the stack, like scene CILS, pause a scene and, save it, and then go to other scenarios and roll back to the beginning .. When a layer needs to be pushed, replaced, or at the end of the current scenario, this mentor is truly able to change the scenario. The instructor is also responsible for the initialization of the home screen.

 

Layers Layer

 

The layer has the big printable area of the screen and he knows how to draw it. It can be partially transparent (there is a hole or a general transparency in the whole/whole), allowing you to see other layers under it. The layer defines the presentation and presentation, so you spend more time programming on the Child classes of the layer.

 

 

You can define the handlers of an event on the layer. The event is extended from start to end on the layer until a layer captures the event and accepts it.

Although many programs require custom layer classes, cocos2d provides a very good pre-defined layer library.

For example, a simple menu layer uses menu, a color layer, and a colorlayer to define a multi-layer.

A layer can contain sprite objects, label objects, and even other layer objects as events.

Because the layer is also a subclass of cocosnode, you can change it manually or by using action. See actions for more detail about actions.

 

Sprites genie

 

The implementation of the genie is through the sprite class. They can have many sub-elves. When a parent genie changes, its sub-genie will also change.

Because the sub-classes of the genie are cocosnode, they can be changed manually or using actions. Pay attention to action for more details.

====

In this case, the source file sprite.png is usually used. There is a lot of elements to be used, that is, the sprite.png source file. We can lock the area of a rectangle through its coordinates and length and width. After reading the image, you can further read the genie at the specified position in the image. It is not as good as painting a bird in my (100,100, 20, 20) region. This can be used as an genie, increase bounce and wait. Or it can change over time.

 

 

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.