Basic Cocos2d-x Concepts
This chapter assumes you've just gotten started with Cocos2d-x, and are ready to start working on the game of your dreams. Don't worry, it will be fun!
Let's get started!
Cocos2d-x is a cross-platform game engine. A game engine is a piece of software that provides common functionality that all games need. You might have heard this referred to as an API or framework but in this guide, we'll be calling it a 'game engine'.
Game engines include many components that when used together will help speed up development time, and often perform better than homemade engines. A game engine is usually comprised of some or all of the following components: a renderer, 2d/3d graphics, collision detection, a physics engine, sound, controller support, animations and more. To be sure we are all on the same page, we should review common game terminology.
Director: You can think of the
Directorthe same way you think about a movie director. The
Directorcontrols every aspect of your game. What is shown on the screen, what sounds are played, what happens with player input, and much more.
Sceneis a container that holds
Nodesand other objects that your game needs. A
Sceneis responsible for running game logic and rendering the content on a per-frame basis.
Spriteis a 2D image that can be animated or transformed by changing its properties. Most all games will have multiple
Spriteobjects ranging from the hero, an enemy or a boss.
Scene Graph: The scene graph is a data structure that arranges a graphical scene, into a tree structure. This tree structure is what is used to render objects onscreen in a specific order.
Renderer: In an oversimplified definition the renderer is responsible for taking everything you want on the screen and getting it there, technically. No need to delve into this further at this time.
Events: What do you do when the player moves around? What about touch events or keyboard input? These all trigger events that can be acted upon as needed.
Audio: Perhaps your game has background music and or sound effects. There needs to be a way to hear them!
UI Components: Things like
ScrollView, etc. Items that help you layout your game and related interfaces.
Physics Engine: The physics engine is responsible for emulating the laws of physics realistically within the application.
Game engines usually support multiple platforms thus making it easy to develop your game and then deploy it to multiple platforms without much overhead at all. Since Cocos2d-x is a game engine, it provides a simplified API for developing cross-platform mobile and desktop games. By encapsulating the power inside an easy to use API, you can focus on developing your games and worry less about the implementation of the technical underpinnings. Cocos2d-x will take care of as much or as little of the heavy lifting as you want.
objects and much more. Everything you need to create your games are included.