`
renzhe20092584
  • 浏览: 10478 次
  • 性别: Icon_minigender_1
最近访客 更多访客>>
社区版块
存档分类
最新评论

cocos2dx android

 
阅读更多

1.cocos2dx从android的sd卡里读取图片

http://cocos2d.cocoachina.com/bbs/forum.php?mod=viewthread&tid=1252

CCSprite* sprite = CCSprite::spriteWithFile("sd开路径")

 

获取sd卡路径

java代码

public static String getSDPath() {
		File file = Environment.getExternalStorageDirectory();
		String sdPath = file.getAbsolutePath();
		String picPath = sdPath + "/my";

		String test = picPath + "/ss.png";
		File fileM = new File(test);
		if (!fileM.exists())
			System.out.println(" data/adc.pngadc.png adc.png  not exits  ");

		return picPath;
	}

 

C++

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)

#include<jni.h>

#include"platform/android/jni/JniHelper.h"

#include<android/log.h>

#endif

        string myP = getSDPath();
	myP.append("/ss.png");
	CCSprite* sprite = CCSprite::spriteWithFile(myP.c_str());
	sprite->setPosition(ccp(size.width/2, size.height/2));
	this->addChild(sprite, 2);

string HelloWorld::getSDPath()

{

bool isHave;

const char* msgRet;

JniMethodInfo minfo;

isHave = JniHelper::getStaticMethodInfo(minfo, "yy/media/MediaActivity",

"getSDPath", "()Ljava/lang/String;");

if (isHave)

{

jobject obj = minfo.env->CallStaticObjectMethod(minfo.classID,

minfo.methodID);

jstring jRet = (jstring) obj;

msgRet = (minfo.env)->GetStringUTFChars(jRet, NULL);

}

returnstring(msgRet);

}

 

 2.cocos2dx调用android控件

C++调用的java类 CJ

privatestatic Handler mHandler;

public static void init(Handler handler) {

ShareWeibo.mHandler = handler;

}

public static String cppCallJava() {

Message msg = mHandler.obtainMessage();

msg.what = WeiboTest2.SHOW_DIALOG;

msg.sendToTarget();

 

return "2";

}

 

接受消息的java类 JJ

publicstaticfinalintSHOW_DIALOG = 0x0001;

CJ.init(mHandler); //告诉CJ发送消息给我这个类

public Handler mHandler = new Handler() {

@Override

public void handleMessage(Message msg) {

switch (msg.what) {

caseSHOW_DIALOG:

//android控件,一般是在Dialog上面加控件

sMediaDialog = new MediaDialog(sMediaActivity); //sMediaActivity定义全局初始时sMediaActivity=this

sMediaDialog.show();

break;

}

}

};

 

3. 改变android横竖屏 配置的xml

    <application

        android:icon="@drawable/icon"

        android:label="@string/app_name">

        <activity

            android:name=".WeiboTest2"

            android:configChanges="orientation"

            android:label="@string/app_name"

            android:screenOrientation="portrait"     //portrait 竖屏  //横屏

            android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

            <intent-filter>

                <actionandroid:name="android.intent.action.MAIN"/>

 

                <categoryandroid:name="android.intent.category.LAUNCHER"/>

            </intent-filter>

        </activity>

    </application>

 

 

 4.导出游戏android版

1.Resources目录下的所有的内容覆盖到android assets

2.所有的文件引用加路径

3.导入的第三方库像引入Classes文件夹那样引进,#include "../第三方库/文件名"

4.

  •  .h文件 iniline ...实现函数不能用(音乐播放)、
  • class 类:声明类不是一个文件夹下的不行(httpClient)是一个文件夹下的等待考证

5. 判断有时平台失效

  • //可能只有在方法中可以判断,
  • #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
  • #include "xxx.h"
  • #endif
  • #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  • #include "xxx.h"
  • #endif

 6.不能在.h中给变量赋值

 7.引进C++的json解析包屏蔽的行

  • json_reader.cpp // 881行被我注释
  • json_value.cpp
  • 158  704729732739
  • 754  759  766 791

 8.threeLibrary里跨平台的SQLLite3引用有问题

 9.引用extension错误

加上

#include"cocos-ext.h"

USING_NS_CC_EXT;

 tableview 时除了ios的要继承publicCCTableViewDataSourcepublicCCTableViewDelegate,

外还要继承CCEditBoxDelegate

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics