Cocos2dx/property
提供: 初心者エンジニアの簡易メモ
サンプルコード
cpp側にのみ記述、h側には記述不要。
#include "HelloWorldScene.h"
USING_NS_CC;
const char* mName = "hoge_property"; // 通常property
static const char* mNameStatic = "hoge_property_static"; // static_property
Scene* HelloWorld::createScene()
{
auto scene = Scene::create();
auto layer = HelloWorld::create();
scene->addChild(layer);
return scene;
}
bool HelloWorld::init()
{
mName = "hoge_property2";
log("%s", mName);
mNameStatic = "hoge_property_static2";
log("%s", mNameStatic);
// 略
}
セッターゲッターでpropertyにアクセス
propertyはpublicにできない? -SampleModule.h
- ifndef Helloworld_SampleModule_h
- define Helloworld_SampleModule_h
class SampleModule
{
public:
static void setName(const char*);
static const char* getName();
};
- endif
-SampleModule.cpp
#include "SampleModule.h"
USING_NS_CC;
static const char* mNameStatic = "hoge_property_static";
void SampleModule::setName(const char* name)
{
mNameStatic = name;
}
const char* SampleModule::getName()
{
return mNameStatic;
}
-HelloWorldScene.cpp
bool HelloWorld::init()
{
NativeLauncher::setName("hoge_setget");
log("%s", NativeLauncher::getName()); // hoge_setget
// 略
}
