Skip to content

Commit

Permalink
About+Position
Browse files Browse the repository at this point in the history
aboutLayer,position confirm.
  • Loading branch information
dawnfan committed Aug 6, 2014
1 parent 14aac34 commit d19f8fe
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 6 deletions.
60 changes: 60 additions & 0 deletions About.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "About.h"
#include "HelloWorldScene.h"
USING_NS_CC;

Scene* GameAbout::createScene()
{
auto scene = Scene::create();
auto layer = GameAbout::create();
scene->addChild(layer);
return scene;
}


bool GameAbout::init()
{

if ( !Layer::init() )
{
return false;
}

Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
//背景
auto sprite = Sprite::create("about/aboutui.png");
sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
this->addChild(sprite);

//响应键盘消息
auto keyListener = EventListenerKeyboard::create();
keyListener->onKeyReleased = CC_CALLBACK_2(GameAbout::onKeyReleased, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this);

//可以触控
this->setTouchEnabled(true);
auto touchListener = EventListenerTouchOneByOne::create();
touchListener->onTouchBegan = CC_CALLBACK_2(GameAbout::onTouchBegan, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
return true;
}

//返回主界面
void GameAbout::onKeyReleased(EventKeyboard::KeyCode keycode,Event* event)
{
if(keycode == EventKeyboard::KeyCode::KEY_BACKSPACE)
{
Scene* newScene = HelloWorld::createScene();
HelloWorld* layer = HelloWorld::create();
newScene->addChild(layer);
Director::sharedDirector()->pushScene(newScene);
}
}

//响应触摸
bool GameAbout::onTouchBegan(Touch *touch, Event *unused)
{
CCLOG("here");
Director::sharedDirector()->replaceScene(HelloWorld::createScene());
return false;
}
21 changes: 21 additions & 0 deletions About.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef __GameAbout_H__
#define __GameAbout_H__

#include "cocos2d.h"

USING_NS_CC;


class GameAbout : public Layer
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
//响应安卓返回键
virtual void onKeyReleased(EventKeyboard::KeyCode keycode,Event* event)override;
//点击函数
virtual bool onTouchBegan(Touch *touch, Event *unused) override;
CREATE_FUNC(GameAbout);
};

#endif // __GameAbout_H__
15 changes: 11 additions & 4 deletions HelloWorldScene.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "HelloWorldScene.h"
#include "About.h"

#define userDefault UserDefault::getInstance()

Expand Down Expand Up @@ -37,13 +38,13 @@ bool HelloWorld::init()
"menu/play1.png",
"menu/play2.png",
CC_CALLBACK_1(HelloWorld::startGame, this));
item_Adventure->setPosition(ccp(0,50));
item_Adventure->setPosition(ccp(80,-135));
//关于界面
auto item_About= MenuItemImage::create(
"menu/about1.png",
"menu/about2.png",
CC_CALLBACK_1(HelloWorld::startGame, this));
item_About->setPosition(ccp(120,-200));
CC_CALLBACK_1(HelloWorld::aboutFunc, this));
item_About->setPosition(ccp(-110,-200));
//播放背景音乐
if(!userDefault->getBoolForKey("Music")){
userDefault->getBoolForKey("Music",true);
Expand Down Expand Up @@ -78,7 +79,7 @@ bool HelloWorld::init()
}
//int selectId = AudioState? 0 : 1;
item_Voice->setSelectedIndex(selectId);
item_Voice->setPosition(ccp(-120,-200));
item_Voice->setPosition(ccp(-30,-155));

CCMenu* menu = CCMenu::create(item_Adventure,item_Voice,item_About,NULL);
this->addChild(menu);
Expand All @@ -95,6 +96,12 @@ bool HelloWorld::init()

return true;
}
//关于按键的回调函数
void HelloWorld::aboutFunc(Ref* pSender)
{
CCLOG("about_Menu item clicked");
Director::sharedDirector()->replaceScene(GameAbout::createScene());
}
//开始游戏按键的回调函数
void HelloWorld::startGame(cocos2d::Ref* pSender)
{
Expand Down
3 changes: 2 additions & 1 deletion HelloWorldScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class HelloWorld : public cocos2d::Layer
virtual bool init();
void menuCloseCallback(cocos2d::Ref* pSender);
CREATE_FUNC(HelloWorld);

//关于按键的回调函数
void aboutFunc(cocos2d::Ref* pSender);
//开始按键的回调函数
void startGame(cocos2d::Ref* pSender);
//声音按键的回调函数
Expand Down
2 changes: 1 addition & 1 deletion test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using namespace std;

void func1()
void func2()
{
return ;

Expand Down

0 comments on commit d19f8fe

Please sign in to comment.