Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Cocos2d Game Development Blueprints

You're reading from   Cocos2d Game Development Blueprints Design, develop, and create your own successful iOS games using the Cocos2d game engine

Arrow left icon
Product type Paperback
Published in Jan 2015
Publisher
ISBN-13 9781783987887
Length 440 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Jorge Jord√°n Jorge Jord√°n
Author Profile Icon Jorge Jord√°n
Jorge Jord√°n
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Sprites, Sounds, and Collisions 2. Explosions and UFOs FREE CHAPTER 3. Your First Online Game 4. Beat All Your Enemies Up 5. Scenes at the Highest Level 6. Physics Behavior 7. Jump and Run 8. Defend the Tower 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.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image