1: #ifndef _GAME_LOGO_SCENE
2: #define _GAME_LOGO_SCENE
3:
4: //create by zgh149 2012/07/22
5:
6: #include "cocos2d.h" //include 需要的標頭檔
7: #include "SimpleAudioEngine.h" //include 需要的標頭檔
8:
9: using namespace cocos2d; //使用名稱空間
10: using namespace CocosDenshion; //使用名稱空間
11:
12: class GameLogoScene : public CCLayerColor // 繼承 CCLayerColor 方便使用畫布顏色
13: {
14:
15: public:
16:
17: GameLogoScene(void); //建構子
18:
19: ~GameLogoScene(void); //解構子
20:
21: virtual bool init(); //初始化
22:
23: static CCScene* scene(); //建立scene
24:
25: LAYER_NODE_FUNC(GameLogoScene); //建立layer
26:
27: bool sleep; //控制此流程的進行
28:
29: int gameFlow; //此流程的分類
30:
31: const static int GAMEFLOW1 =1; //流程分類1
32:
33: void Run(float dt);//主要迴圈
34:
35: int GF1Time;//流程分類1的時間控制
36:
37: CCSprite* logoSpr; //使用Logo圖片的CCSprite
38:
39: void logoSprLoad();//logoSpr的資源讀取
40:
41: void logoSprAct();//logoSpr的動作
44:
45:
46:
47: void nextScene(CCNode* sender);//下一個流程
48:
49: void visit();//繪圖
50:
51: protected:
52:
53: private:
54:
55: void ccTouchesEnded(CCSet* touches, CCEvent* event);//控制觸碰
56:
57: };
58:
59: #endif
60:
61: //create by zgh149
1: #include "GameLogoScene.h"
2: #include "HelloWorldScene.h"
3:
4: using namespace cocos2d;
5:
6: GameLogoScene::GameLogoScene(void)
7: {
8:
9: //初始化各項數值
10: this->initWithColor(ccc4(255,255,255,255));
11: sleep = false;
12: gameFlow = 1;
13: GF1Time = 0;
14:
15:
16: logoSprLoad();
17:
18: //加入schedule
19: this->schedule( schedule_selector(GameLogoScene::Run),0.5); //加入schedule
20:
21:
22: }
23:
24: GameLogoScene::~GameLogoScene(void)
25: {
26:
27: }
28:
29:
30: CCScene* GameLogoScene::scene()
31: {
32:
33: CCScene* scene = NULL;
34:
35: do
36: {
37:
38: scene = CCScene::node();
39: CC_BREAK_IF(! scene);
40:
41:
42: GameLogoScene *layer = GameLogoScene::node();
43: CC_BREAK_IF(! layer);
44:
45:
46: scene->addChild(layer);
47: } while (0);
48:
49: return scene;
50: }
51:
52: void GameLogoScene::Run(float dt)
53: {
54:
55: if(gameFlow==GAMEFLOW1)
56: {
57: GF1Time++;
58: logoSprAct();
59:
60: }
61:
62: }
63:
64: void GameLogoScene::ccTouchesEnded(CCSet* touches, CCEvent* event)
65: {
66:
67: CCTouch* touch = (CCTouch*)( touches->anyObject() );
68:
69: CCPoint location = touch->locationInView();
70:
71: location = CCDirector::sharedDirector()->convertToGL(location);
72:
73: CCLog("convertToGLXY x:%f, y:%f", location.x, location.y);
74:
75: }
76:
77:
78: bool GameLogoScene::init()
79: {
80: bool bRet = false;
81: do
82: {
83:
84: this->setTouchEnabled(true);
85:
86: bRet = true;
87:
88: } while (0);
89:
90: return bRet;
91: }
92:
93:
94: void GameLogoScene::logoSprLoad()
95: {
96: logoSpr = CCSprite::spriteWithFile("newlogo.png");
97:
98: logoSpr->setPosition(ccp(480/2,320/2));
99:
100: this->addChild(logoSpr);
101:
102: logoSpr->setVisible(false);//這裡setIsVisible(false)是因為要讓logoSpr一開始能淡入
103: }
104:
105: void GameLogoScene::logoSprAct()
106: {
107: if(GF1Time==1)
108: {
109: logoSpr->runAction(CCSequence::actions(CCShow::action(),CCFadeIn::actionWithDuration(2),NULL));
110: CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("testlogo.mp3",false);}
111: else if(GF1Time==8)
112: {
113: logoSpr->runAction(CCSequence::actions(CCFadeOut::actionWithDuration(2),CCCallFuncN::actionWithTarget(this, callfuncN_selector(GameLogoScene::nextScene)),NULL));
114: }
115: }
116:
117:
118: void GameLogoScene::visit()
119: {
120: if(gameFlow==GAMEFLOW1)
121: {
122: this->draw();
123:
124: logoSpr->visit();
125:
126: }
127:
128: }
129:
130: void GameLogoScene::nextScene(CCNode* sender)
131: {
132:
133: bool tempa = CocosDenshion::SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying();
134:
135: if(tempa)
136: {
137:
138: CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(true);
139: }
140:
141:
142: //到HelloWorld
143: CCScene* hw = HelloWorld::scene();
144:
145: CCScene* TranScene = CCTransitionFade::transitionWithDuration(2, hw ,ccc3(0,0,0));
146:
147: if(TranScene)
148: {
149:
150: CCDirector::sharedDirector()->replaceScene(TranScene);
151: }
152:
153: }