「Cocos2dx/method」の版間の差分
提供: 初心者エンジニアの簡易メモ
| 行1: | 行1: | ||
==サンプルコード(staticメソッド)== | ==サンプルコード(staticメソッド)== | ||
| − | HelloWorld:: | + | HelloWorld::custom1()のstaticメソッドを追加する場合 |
-Classes/HelloWorldScene.h | -Classes/HelloWorldScene.h | ||
| 行8: | 行8: | ||
static cocos2d::Scene* createScene(); | static cocos2d::Scene* createScene(); | ||
virtual bool init(); | virtual bool init(); | ||
| − | const char* | + | const char* custom1(); |
CREATE_FUNC(HelloWorld); | CREATE_FUNC(HelloWorld); | ||
}; | }; | ||
-Classes/HelloWorldScene.cpp | -Classes/HelloWorldScene.cpp | ||
| − | const char* HelloWorld:: | + | const char* HelloWorld::custom1() |
{ | { | ||
| − | const char *hoge = " | + | const char *hoge = "custom1"; |
return hoge; | return hoge; | ||
} | } | ||
| 行21: | 行21: | ||
カスタム関数呼び出し(適当な場所で) | カスタム関数呼び出し(適当な場所で) | ||
-Classes/HelloWorldScene.cpp | -Classes/HelloWorldScene.cpp | ||
| − | const char *b = HelloWorld:: | + | const char *b = HelloWorld::custom1(); |
log("%s", b); | log("%s", b); | ||
2017年3月2日 (木) 17:16時点における版
サンプルコード(staticメソッド)
HelloWorld::custom1()のstaticメソッドを追加する場合
-Classes/HelloWorldScene.h
class HelloWorld : public cocos2d::Layer
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
const char* custom1();
CREATE_FUNC(HelloWorld);
};
-Classes/HelloWorldScene.cpp
const char* HelloWorld::custom1()
{
const char *hoge = "custom1";
return hoge;
}
カスタム関数呼び出し(適当な場所で) -Classes/HelloWorldScene.cpp
const char *b = HelloWorld::custom1();
log("%s", b);
