This version seems to be available on the Internet, but people do it. I think it is still different if I try it again.
MoonWarrior cocos2d-x is bound with JS to achieve, the effect of writing is quite good, although the sparrow is small and dirty, changed to C ++, both familiar with the cocos2d-x, also reviewed the previous learning js
After the win32 environment is set up, create a cocos2d-x project, this write Menu
Creates a class that inherits from CCLayer,
Two lines of code are required.
[Cpp]
Virtual bool init ();
CREATE_FUNC (LoadingScene );
Virtual bool init ();
CREATE_FUNC (LoadingScene );
CREATE_FUNC is a macro definition, that is, the create method is implemented, and the create method will call the init method to initialize
[Cpp]
Bool bRet = false;
Do {
//////////////////////////////////////// //////////////////////////////////
// Super init first
//////////////////////////////////////// //////////////////////////////////
CC_BREAK_IF (! CCLayer: init ());
CCSize winSize = CCDirector: sharedDirector ()-> getWinSize ();
Bool bRet = false;
Do {
//////////////////////////////////////// //////////////////////////////////
// Super init first
//////////////////////////////////////// //////////////////////////////////
CC_BREAK_IF (! CCLayer: init ());
CCSize winSize = CCDirector: sharedDirector ()-> getWinSize (); [cpp] view plaincopyprint?
// Adds two images.
CCSprite * background = CCSprite: create ("loading.png ");
Background-> setAnchorPoint (ccp (0, 0 ));
This-> addChild (background, 0, 1 );
CCSprite * logo = CCSprite: create ("logo.png ");
Logo-> setAnchorPoint (ccp (0, 0 ));
Logo-> setPosition (ccp (0,250 ));
This-> addChild (logo, 10, 1 );
// Adds two images.
CCSprite * background = CCSprite: create ("loading.png ");
Background-> setAnchorPoint (ccp (0, 0 ));
This-> addChild (background, 0, 1 );
CCSprite * logo = CCSprite: create ("logo.png ");
Logo-> setAnchorPoint (ccp (0, 0 ));
Logo-> setPosition (ccp (0,250 ));
This-> addChild (logo, 10, 1 );
[Cpp]
// When three menus are in, the menus are also stateful and can be generated directly.
CCSprite * newGameNormal = CCSprite: create ("menu.png", CCRectMake (0, 0,126, 33); // cc. sprite. create (s_menu, cc. rect (0, 0,126, 33 ));
CCSprite * newGameSelected = CCSprite: create ("menu.png", CCRectMake (0, 33,126, 33 ));
CCSprite * newGameDisabled = CCSprite: create ("menu.png", CCRectMake (0, 33*2,126, 33 ));
CCSprite * gameSettingsNormal = CCSprite: create ("menu.png", CCRectMake (126, 0,126, 33 ));
CCSprite * gameSettingsSelected = CCSprite: create ("menu.png", CCRectMake (126, 33,126, 33 ));
CCSprite * gameSettingsDisabled = CCSprite: create ("menu.png", CCRectMake (126, 33*2,126, 33 ));
CCSprite * aboutNormal = CCSprite: create ("menu.png", CCRectMake (252, 0,126, 33 ));
CCSprite * aboutSelected = CCSprite: create ("menu.png", CCRectMake (252, 33,126, 33 ));
CCSprite * aboutDisabled = CCSprite: create ("menu.png", CCRectMake (252, 33*2,126, 33 ));
CCMenuItem * newGame = CCMenuItemSprite: create (newGameNormal, newGameSelected, newGameDisabled, this,
Menu_selector (LoadingSense: newGameCallback ));
CCMenuItem * gameSettings = CCMenuItemSprite: create (gameSettingsNormal, gameSettingsSelected, gameSettingsDisabled, this,
Menu_selector (LoadingSense: onSettings ));
CCMenuItem * about = CCMenuItemSprite: create (aboutNormal, aboutSelected, aboutDisabled, this,
Menu_selector (LoadingSense: onAbout); // cc. MenuItemSprite. create (aboutNormal, aboutSelected, aboutDisabled, this, this. onAbout );
CCMenu * menu = CCMenu: create (newGame, gameSettings, about, NULL );
// CCMenu: create (newGame, gameSettings, about );
Menu-> alignItemsVerticallyWithPadding (10 );
This-> addChild (menu, 1, 2 );
Menu-> setPosition (ccp (winSize. width/2, winSize. height/2-80 ));
// When three menus are in, the menus are also stateful and can be generated directly.
CCSprite * newGameNormal = CCSprite: create ("menu.png", CCRectMake (0, 0,126, 33); // cc. sprite. create (s_menu, cc. rect (0, 0,126, 33 ));
CCSprite * newGameSelected = CCSprite: create ("menu.png", CCRectMake (0, 33,126, 33 ));
CCSprite * newGameDisabled = CCSprite: create ("menu.png", CCRectMake (0, 33*2,126, 33 ));
CCSprite * gameSettingsNormal = CCSprite: create ("menu.png", CCRectMake (126, 0,126, 33 ));
CCSprite * gameSettingsSelected = CCSprite: create ("menu.png", CCRectMake (126, 33,126, 33 ));
CCSprite * gameSettingsDisabled = CCSprite: create ("menu.png", CCRectMake (126, 33*2,126, 33 ));
CCSprite * aboutNormal = CCSprite: create ("menu.png", CCRectMake (252, 0,126, 33 ));
CCSprite * aboutSelected = CCSprite: create ("menu.png", CCRectMake (252, 33,126, 33 ));
CCSprite * aboutDisabled = CCSprite: create ("menu.png", CCRectMake (252, 33*2,126, 33 ));
CCMenuItem * newGame = CCMenuItemSprite: create (newGameNormal, newGameSelected, newGameDisabled, this,
Menu_selector (LoadingSense: newGameCallback ));
CCMenuItem * gameSettings = CCMenuItemSprite: create (gameSettingsNormal, gameSettingsSelected, gameSettingsDisabled, this,
Menu_selector (LoadingSense: onSettings ));
CCMenuItem * about = CCMenuItemSprite: create (aboutNormal, aboutSelected, aboutDisabled, this,
Menu_selector (LoadingSense: onAbout); // cc. MenuItemSprite. create (aboutNormal, aboutSelected, aboutDisabled, this, this. onAbout );
CCMenu * menu = CCMenu: create (newGame, gameSettings, about, NULL );
// CCMenu: create (newGame, gameSettings, about );
Menu-> alignItemsVerticallyWithPadding (10 );
This-> addChild (menu, 1, 2 );
Menu-> setPosition (ccp (winSize. width/2, winSize. height/2-80 ));
[Cpp]
// This schedule is used to let the plane with the background fly to the top, and then fly from below
// This-> schedule
This-> schedule (schedule_selector (LoadingSense: update), 0.1 );
CCTexture2D * tmp = CCTextureCache: sharedTextureCache ()-> addImage ("ship01.png ");
M_pShip = CCSprite: createWithTexture (tmp, CCRectMake (0, 45, 60, 38 ));
This-> addChild (m_pShip, 0, 4 );
CCPoint pos = ccp (float) (rand () % 10)/10) * winSize. width, 0 );
// Let the plane fly from the bottom to the top
M_pShip-> setPosition (pos );
// M_pShip-> setPosition (ccp (100,100 ));
M_pShip-> runAction (CCMoveBy: create (2, ccp (float) (rand () % 10)/10) * winSize. width, pos. y + winSize. height + 100 )));
// M_pShip-> runAction (CCMoveBy: create (2, CPC (200,200 )));
// This schedule is used to let the plane with the background fly to the top, and then fly from below
// This-> schedule
This-> schedule (schedule_selector (LoadingSense: update), 0.1 );
CCTexture2D * tmp = CCTextureCache: sharedTextureCache ()-> addImage ("ship01.png ");
M_pShip = CCSprite: createWithTexture (tmp, CCRectMake (0, 45, 60, 38 ));
This-> addChild (m_pShip, 0, 4 );
CCPoint pos = ccp (float) (rand () % 10)/10) * winSize. width, 0 );
// Let the plane fly from the bottom to the top
M_pShip-> setPosition (pos );
// M_pShip-> setPosition (ccp (100,100 ));
M_pShip-> runAction (CCMoveBy: create (2, ccp (float) (rand () % 10)/10) * winSize. width, pos. y + winSize. height + 100 )));
// M_pShip-> runAction (CCMoveBy: create (2, ccp (200,200); [cpp] view plaincopyprint?
<SPAN style = "FONT-SIZE: 12px"> // play music
If (true ){
CocosDenshion: SimpleAudioEngine: sharedEngine ()-> setBackgroundMusicVolume (0.7 );
CocosDenshion: SimpleAudioEngine: sharedEngine ()-> playBackgroundMusic (s_mainMainMusic, true );
}
BRet = true;
} While (0 );
Return bRet;
</SPAN>
// Play music
If (true ){
CocosDenshion: SimpleAudioEngine: sharedEngine ()-> setBackgroundMusicVolume (0.7 );
CocosDenshion: SimpleAudioEngine: sharedEngine ()-> playBackgroundMusic (s_mainMainMusic, true );
}
BRet = true;
} While (0 );
Return bRet;
Go to an article about the anchor
Basically, there is now an animation effect. After clicking new game, there will be an effect to see how this effect works.
[Cpp]
CCSprite * flare = CCSprite: create ("flare.jpg ");
CcBlendFunc ccBF = {GL_SRC_ALPHA, GL_ONE };
CCSprite * flare = CCSprite: create ("flare.jpg ");
CcBlendFunc ccBF = {GL_SRC_ALPHA, GL_ONE}; [cpp] view plaincopyprint?
<SPAN style = "FONT-SIZE: 12px"> flare-> setBlendFunc (ccBF );
Parent-> addChild (flare, 10 );
Flare-> setOpacity (0 );
Flare-& gt; setPosition (ccp (-30,297 ));
Flare-> setRotation (-120 );
Flare-> setScale (0.2 );
CCFadeTo * opacityAnim = CCFadeTo: create (0.5, 255 );
CCFadeTo * opacDim = CCFadeTo: create (1, 0 );
CCScaleBy * biggeAnim = CCScaleBy: create (0.7, 1.2, 1.2 );
CCEaseSineOut * biggerout = CCEaseSineOut: create (biggeAnim );
CCMoveBy * moveAnim = CCMoveBy: create (0.5, ccp (328, 0 ));
CCEaseSineOut * easeMove = CCEaseSineOut: create (moveAnim );
CCRotateBy * rotateAnim = CCRotateBy: create (2.5, 90 );
CCEaseExponentialOut * rotateEase = CCEaseExponentialOut: create (rotateAnim );
CCScaleTo * bigger = CCScaleTo: create (0.5, 1 );
CCCallFunc * onComplete = CCCallFunc: create (target, callback );
CCCallFunc * killflare = CCCallFunc: create (target, callfunc_selector (LoadingSense: killFlare ));
Flare-> runAction (CCSequence: create (opacityAnim, bigger.pdf, opacDim, killflare, onComplete, NULL ));
Flare-> runAction (easeMove );
Flare-> runAction (rotateEase );
Flare-> runAction (bigger );
</SPAN>
Flare-> setBlendFunc (ccBF );
Parent-> addChild (flare, 10 );
Flare-> setOpacity (0 );
Flare-& gt; setPosition (ccp (-30,297 ));
Flare-> setRotation (-120 );
Flare-> setScale (0.2 );
CCFadeTo * opacityAnim = CCFadeTo: create (0.5, 255 );
CCFadeTo * opacDim = CCFadeTo: create (1, 0 );
CCScaleBy * biggeAnim = CCScaleBy: create (0.7, 1.2, 1.2 );
CCEaseSineOut * biggerout = CCEaseSineOut: create (biggeAnim );
CCMoveBy * moveAnim = CCMoveBy: create (0.5, ccp (328, 0 ));
CCEaseSineOut * easeMove = CCEaseSineOut: create (moveAnim );
CCRotateBy * rotateAnim = CCRotateBy: create (2.5, 90 );
CCEaseExponentialOut * rotateEase = CCEaseExponentialOut: create (rotateAnim );
CCScaleTo * bigger = CCScaleTo: create (0.5, 1 );
CCCallFunc * onComplete = CCCallFunc: create (target, callback );
CCCallFunc * killflare = CCCallFunc: create (target, callfunc_selector (LoadingSense: killFlare ));
Flare-> runAction (CCSequence: create (opacityAnim, bigger.pdf, opacDim, killflare, onComplete, NULL ));
Flare-> runAction (easeMove );
Flare-> runAction (rotateEase );
Flare-> runAction (bigger );