Skip to content

Instantly share code, notes, and snippets.

@prototechno
Created February 19, 2013 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prototechno/4990091 to your computer and use it in GitHub Desktop.
Save prototechno/4990091 to your computer and use it in GitHub Desktop.
Cocos2d-xでシングルトンによる画面間データ連携 ref: http://qiita.com/items/5eca8aab0dbd3f33273c
//
// GameManager.cpp
// SingletonTEST
//
// Created by prototechno on 2013/02/20.
//
//
#include "SimpleAudioEngine.h"
#include "GameManager.h"
using namespace cocos2d;
using namespace CocosDenshion;
//All static variables need to be defined in the .cpp file
//I've added this following line to fix the problem
GameManager* GameManager::m_mySingleton = NULL;
GameManager::GameManager()
{
}
GameManager* GameManager::sharedGameManager()
{
//If the singleton has no instance yet, create one
if(NULL == m_mySingleton)
{
//Create an instance to the singleton
m_mySingleton = new GameManager();
}
//Return the singleton object
return m_mySingleton;
}
//
// GameManager.h
// SingletonTEST
//
// Created by prototechno on 2013/02/20.
//
//
#ifndef __SingletonTEST__GameManager__
#define __SingletonTEST__GameManager__
typedef enum{
GameModeMenu ,
GameModeNagasa ,
GameModeKasa ,
}GameMode;
#include "cocos2d.h"
class GameManager
{
private:
GameManager();
static GameManager* m_mySingleton;
public:
static GameManager* sharedGameManager();
GameMode gameMode;
int count;
float gameTime;
};
#endif /* defined(__SingletonTEST__GameManager__) */
#include "GameManager.h"
void Play5::countTimer(float time)
{
GameManager::sharedGameManager()->gameTime += time;
//時間を表示する
CCString* timeString = CCString::createWithFormat("%8.0f秒", GameManager::sharedGameManager()->gameTime);
CCLabelTTF* timerLabel = (CCLabelTTF*)this->getChildByTag(kTagTimerLabel);
timerLabel->setString(timeString->getCString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment