Chromium Code Reviews| Index: nacltoons/src/GameplayScene.cc |
| diff --git a/nacltoons/src/GameplayScene.cc b/nacltoons/src/GameplayScene.cc |
| index f6f45e40483befb31b0758554ee17dfa6c0daf3d..48761d783adcc04734d6529ece055adead9e4238 100644 |
| --- a/nacltoons/src/GameplayScene.cc |
| +++ b/nacltoons/src/GameplayScene.cc |
| @@ -1,46 +1,74 @@ |
| -// Copyright (c) 2013 The Native Client Authors. All rights reserved. |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| #include "GameplayScene.h" |
| +#include "PhysicsLayer.h" |
| + |
| +#define PHYSICS_TAG 101 |
|
noelallen1
2013/02/12 23:35:52
Are these IDs global? Meaning we don't when them
|
| +#define UI_TAG 102 |
| USING_NS_CC; |
| -Gameplay::~Gameplay() |
| -{ |
| +CCScene* Gameplay::scene() { |
| + return Gameplay::create(); |
|
noelallen1
2013/02/12 23:35:52
Is there a reason that "scene" in this one returns
|
| } |
| -Gameplay::Gameplay() |
| -{ |
| +void Gameplay::restart() { |
| + removeChild(getChildByTag(PHYSICS_TAG)); |
| + CCLayer* physics = PhysicsLayer::create(); |
| + addChild(physics, 2, PHYSICS_TAG); |
| } |
| -CCScene* Gameplay::scene() |
| -{ |
| - CCScene* scene = CCScene::create(); |
| - Gameplay* layer = Gameplay::create(); |
| - scene->addChild(layer); |
| - return scene; |
| -} |
| -bool Gameplay::init() |
| -{ |
| - CCLayerColor::initWithColor(ccc4(0,0x8F,0xD8,0xD8)); |
| - setTouchEnabled(true); |
| - schedule(schedule_selector(Gameplay::updateGame)); |
| +bool Gameplay::init() { |
| + if (!CCScene::init()) |
| + return false; |
| + CCLayer* ui = UILayer::create(); |
| + addChild(ui, 1, UI_TAG); |
| + |
| + CCLayer* physics = PhysicsLayer::create(); |
| + addChild(physics, 2, PHYSICS_TAG); |
| return true; |
| } |
| -void Gameplay::ccTouchesEnded(CCSet* touches, CCEvent* event) |
| -{ |
| - for (CCSetIterator it = touches->begin(); it != touches->end(); it++) |
| - { |
| - CCTouch* touch = (CCTouch*)(*it); |
| - if (!touch) |
| - break; |
| - |
| - CCPoint location = touch->getLocation(); |
| - CCLog("touch x:%f, y:%f", location.x, location.y); |
| - } |
| + |
| +void UILayer::restart(CCObject* sender) { |
| + CCLog("restart pressed"); |
| + ((Gameplay*)getParent())->restart(); |
|
noelallen1
2013/02/12 23:35:52
static_cast<Gameplay*>(getParent())->
|
| +} |
| + |
| + |
| +void UILayer::exit(CCObject* sender) { |
| + CCLog("exit pressed"); |
| + CCDirector::sharedDirector()->popScene(); |
| } |
| -void Gameplay::updateGame(float dt) { |
| + |
| +bool UILayer::init() { |
| + if (!CCLayer::init()) |
| + return false; |
| + setTouchEnabled(true); |
| + |
| + // Create the menu. |
| + CCLabelTTF* restart_label = CCLabelTTF::create("Restart", "Arial.ttf", 24); |
| + CCLabelTTF* exit_label = CCLabelTTF::create("Exit", "Arial.ttf", 24); |
| + |
| + CCMenuItemLabel* restart = CCMenuItemLabel::create( |
| + restart_label, this, menu_selector(UILayer::restart)); |
| + |
| + CCMenuItemLabel* exit = CCMenuItemLabel::create( |
| + exit_label, this, menu_selector(UILayer::exit)); |
| + |
| + CCMenu* menu = CCMenu::create(restart, exit, NULL); |
| + addChild(menu); |
| + |
| + // Position the menu |
| + CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); |
| + CCSize label_size = restart_label->getContentSize(); |
| + CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); |
| + menu->alignItemsVertically(); |
| + float xpos = origin.x + visibleSize.width*0.05 + label_size.width/2; |
| + float ypos = origin.y + visibleSize.height*0.95 - label_size.height; |
| + menu->setPosition(ccp(xpos, ypos)); |
| + return true; |
| } |