[Cocos2d-x for WP8 study notes] some of the basic concepts, to establish their o

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Process control: elements of the game scene is set relatively unchanged, the game switches in the scene is process control.

The scene, and the elves: they are game elements at different levels. Usually, the scene contains layer, layer contains the elves, scene and layer is a container for other game elements, while the wizard is show game player graphics.

Nodes and render tree: it can show the game elements are nodes in the render tree. Cocos2d-x by traversing the render tree drawing pictures of the game. The scene, or Elf as the render tree node, we are not on their layers make rigid restrictions, such as developers can add a layer to the elves.

Action: action on the elements of the game, the game elements specified motion mode. Animation is a special action on a fairy.

Similar to the Objective-C code style: use the initialization method or the factory method to create an object, use the accessor methods to simulate the properties. Cocos2d-x provides Objective-C style container CCArray and CCDictionary.

Memory management: similar to Objective-C's reference count memory management mechanism, while providing the object semi automatic automatic recycling pool, realize flexible memory management.

Life cycle: AppDelegate is responsible for the control of the game's life cycle.

First create a MainScene class, and copy HelloWorld into the required header files, the addition of the two image project, the main interface and the main interface on the button background.

CCDirector: director class, control the flow of a game

The first scene created in AppDelegate into newly created MainScene CCScene *pScene = MainScene:: Scene();

The CCScene: scene, CCLayer: container layer, the container of the contents of the

Some essential methods in MainScene, such as the initialization and so on

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
bool MainScene::init()
{
bool bRet = false;
do
{
  if ( !CCLayer::init() )
  {
   break;
  }
  CCSize size = CCDirector::sharedDirector()->getWinSize();
 
  CCSprite* mainback = CCSprite::create("Background/main_back.jpg");
  mainback->setPosition(ccp(size.width * 0.5, size.height * 0.5));
  this->addChild(mainback);
  CCSprite* btback1 = CCSprite::create("Background/main_button_back.png");
  btback1->setPosition( ccp(size.width * 0.5, size.height * 0.5) );
  CCLabelTTF* pLabelStart = CCLabelTTF::create("Start", "Consolas", 28);
  pLabelStart->setPosition( ccp(75, 20) );
  pLabelStart->setColor(ccc3(0, 0,0));
  this->addChild(btback1,1);
  btback1->addChild(pLabelStart, 5);
  CCSprite* btback2 = CCSprite::create("Background/main_button_back.png");
  btback2->setPosition( ccp(size.width * 0.5, size.height * 0.5-70) );
  CCLabelTTF* pLabelExit = CCLabelTTF::create("Exit", "Consolas", 28);
  pLabelExit->setPosition( ccp(75, 20) );
  pLabelExit->setColor(ccc3(0, 0, 0));
  btback2->addChild(pLabelExit, 6);
  this->addChild(btback2,2);
  setTouchEnabled(true);
  bRet = true;
} while (0);
return bRet;
}

In this code, respectively, add a background, two button background, two paragraphs.

CCSprite: The elves, represents the minimum visible units in the game.

Add the picture above is a wizard.

CCSprite and CCLayer are inherited from CCNode, and addChild is in the CCNode method, so it can be added to the layer or Elf elf in.

The following code in the MainScene layer in response to a touch event, to obtain the coordinates, and perform the exit operation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void MainScene::ccTouchesBegan(CCSet* touches, CCEvent *event)
{
if(touches->count()==1)
{
  CCTouch* touch = dynamic_cast<CCTouch*>(touches->anyObject());
  CCPoint position = touch->getLocationInView();
  position=CCDirector::sharedDirector()->convertToGL(position);
  CCLOG("X = %f Y = %f",position.x,position.y);
  if(position.x>166&&position.x<313&&position.y>306&&position.y<353)
  {
   CCDirector::sharedDirector()->end();
  }
}
}

In this paper, the fixed link: reprint please indicate


In this paper, the fixed link: reprint please indicate

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Polly at December 20, 2013 - 2:46 AM