參考 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;
}
訂閱:
文章 (Atom)
cocos2dx-lua 建立滑鼠監聽
重要關鍵字 EVENT_MOUSE_SCROLL addEventListenerWithSceneGraphPriority if IsPc() then --建立滑鼠監聽 local listener = cc.EventListenerMouse...
-
http://blog.csdn.net/teng_ontheway/article/details/26078869 遊戲中經常會用到一些變換: 遊戲中武器和角色在一個layer上,為了效率,會考慮將bullet, effect和 PhysicsParticle分別放...
-
AppDelegate::applicationDidFinishLaunching()函數里 把 glview = GLViewImpl::createWithRect("NAME", Rect(0, 0, designResolutionSize.widt...
-
https://cocosgamestory.wordpress.com/2015/08/12/%E6%9B%B4%E6%8F%9B%E6%96%B0%E7%9A%84appicon/ 使用心得: 透過網站 取得各種SIZE的ICON,在手動更換目錄下的ICON即可 (coco...