Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: nacltoons/src/gameplay_scene.cc

Issue 12220140: [nacltoons] Cleanup initial game code. (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include "gameplay_scene.h" 4 #include "gameplay_scene.h"
5 #include "physics_layer.h" 5 #include "physics_layer.h"
6 6
7 #define PHYSICS_TAG 101 7 /**
8 #define UI_TAG 102 8 * Tags used by the GameplayScene to identify child elements. Actual values
9 * here are not important as long as they are unique within the scene.
10 */
11 enum ObjectTags {
12 NODE_TAG_PHYSICS = 100,
13 NODE_TAG_UI
14 };
9 15
10 USING_NS_CC; 16 USING_NS_CC;
11 17
12 CCScene* Gameplay::scene() { 18 void GameplayScene::Restart() {
13 return Gameplay::create(); 19 removeChild(getChildByTag(NODE_TAG_PHYSICS));
20 CCLayer* physics = PhysicsLayer::create();
21 addChild(physics, 2, NODE_TAG_PHYSICS);
14 } 22 }
15 23
16 void Gameplay::Restart() { 24 bool GameplayScene::init() {
17 removeChild(getChildByTag(PHYSICS_TAG));
18 CCLayer* physics = PhysicsLayer::create();
19 addChild(physics, 2, PHYSICS_TAG);
20 }
21
22 bool Gameplay::init() {
23 if (!CCScene::init()) 25 if (!CCScene::init())
24 return false; 26 return false;
25 CCLayer* ui = UILayer::create(); 27 CCLayer* ui = UILayer::create();
26 addChild(ui, 1, UI_TAG); 28 addChild(ui, 1, NODE_TAG_UI);
27 29
28 CCLayer* physics = PhysicsLayer::create(); 30 CCLayer* physics = PhysicsLayer::create();
29 addChild(physics, 2, PHYSICS_TAG); 31 addChild(physics, 2, NODE_TAG_PHYSICS);
30 return true; 32 return true;
31 } 33 }
32 34
33 void UILayer::Restart(CCObject* sender) { 35 void UILayer::Restart(CCObject* sender) {
34 CCLog("Restart pressed"); 36 CCLog("Restart pressed");
35 ((Gameplay*)getParent())->Restart(); 37 GameplayScene* scene = static_cast<GameplayScene*>(getParent());
38 scene->Restart();
36 } 39 }
37 40
38 void UILayer::Exit(CCObject* sender) { 41 void UILayer::Exit(CCObject* sender) {
39 CCLog("Exit pressed"); 42 CCLog("Exit pressed");
40 CCDirector::sharedDirector()->popScene(); 43 CCDirector::sharedDirector()->popScene();
41 } 44 }
42 45
43 bool UILayer::init() { 46 bool UILayer::init() {
44 if (!CCLayer::init()) 47 if (!CCLayer::init())
45 return false; 48 return false;
(...skipping 10 matching lines...) Expand all
56 exit_label, this, menu_selector(UILayer::Exit)); 59 exit_label, this, menu_selector(UILayer::Exit));
57 60
58 CCMenu* menu = CCMenu::create(restart, exit, NULL); 61 CCMenu* menu = CCMenu::create(restart, exit, NULL);
59 addChild(menu); 62 addChild(menu);
60 63
61 // Position the menu 64 // Position the menu
62 CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); 65 CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
63 CCSize label_size = restart_label->getContentSize(); 66 CCSize label_size = restart_label->getContentSize();
64 CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); 67 CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
65 menu->alignItemsVertically(); 68 menu->alignItemsVertically();
66 float xpos = origin.x + visibleSize.width*0.05 + label_size.width/2; 69 float xpos = origin.x + visibleSize.width * 0.05 + label_size.width/2;
67 float ypos = origin.y + visibleSize.height*0.95 - label_size.height; 70 float ypos = origin.y + visibleSize.height * 0.95 - label_size.height;
68 menu->setPosition(ccp(xpos, ypos)); 71 menu->setPosition(ccp(xpos, ypos));
69 return true; 72 return true;
70 } 73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698