Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Cocos2d Game Development Blueprints
  • Table Of Contents Toc
Cocos2d Game Development Blueprints

Cocos2d Game Development Blueprints

By : Jorge Jordán
5 (2)
close
close
Cocos2d Game Development Blueprints

Cocos2d Game Development Blueprints

5 (2)
By: Jorge Jordán

Overview of this book

Whether you are a passionate gamer, like developing, or are just curious about game development, this book is for you. The book has been written to teach 2D game development to app developers and to teach Objective-C to game developers, as learning Cocos2d is the perfect step for both roles.
Table of Contents (10 chapters)
close
close
9
Index

CCNode

Sometimes called a scene hierarchy, the scene graph is a hierarchy of every Cocos2d node that's currently active.

We call them nodes because they inherit from the class CCNode (http://www.cocos2d-swift.org/docs/api/Classes/CCNode.html), the base class to display objects in Cocos2d.

The usual picture of a scene graph is a root CCScene node with several node children such as CCButton, CCSprite, and CCLabelTTF. For example, the graph of an initial Cocos2d project looks like the following:

CCNode

One important feature of CCNode in the current Cocos2d version is that it inherits from CCResponder, which allows all the objects derived from CCNode to handle user touches and mouse events.

I said that CCNode is the base class to display objects, but what are the classes that inherit from it? You can see the CCNode class hierarchy in the following graph:

CCNode

As I mentioned in the previous section, scenes will no longer derive from CCLayer (as has been the case in previous Cocos2d versions) and if you look closely at the CCNode class hierarchy in the preceding graph, you will realize that this class doesn't appear in it. It means that CCLayer has been deprecated and doesn't exist anymore, due to the fact that CCNode now supports user interaction, which was basically the purpose of CCLayer besides grouping nodes, a task perfectly accomplished by CCScene.

One important CCNode property is positionType. This property makes reference to how a node's position will be interpreted and can take three different values:

  • CCPositionUnitPoints: The node's position will be set in points. This is the default value.
  • CCPositionUnitScaled: The node's position will be scaled, for example, to be supported by iPhone and iPad.
  • CCPositionUnitNormalized: The node's position will be relative to its parent node.

Another important property is contentSizeType, which means that the size of the node's content will be interpreted in different ways depending on its value:

  • CCSizeUnitPoints: This is the default value and means that the size will be set in points
  • CCSizeUnitScaled: The node's content size will be scaled by the factor indicated
  • CCSizeUnitNormalized: The size will be relative to its parent container size
  • CCSizeUnitInset: The size of the node's content will be the same as its parent node, but it will be inset by the indicated value
  • CCSizeUnitInsetScaled: The size of the node's content will be the same as its parent node, but it will be inset by the indicated value that will be multiplied by a scale factor

This class is one of the most important because our games will have plenty of classes that derive from it, such as CCButton (inherits from CCControl), CCParallaxNode, CCParticleSystemBase, CCSprite, CCLabelTTF (inherits from CCSprite), CCLabelBMFont (inherits from CCSpriteBatchNode), or CCScene.

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Cocos2d Game Development Blueprints
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon