1. Each object class has a CREATE function of its own public (equivalent to Create_func), and the Init function.
The 2.create function returns its own type, and the Init function is called automatically when the Ceate function is called.
3. If it is a scene object class, also public a static cocos2d::scene* Createscene (), the function, the return value is the scene type
If we're going to present a moving man,
1. Define an object class that inherits from node
2. Define a private Sprite * Sprite Property
3. In the INIT function
Node::init (); Executing the parent class method
Set the size, scale, body size of the node
Size S = size (44, 52);
Setcontentsize (s);
Setphysicsbody (Physicsbody::createbox (s));
Setscale (0.5);
Set the sprite's texture, size, zoom, Position
Sprite = Sprite::create ("S_1.png");
Sprite->setcontentsize (s);
Sprite->setscale (0.5);
Sprite->setposition (22, 52); Set to coincide with node
Bind the Genie to the node, and the genie becomes the child node of the node.
This->addchild (sprite);
Performing animations
Animation * Animation = Animation::create ();
Animation->addspriteframewithfile ("S_1.png");
Animation->addspriteframewithfile ("S_2.png");
Animation->addspriteframewithfile ("S_3.png");
Animation->addspriteframewithfile ("S_4.png");
Animation->addspriteframewithfile ("S_5.png");
Animation->addspriteframewithfile ("S_6.png");
Animation->setdelayperunit (0.1f);
Animation->setrestoreoriginalframe (TRUE);
Animating an action
Auto animate = animate::create (animation);
Sprite->runaction (Repeatforever::create (animate));
Set Rigid Body Properties
Getphysicsbody ()->setrotationenable (false);
Getphysicsbody ()->setcontacttestbitmask (1);
return true;
4. When we create a node, call the initialization method, and return a node that contains the sprite child node that performs the sprite animation, which achieves the effect we want, and we operate on the node, it contains the child node sprite will follow the move
About the relationship of nodes and sprites in cocos2d-x and initialization