facebook twitter hatena line email

「Cocos2dx/method」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(サンプルコード(staticメソッド))
 
(同じ利用者による、間の1版が非表示)
行1: 行1:
==サンプルコード(staticメソッド)==
+
==サンプルコード==
HelloWorld::costom1()のstaticメソッドを追加する場合
+
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* costom1();
+
     const char* custom1();
 
     CREATE_FUNC(HelloWorld);
 
     CREATE_FUNC(HelloWorld);
 
  };
 
  };
  
 
-Classes/HelloWorldScene.cpp
 
-Classes/HelloWorldScene.cpp
  const char* HelloWorld::costom1()
+
  const char* HelloWorld::custom1()
 
  {
 
  {
       const char *hoge = "costom1";
+
       const char *hoge = "custom1";
 
       return hoge;
 
       return hoge;
 
  }
 
  }
行21: 行21:
 
カスタム関数呼び出し(適当な場所で)
 
カスタム関数呼び出し(適当な場所で)
 
-Classes/HelloWorldScene.cpp
 
-Classes/HelloWorldScene.cpp
  const char *b = HelloWorld::costom1();
+
  const char *b = HelloWorld::custom1();
 
  log("%s", b);
 
  log("%s", b);

2017年3月2日 (木) 17:19時点における最新版

サンプルコード

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);