AppDelegate::applicationDidFinishLaunching()函數里
把
glview = GLViewImpl::createWithRect("NAME", Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
改成
glview = GLViewImpl::createWithFullScreen("NAME");
就可以全屏
2018年5月10日 星期四
2017年12月20日 星期三
1220 VS2013 使用ramDisk
1. 下載軟體 SoftPerfect RAMDISK 3.4.8
4.0 版取消免費版, home license開始要收費download 3.4.8免費版要快手,不知majorgeeks幾時推送4.0
http://www.majorgeeks.com/files/details/softperfect_ram_disk.html
3.4.8 另一個download mirror
http://filehippo.com/download_softperfect-ram-disk/71289/
2. 建立RAMDDISK !並且掛載至系統上 範例教學
http://wuhsiublog.blogspot.tw/2015/07/softperfect-ram-disk.html
3. 利用軟體建立 windows 系統暫儲檔
記得暫存檔路徑一定要有目錄
例如 R:\temp
2017年12月8日 星期五
1208 Cocos2dx - Sprite 更換圖片的方法
http://cocos2dx.logdown.com/tags/%E6%9B%B4%E6%8F%9B%E5%9C%96%E7%89%87
自己程式用到的方式有
刪除舊檔
TextureCache::getInstance()->removeTextureForKey(avatarFileName); //檔名加路徑
//增加至CACHE中
SpriteFrameCache* cache = SpriteFrameCache::getInstance();
auto pNewSprite = Sprite::create(avatarFileName); //開檔載入
if (pNewSprite != nullptr)
{
auto pFrame = pNewSprite->getSpriteFrame();
cache->addSpriteFrame(pFrame, stInfo.FileName);
}
新檔案載入
//將大頭照載入cache 中
SpriteFrameCache* cache = SpriteFrameCache::getInstance();
auto pFrame = cache->getSpriteFrameByName(avatar);
if (pFrame == nullptr)
{ //檢查是否已經在cahce
auto pNewSprite = Sprite::create(fileName); //開檔載入
if (pNewSprite != nullptr)
{
TextureCache::getInstance()->removeTextureForKey(avatar);
//cache->addSpriteFramesWithFile(fileName);
pFrame = pNewSprite->getSpriteFrame();
cache->addSpriteFrame(pFrame, avatar);
}
}
if (pFrame != nullptr)
{
logFile(LOG_DEBUG, "Image name %s (%p)", avatar.c_str(), pFrame);
spritePersion->setSpriteFrame(pFrame);
return true;
}
自己程式用到的方式有
刪除舊檔
TextureCache::getInstance()->removeTextureForKey(avatarFileName); //檔名加路徑
//增加至CACHE中
SpriteFrameCache* cache = SpriteFrameCache::getInstance();
auto pNewSprite = Sprite::create(avatarFileName); //開檔載入
if (pNewSprite != nullptr)
{
auto pFrame = pNewSprite->getSpriteFrame();
cache->addSpriteFrame(pFrame, stInfo.FileName);
}
新檔案載入
//將大頭照載入cache 中
SpriteFrameCache* cache = SpriteFrameCache::getInstance();
auto pFrame = cache->getSpriteFrameByName(avatar);
if (pFrame == nullptr)
{ //檢查是否已經在cahce
auto pNewSprite = Sprite::create(fileName); //開檔載入
if (pNewSprite != nullptr)
{
TextureCache::getInstance()->removeTextureForKey(avatar);
//cache->addSpriteFramesWithFile(fileName);
pFrame = pNewSprite->getSpriteFrame();
cache->addSpriteFrame(pFrame, avatar);
}
}
if (pFrame != nullptr)
{
logFile(LOG_DEBUG, "Image name %s (%p)", avatar.c_str(), pFrame);
spritePersion->setSpriteFrame(pFrame);
return true;
}
參考文件資料
網路上常見的兩種方法
基本上網路上的做法為更換掉 Sprite 中的Texture, 或者將 SpriteFrame 中的DisplayFrame 換掉。
但必須得說, 這些做法都相對麻煩, 而且就效率來說與新建一張Sprite的成本, 差距不大。
但必須得說, 這些做法都相對麻煩, 而且就效率來說與新建一張Sprite的成本, 差距不大。
於是有些時候我會採用下面的做法。
新建一張Sprite, 將裡面的Texture貼回需要替換的Sprite
Sprite *newSprite = Sprite::create("newImage.png");
oldSprite->setTexture(newSprite->getTexture());
- 限制: 更換Sprite 的 Texture時, 需要注意如果是更新有相同名稱的圖檔時, 需要先將舊有的 Cache清除, 不然使用相同名稱時, 會取成舊有Cache中的 Texture檔
Director::getInstance()->getTextureCache()->removeTextureForKey("photo.png");
筆者: 好處是不需要額外處理 Texture中的許多細節, 缺點則是多了一個 create 的呼叫, 在有許多圖檔建立時, App會變得很慢, 所以這種作法請千萬不要在需要一次更換很多圖檔時使用。
2017年8月23日 星期三
0823 cocos2d-x 手機連線 相關資料
http://qiankanglai.me/2014/12/02/cocos2dx-assetsmanager/
基於cocos2d-x 3.x版本修改的Assets Manager,加幾行代碼就能實現斷線續傳功能…so easy
|
然後在下面設置curl的地方
|
2017年8月18日 星期五
0818 cocos2d-x 如何取得手機型號跟其他資訊(android)
//範例程式碼
proj.android-studio\app\src\org\cocos2dx\cpp\AppActivity.java
增加
import android.os.Build; // 主機版名稱 String board = Build.BOARD;
public class AppActivity extends Cocos2dxActivity {
private static String deviceInfo; //回傳手機型號跟系統版本
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
deviceInfo = this.getDeviceInfo();
}
public static String findDeviceInfo() {
return deviceInfo;
}
/**
* Get Android node and Android version
* */
public String getDeviceInfo()
{
TelephonyManager manager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String model = Build.MODEL; //手機型號
String phoneNum = manager.getLine1Number();//本機電話號碼
String sdkVersion = Build.VERSION.SDK;//SDK版本號
String osVersion = Build.VERSION.RELEASE;//Firmware/OS 版本號
return "Phone:" +model + " OS:" + osVersion;
}
}
///參考文章
http://www.cocos2dev.com/?p=208
proj.android-studio\app\src\org\cocos2dx\cpp\AppActivity.java
增加
import android.os.Build; // 主機版名稱 String board = Build.BOARD;
public class AppActivity extends Cocos2dxActivity {
private static String deviceInfo; //回傳手機型號跟系統版本
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
deviceInfo = this.getDeviceInfo();
}
public static String findDeviceInfo() {
return deviceInfo;
}
/**
* Get Android node and Android version
* */
public String getDeviceInfo()
{
TelephonyManager manager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String model = Build.MODEL; //手機型號
String phoneNum = manager.getLine1Number();//本機電話號碼
String sdkVersion = Build.VERSION.SDK;//SDK版本號
String osVersion = Build.VERSION.RELEASE;//Firmware/OS 版本號
return "Phone:" +model + " OS:" + osVersion;
}
}
///參考文章
http://www.cocos2dev.com/?p=208
今天要獲取用戶反饋意見,我默認將用戶的手機號碼上傳了,結果發現並不是所有的手機能拿到本機號碼。找了下發現原是用戶的SIM卡沒有寫入本機號碼導致的。
Android獲取本機號碼:
TelephonyManager phoneMgr = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String phoneNum = phoneMgr.getLine1Number();
AndroidManifest.xml中添加權限:
<uses-permission android:name=」android.permission.READ_PHONE_STATE」 />
剛才也說了,手機號碼不是所有的都能獲取。只是有一部分可以拿到。這個是由於移動運營商沒有把手機號碼的數據寫入到sim卡中。
手機型號 Build.MODEL
String MODEL The end-user-visible name for the end product.
sdk版本 Build.VERSION.SDK
String SDK This constant is deprecated. Use SDK_INT to easily get this as an integer.
frimware版本號(系統版本號) Build.VERSION.RELEASE
String RELEASE The user-visible version string.
獲取手機的其他信息:
private void getPhoneStatus(){
TelephonyManager phoneMgr=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String model = Build.MODEL; //手機型號
String phoneNum = phoneMgr.getLine1Number();//本機電話號碼
String sdkVersion = Build.VERSION.SDK;//SDK版本號
String osVersion = Build.VERSION.RELEASE;//Firmware/OS 版本號
}
Build中包括 硬件廠商,硬件編號,序列號等很多信息。調用方法也很簡單,和上面類似的。
下面是Google提供的參考表:
| String | BOARD | The name of the underlying board, like 「goldfish」. |
| String | BOOTLOADER | The system bootloader version number. |
| String | BRAND | The brand (e.g., carrier) the software is customized for, if any. |
| String | CPU_ABI | The name of the instruction set (CPU type + ABI convention) of native code. |
| String | CPU_ABI2 | The name of the second instruction set (CPU type + ABI convention) of native code. |
| String | DEVICE | The name of the industrial design. |
| String | DISPLAY | A build ID string meant for displaying to the user |
| String | FINGERPRINT | A string that uniquely identifies this build. |
| String | HARDWARE | The name of the hardware (from the kernel command line or /proc). |
| String | HOST | |
| String | ID | Either a changelist number, or a label like 「M4-rc20」. |
| String | MANUFACTURER | The manufacturer of the product/hardware. |
| String | MODEL | The end-user-visible name for the end product. |
| String | PRODUCT | The name of the overall product. |
| String | RADIO | The radio firmware version number. |
| String | SERIAL | A hardware serial number, if available. |
| String | TAGS | Comma-separated tags describing the build, like 「unsigned,debug」. |
| long | TIME | |
| String | TYPE | The type of build, like 「user」 or 「eng」. |
| String | UNKNOWN | Value used for when a build property is unknown. |
| String | USER |
2017年8月16日 星期三
0816 cocos2d-x 開啟網址
http://jslim.net/blog/2014/09/24/cocos2d-x-v3-open-url/
You can invoke
Application::getInstance()->openURL("your url"). e.g.
MyScene.cpp
|
|
2017年7月5日 星期三
0714 cocos2d-x 3.15 如何增加複製到系統剪貼簿
參考 http://blog.csdn.net/mydreamremindme/article/details/49229205
1.1 程式碼增加
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
bool PageMain::copyToClipboard(const std::string &content)
{
return copyToClipboardJNI(content.c_str());
}
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
bool PageMain::copyToClipboard(const std::string &content)
{
if (OpenClipboard(NULL))
{
EmptyClipboard();
HGLOBAL clipbuffer;
char* buffer;
const char* str = content.c_str();
const int length = strlen(str);
clipbuffer = GlobalAlloc(GMEM_DDESHARE, length + 1);
buffer = (char*)GlobalLock(clipbuffer);
strcpy(buffer, str);
GlobalUnlock(clipbuffer);
SetClipboardData(CF_TEXT, clipbuffer);
CloseClipboard();
return true;
}
return false;
}
#endif
1.2 增加對應的函數 讓C呼叫
cocos2d-x\cocos\platform\android\jni\Java_org_cocos2dx_lib_Cocos2dxHelper.cpp
extern bool copyToClipboardJNI(const char* content)
{
JniMethodInfo t;
bool ret = false;
if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/Cocos2dxHelper", "copyToClipboard", "(Ljava/lang/String;)Z"))
{
jstring stringArg = t.env->NewStringUTF(content);
ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID,stringArg);
t.env->DeleteLocalRef(t.classID);
t.env->DeleteLocalRef(stringArg);
}
return ret;
}
1.3 撰寫JAVA 的程式碼
cocos2d-x\cocos\platform\android\java\src\org\cocos2dx\lib\Cocos2dxHelper.java
1.3.1 宣告
在 public class Cocos2dxHelper { 增加一行
//example in line 94
private static android.content.ClipboardManager clipboardmanager = null;
1.3.2 設定對應函數
在 public static void init(final Activity activity) { 增加一行
//example in line 167 Cocos2dxBitmap.setContext(activity); 之上
Cocos2dxHelper.clipboardmanager = (android.content.ClipboardManager)activity.getSystemService(Context.CLIPBOARD_SERVICE);//獲取剪貼板服務
1.3.3 JAVA與C的接口
在 public static void init(final Activity activity) 函數之後 增加下列函數
//example in line 195 找地方寫函數就對了
public static boolean copyToClipboard(String content){
clipboardmanager.setText(content);
System.out.println("come here");
return true;
}
1.1 程式碼增加
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
bool PageMain::copyToClipboard(const std::string &content)
{
return copyToClipboardJNI(content.c_str());
}
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
bool PageMain::copyToClipboard(const std::string &content)
{
if (OpenClipboard(NULL))
{
EmptyClipboard();
HGLOBAL clipbuffer;
char* buffer;
const char* str = content.c_str();
const int length = strlen(str);
clipbuffer = GlobalAlloc(GMEM_DDESHARE, length + 1);
buffer = (char*)GlobalLock(clipbuffer);
strcpy(buffer, str);
GlobalUnlock(clipbuffer);
SetClipboardData(CF_TEXT, clipbuffer);
CloseClipboard();
return true;
}
return false;
}
#endif
1.2 增加對應的函數 讓C呼叫
cocos2d-x\cocos\platform\android\jni\Java_org_cocos2dx_lib_Cocos2dxHelper.cpp
extern bool copyToClipboardJNI(const char* content)
{
JniMethodInfo t;
bool ret = false;
if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/Cocos2dxHelper", "copyToClipboard", "(Ljava/lang/String;)Z"))
{
jstring stringArg = t.env->NewStringUTF(content);
ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID,stringArg);
t.env->DeleteLocalRef(t.classID);
t.env->DeleteLocalRef(stringArg);
}
return ret;
}
1.3 撰寫JAVA 的程式碼
cocos2d-x\cocos\platform\android\java\src\org\cocos2dx\lib\Cocos2dxHelper.java
1.3.1 宣告
在 public class Cocos2dxHelper { 增加一行
//example in line 94
private static android.content.ClipboardManager clipboardmanager = null;
1.3.2 設定對應函數
在 public static void init(final Activity activity) { 增加一行
//example in line 167 Cocos2dxBitmap.setContext(activity); 之上
Cocos2dxHelper.clipboardmanager = (android.content.ClipboardManager)activity.getSystemService(Context.CLIPBOARD_SERVICE);//獲取剪貼板服務
1.3.3 JAVA與C的接口
在 public static void init(final Activity activity) 函數之後 增加下列函數
//example in line 195 找地方寫函數就對了
public static boolean copyToClipboard(String content){
clipboardmanager.setText(content);
System.out.println("come here");
return true;
}
2017年6月3日 星期六
0603 cocos2dx 3.0 之 用std::bind替換CC_CALLBACK_N
http://www.cnblogs.com/fzll/p/3954604.html
比如action的回調 ,CC_CALLBACK_0
或者action帶一個參數的回調:CC_CALLBACK_1,在這裡,pSender就是動作的執行者sprite2
或者按鈕的回調函數:CC_CALLBACK_1
或者touch函數:CC_CALLBACK_2
回來了。讓我先回口血,恩,接著寫...
一般來說:
CallFunc用於 不帶參數的,
CallFuncN 用於創建 帶一個Node節點參數的,Node*節點參數是動作的執行者
CCCallFuncND 比CallFuncN多了一個參數,可以是任意類型的參數 void *,用法看下面
其實上面調用帶兩個參數的函數的這句代碼:
我們還可以這樣子寫:
其實上面的CC_CALLBACK_0 啊CC_CALLBACK_1 啊,都可以類似這麼寫,很多種寫法,原因是因為CC_CALLBACK_N有一個可變參數宏##__VA_ARGS__。
是不是看到了std::bind、##__VA_ARGS__、std::placeholders::_1等等,這些都是神馬玩意,
##__VA_ARGS__是可變參數宏
std::placeholders::_1是參數佔位符,表示第一個參數,以此類推
那std::bind是神馬,不急我們先看一段代碼
然後看一下輸出結果:
再解釋一下:
比如我們要替換CC_CALLBACK_0
再比如調用兩個參數的...
在cocos2dx 3.0 版本中,回調函數基本上由4個CC_CALLBACK_N 函數代替,N代表回調函數的參數個數
1.先讓我們來看看這些CC_CALLBACK_N怎麼用
比如action的回調 ,CC_CALLBACK_0
- auto animation = Animation::create();
- auto animate = Animate::create(animation);
- CallFunc* animateDone = CallFunc::create(CC_CALLBACK_0(PlaneLayer::removePlane,this));
- auto sequence = Sequence::create(animate,animateDone,NULL);
- sprite1->runAction(sequence);
- void PlaneLayer::removePlane(){
- //.....
- }
- auto actionMove = MoveTo::create(randomDuration, Point(0, 0));
- auto actionDone = CallFuncN::create(CC_CALLBACK_1(EnemyLayer::enemy1MoveFinished,this));
- auto sequence = Sequence::create(actionMove,actionDone,NULL);
- sprite2->runAction(sequence);
- void EnemyLayer::enemy1MoveFinished(Node* pSender){
- Sprite* sprite2 = (Sprite*)pSender;
- }
或者按鈕的回調函數:CC_CALLBACK_1
- auto pauseNormal = Sprite::create("game_pause_nor.png");
- auto pausePressed = Sprite::create("game_pause_pressed.png");
- auto menuItem = MenuItemSprite::create(pauseNormal,pausePressed,NULL,CC_CALLBACK_1(ControlLayer::menuPauseCallback,this));
- menuItem->setPosition(Point::ZERO);
- auto menuPause = Menu::create(menuItem,NULL);
- menuPause->setPosition(Point::ZERO);
- //回調函數
- void ControlLayer::menuPauseCallback(Object* pSender)
- {
- //....
- }
或者touch函數:CC_CALLBACK_2
- //單點觸摸
- virtual bool onTouchBegan(Touch *touch, Event *unused_event);
- virtual void onTouchMoved(Touch *touch, Event *unused_event);
- virtual void onTouchEnded(Touch *touch, Event *unused_event);
- virtual void onTouchCancelled(Touch *touch, Event *unused_event);
- auto dispatcher = Director::getInstance()->getEventDispatcher();
- auto listener = EventListenerTouchOneByOne::create();
- listener->onTouchBegan = CC_CALLBACK_2(GameLayer::onTouchBegan,this);
- listener->onTouchMoved = CC_CALLBACK_2(GameLayer::onTouchMoved,this);
- listener->onTouchEnded = CC_CALLBACK_2(GameLayer::onTouchEnded,this);
- listener->setSwallowTouches(true);//不向下傳遞觸摸
- dispatcher->addEventListenerWithSceneGraphPriority(listener,this);
2.發現了上面的CallFunc和CallFucnN了沒有,恩,先去LOL一把再接著寫。。
回來了。讓我先回口血,恩,接著寫...
一般來說:
CallFunc用於 不帶參數的,
CallFuncN 用於創建 帶一個Node節點參數的,Node*節點參數是動作的執行者
CCCallFuncND 比CallFuncN多了一個參數,可以是任意類型的參數 void *,用法看下面
- auto animation = AnimationCache::getInstance()->animationByName("Enemy1Blowup");
- auto animate = Animate::create(animation);
- CCCallFuncND* animateDone = CCCallFuncND::create(this,callfuncND_selector(EnemyLayer::removeEnemy1),(void*)enemy1);
- auto sequence = Sequence::create(animate, animateDone,NULL);
- Sprite* m_sprite = enemy1->getSprite();
- m_sprite ->runAction(sequence);
- void EnemyLayer::removeEnemy1(Node* pTarget, void* data){
- Sprite* m_sprite = (Sprite*) pTarget; //node節點為動作的執行者
- Enemy* enemy1 = (Enemy*)data; //我們傳的自定義數據enemy1
- //...
- }
- CCCallFuncND* animateDone = CCCallFuncND::create(this,callfuncND_selector(EnemyLayer::removeEnemy1),(void*)enemy1);
- //寫法1
- CCCallFuncN* animateDone = CCCallFuncN::create(CC_CALLBACK_1(EnemyLayer::removeEnemy1,this,enemy1));
- //寫法2
- CCCallFunc* animateDone = CCCallFunc::create(CC_CALLBACK_0(EnemyLayer::removeEnemy1,this,enemy1->getSprite(),enemy1));
- //寫法3,用std::bind
- CCCallFuncN* animateDone = CCCallFuncN::create(std::bind(&EnemyLayer::removeEnemy1,this,enemy1->getSprite(),enemy1));
恩,是不是有點亂,記不住沒關係,我也經常沒記住,我們來具體看一下CC_CALLBACK_N到底是神馬玩意
- // new callbacks based on C++11
- #define CC_CALLBACK_0(__selector__,__target__, ...) std::bind(&__selector__,__target__, ##__VA_ARGS__)
- #define CC_CALLBACK_1(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, ##__VA_ARGS__)
- #define CC_CALLBACK_2(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, ##__VA_ARGS__)
- #define CC_CALLBACK_3(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3 ##__VA_ARGS__)
是不是看到了std::bind、##__VA_ARGS__、std::placeholders::_1等等,這些都是神馬玩意,
先解釋一下:
std::placeholders::_1是參數佔位符,表示第一個參數,以此類推
那std::bind是神馬,不急我們先看一段代碼
- #include <iostream>
- #include <functional>
- using namespace std;
- typedef std::function<void ()> fp;
- void g_fun()
- {
- cout<<"g_fun()"<<endl;
- }
- class A
- {
- public:
- static void A_fun_static()
- {
- cout<<"A_fun_static()"<<endl;
- }
- void A_fun()
- {
- cout<<"A_fun()"<<endl;
- }
- void A_fun_int(int i)
- {
- cout<<"A_fun_int() "<<i<<endl;
- }
- void A_fun_int_double(int i,int p)
- {
- cout<<"A_fun_int_double ()"<<i<<","<<p<<endl;
- }
- //非靜態類成員,因為含有this指針,所以需要使用bind
- void init()
- {
- //綁定不帶參數的函數
- fp fp1=std::bind(&A::A_fun,this);
- fp1();
- }
- void init2()
- {
- typedef std::function<void (int)> fpi;
- //綁定帶一個參數的函數
- fpi f=std::bind(&A::A_fun_int,this,std::placeholders::_1);//參數要使用佔位符 std::placeholders::_1表示第一個參數
- f(5);
- }
- void init3(){
- typedef std::function<void (int,double)> fpid;
- //綁定帶兩個參數的函數
- fpid f=std::bind(&A::A_fun_int_double,this,std::placeholders::_1,std::placeholders::_2);
- f(5,10);
- }
- };
- int main()
- {
- //綁定到全局函數
- fp f2=fp(&g_fun);
- f2();
- //綁定到類靜態成員函數
- fp f1=fp(&A::A_fun_static);
- f1();
- A().init();
- A().init2();
- A().init3();
- return 0;
- }
然後看一下輸出結果:
- g_fun()
- A_fun_static()
- A_fun()
- A_fun_int() 5
- A_fun_int_double ()5,10
再解釋一下:
std::function --> 綁定到全局函數/類靜態成員函數(類靜態成員函數與全局函數沒有區別)
std::bind --> 綁定到類的非靜態成員函數
std::bind --> 綁定到類的非靜態成員函數
到這裡是不是有豁然開朗的感覺呢,哈哈,知道了bind函數怎麼用,然後我們就可以使用std::bind替換CC_CALLBACK_N寫法了
3.使用std:bind函數替換CC_CALLBACK_N:
比如我們要替換CC_CALLBACK_0
- auto animation = Animation::create();
- auto animate = Animate::create(animation);
- //CallFunc* animateDone = CallFunc::create(CC_CALLBACK_0(PlaneLayer::removePlane,this));
- CallFunc* animateDone = CallFunc::create(std::bind(&PlaneLayer::removePlane,this));//替換
- auto sequence = Sequence::create(animate,animateDone,NULL);
- sprite1->runAction(sequence);
- void PlaneLayer::removePlane(){
- //.....
- }
比如我們要替換帶一個參數的CC_CALLBACK_1
- auto actionMove = MoveTo::create(randomDuration, Point(0, 0));
- //auto actionDone = CallFuncN::create(CC_CALLBACK_1(EnemyLayer::enemy1MoveFinished,this));
- auto actionDone = CallFuncN::create(std::bind(&EnemyLayer::enemy1MoveFinished,this,enemy1));//替換
- auto sequence = Sequence::create(actionMove,actionDone,NULL);
- sprite2->runAction(sequence);
- void EnemyLayer::enemy1MoveFinished(Node* pSender){
- Sprite* sprite2 = (Sprite*)pSender;
- }
- auto animation = AnimationCache::getInstance()->animationByName("Enemy1Blowup");
- auto animate = Animate::create(animation);
- //CCCallFuncND* animateDone = CCCallFuncND::create(this,callfuncND_selector(EnemyLayer::removeEnemy1),(void*)enemy1);
- CCCallFuncN* animateDone = CCCallFuncN::create(std::bind(&EnemyLayer::removeEnemy1,this,enemy1->getSprite(),enemy1));//替換
- auto sequence = Sequence::create(animate, animateDone,NULL);
- Sprite* m_sprite = enemy1->getSprite();
- m_sprite ->runAction(sequence);
- void EnemyLayer::removeEnemy1(Node* pTarget, void* data){
- Sprite* m_sprite = (Sprite*) pTarget; //node節點為動作的執行者
- Enemy* enemy1 = (Enemy*)data; //我們傳的自定義數據enemy1
- //...
- }
哈哈,這下子很清楚了吧。。再也不會混亂了。。
訂閱:
文章 (Atom)
cocos2dx-lua 建立滑鼠監聽
重要關鍵字 EVENT_MOUSE_SCROLL addEventListenerWithSceneGraphPriority if IsPc() then --建立滑鼠監聽 local listener = cc.EventListenerMouse...
-
https://changeyu.wordpress.com/2015/03/25/%E4%BD%A0%E7%9A%84macbook-air%E7%B8%BD%E6%98%AF%E7%A9%BA%E9%96%93%E4%B8%8D%E5%A4%A0%E5%97%8E%EF%BC...
-
http://kirkhsutw.blogspot.tw/2015/05/ios-ad-hoc.html [iOS] 第一次 Ad Hoc 就上手 之前都沒想過要用這個 Ad Hoc,這一次是因為用到了Dropbox API,在Submit被re...
-
答案:直接回傳 std :: vector < MyObj > myFunction (); C++: What is the best method to return a vector of objects from a function...