《Cocos2d学习之路》五,粒子效果,Actions,以及中文显示问题的解决

前端之家收集整理的这篇文章主要介绍了《Cocos2d学习之路》五,粒子效果,Actions,以及中文显示问题的解决前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

转载请说明出处:http://blog.csdn.net/lsmfeixiang/article/details/42331321

github地址:https://github.com/teffy/cocos2dx


最近有点事情,学习之路耽搁了。之前看了粒子效果,感觉东西太少了就准备再学习一下actions的东西再发文,耽误了这么久。


第一部分是粒子效果

当然Code非常简单,主要是一些API的变化,基本变化还是原来的CC开头的代码,3.x可以去掉CC使用,例如:CCParticleSnow变为了ParticleSnow

使用方法分为两种:

第一种是Cocosd提供的API,

// ParticleSnow
// ParticleFire
// ParticleFlower
// ParticleGalaxy
// ParticleMeteor
// ParticleRain
// ParticleSmoke
// ParticleSpiral
// ParticleSun

等等,create->setTexture->add to scene就可以显示

放一段实例代码

	ParticleSystem* particle = ParticleSun::create();
	particle->setTexture(TextureCache::sharedTextureCache()->addImage("res/laugh.png"));
	this->addChild(particle);

第二种,使用各种粒子效果软件生成的粒子效果文件,.plist,然后使用Code去加载这些文件,然后add to scene就可以了,实例代码
	ParticleSystemQuad* quad = ParticleSystemQuad::create("particles/Upsidedown.plist");
	quad->setPosition(Vec2(visibleSize.width / 2,visibleSize.height / 2));
	quad->setAutoRemoveOnFinish(true);
	this->addChild(quad);

另外文章中说到cocos2d提供了一些测试效果,3.3的路径是X:\Cocos\cocos2d-x-3.3\tests\cpp-tests\Resources\Particles下,可以挨个运行一下,还是挺有意思的


第二部分,Actions

由于cocos2d的action太多了,先看下Action的继承关系图


其中,ActionInstant为即时动画,ActionInterval为持续动画,需要持续运行一段时间的动作。 它有一个启动时间和结束时间,结束时间由启动时间加上周期得出。

我就打算全部列举出来,放置三个按钮,last,restart,next,上面显示对这个动画的描述,点击按钮的时候会让一个sprite执行动画,效果图如下:


同时呢,由于要在上面显示中文 ,就引出了中文不能显示的问题,一点一点看Code。

首先是三个按钮

	int x = 0;
	auto last = MenuItemFont::create("Last",CC_CALLBACK_1(HelloWorld::menuLastCallback,this));
	x = origin.x + last->getContentSize().width+160;
	last->setPosition(Vec2(x,origin.y + last->getContentSize().height));

	auto restart = MenuItemFont::create("Restart",CC_CALLBACK_1(HelloWorld::menuRestartCallback,this));
	x += restart->getContentSize().width + 30;
	restart->setPosition(Vec2(x,origin.y + restart->getContentSize().height));

	auto next = MenuItemFont::create("Next",CC_CALLBACK_1(HelloWorld::menuNextCallback,this));
	x += next->getContentSize().width+30;
	next->setPosition(Vec2(x,origin.y + next->getContentSize().height));
分别有回调函数
menuLastCallback
menuRestartCallback
menuNextCallback

所有的action放在Vector中,对action的描述放在std::list<std::string>中

	int index;
        FiniteTimeAction* currentAction;
        Vector<FiniteTimeAction*> actions;
        std::list<std::string> *actionDescriptions;
//下面是初始化出action和描述,放进集合中去
	auto scaleto = ScaleTo::create(2.0f,2.0f,0.5f);
	actionDescriptions->push_back(gbk2utf8("ScaleTo,缩放动画"));
	actions.pushBack(scaleto);
	auto hide = Hide::create();
	actionDescriptions->push_back(getStringByKey("Hide"));
	actions.pushBack(hide);
上面对于描述的操作,分为两种,就是两种处理中文的方式,后面再讲;这里只列举了两个action,更多的还是看code中。

然后是点击三个按钮的事件处理

void HelloWorld::menuLastCallback(Ref* pSender){
	this->removeChildByName(ANDROIDAPPLE,true);
	androidapple = Sprite::create("res/androidapple.png");
	androidapple->setPosition(Vec2(visibleSize.width / 3,visibleSize.height / 2 - androidapple->getContentSize().height));
	this->addChild(androidapple,ANDROIDAPPLE);

	currentAction = actions.at(index);
	androidapple->runAction(Sequence::create(DelayTime::create(0.5f),currentAction,NULL));
	
	std::list<std::string>::iterator it = actionDescriptions->begin();
	for (int i = 0; i < index; ++i) {
		++it;
	}
	this->removeChildByName(LABEL,true);
	log("%s",((std::string) *it).c_str());
	label = Label::createWithTTF(((std::string) *it).c_str(),TTF,24);
	label->setPosition(Vec2(visibleSize.width / 2,visibleSize.height - label->getContentSize().height));
	this->addChild(label,1,LABEL);

	if (--index < 0){
		index = actions.size()-1;
	}
}
void HelloWorld::menuRestartCallback(Ref* pSender){
	if (currentAction != NULL){
		this->removeChildByName(ANDROIDAPPLE,true);
		androidapple = Sprite::create("res/androidapple.png");
		androidapple->setPosition(Vec2(visibleSize.width / 3,visibleSize.height / 2 - androidapple->getContentSize().height));
		this->addChild(androidapple,ANDROIDAPPLE);
		androidapple->runAction(Sequence::create(DelayTime::create(0.5f),NULL));
	}
}
void HelloWorld::menuNextCallback(Ref* pSender){
	//不知道怎样使sprite恢复到原始状态,只能用最笨的方法了,remove掉,然后重新加载一个进来
	this->removeChildByName(ANDROIDAPPLE,ANDROIDAPPLE);
	
	//DelayTime::create(1);//为了明细的看出效果,延后0.5秒
	//Sequence::create//动作组合,顺序执行,NULL是结束
	currentAction = actions.at(index);
	androidapple->runAction(Sequence::create(DelayTime::create(0.5f),LABEL);

	// 检测index,以防越界
	if (++index >= actions.size()){
		index = 0;
	}
}
实在是不知道怎么让sprite恢复到初始状态,只能用最笨的方法,请勿见笑,也请高手留言告诉我。

我的demo中没有对于GridAction和ProgressTo的使用的实例,因为暂时没搞懂,运行时也有错,先把文章发出了吧。



下面来讲关于中文显示的处理,在网上各种搜索,原因是很多PC的各种编译器的编码格式是gb2312,而cocos的是utf8,所以导致编码乱了。分为两种解决方案:

第一种,在读取字符的时候进行转码,而最常用的方式是使用iconv库,cocos2d 3.x已经自带了,比较方便

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "..\cocos2d\iconv\include\iconv.h"
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#include "..\cocos2d\external\win32-specific\icon\include\iconv.h"
#endif

#pragma comment(lib,"libiconv.lib")
#include "string"
using namespace std;

static int code_convert(const char *from_charset,const char *to_charset,const char *inbuf,size_t inlen,char *outbuf,size_t outlen)
{
	iconv_t cd;
	const char *temp = inbuf;
	const char **pin = &temp;
	char **pout = &outbuf;
	memset(outbuf,outlen);
	cd = iconv_open(to_charset,from_charset);
	if (cd == 0) return -1;
	if (iconv(cd,pin,&inlen,pout,&outlen) == -1) return -1;
	iconv_close(cd);
	return 0;
}

/*UTF8 to GB2312*/
static std::string utf2gbk(const char *inbuf)
{
	size_t inlen = strlen(inbuf);
	char * outbuf = new char[inlen * 2 + 2];
	std::string strRet;
	if (code_convert("utf-8","gb2312",inbuf,inlen,outbuf,inlen * 2 + 2) == 0)
	{
		strRet = outbuf;
	}
	delete[] outbuf;
	return strRet;
}

/*GB2312 to UTF8*/
static std::string gbk2utf8(const char *inbuf)
{
	size_t inlen = strlen(inbuf);
	char * outbuf = new char[inlen * 2 + 2];
	std::string strRet;
	if (code_convert("gb2312","utf-8",inlen * 2 + 2) == 0)
	{
		strRet = outbuf;
	}
	delete[] outbuf;
	return strRet;
}
//#endif

用法呢,就是我上面的code中的用法


第二种,使用xml,xml头的格式可以定义,然后使用Dictionary解析得出,而且这种方式对于国际化来说很有帮助(感觉和android里的国际化有点类似,但是我目前还不知道怎么搞)

static std::string getStringByKey(const char* key){
	Dictionary *strings = Dictionary::createWithContentsOfFile("fonts/strings.xml");
	return ((String*)strings->objectForKey(key))->getCString();
}
函数用法,上面code有提到。

另外1,Label在create要指定的字体库.ttf要包含中文字库,要不然也显示不了,我的demo中用到了一个方正中宋简体的字体,后面会放出连接。(有没有小点的字体包,这个太大,4M好像)

另外2,win平台可以直接编译运行,但是Android下面在Eclipse下编译出错,需要按照后面给出的连接中一步一步修改,我也会在资源中放上资源包和需要修改的几个文件

1、下载libiconv-1.14.tar.gz,解压出来,最里面的文件夹rename为iconv,然后copy到项目的cocos2d文件夹下


2、在刚才的iconv文件夹下,新建一个Android.mk文件,然后内容

LOCAL_PATH:= $(call my-dir)
#libiconv.so
include $(CLEAR_VARS)
 
LOCAL_MODULE := iconv_static
LOCAL_MODULE_FILENAME := libiconv
LOCAL_CFLAGS := \
  -Wno-multichar \
  -DAndroid \
  -DLIBDIR="c" \
  -DBUILDING_LIBICONV \
  -DIN_LIBRARY
LOCAL_SRC_FILES := \
  libcharset/lib/localcharset.c \
  lib/iconv.c \
  lib/relocatable.c
LOCAL_C_INCLUDES += \
  $(LOCAL_PATH)/include \
  $(LOCAL_PATH)/libcharset \
  $(LOCAL_PATH)/lib \
  $(LOCAL_PATH)/libcharset/include \
  $(LOCAL_PATH)/srclib
include $(BUILD_STATIC_LIBRARY)

3、然后去我们自己的proj.android/jni下修改mk文件添加以下配置

$(LOCAL_PATH)/../../cocos2d/iconv/include \
$(LOCAL_PATH)/../../cocos2d/iconv/libcharset \
$(LOCAL_PATH)/../../cocos2d/iconv/lib \
$(LOCAL_PATH)/../../cocos2d/iconv/libcharset/include \
$(LOCAL_PATH)/../../cocos2d/iconv/srclib \
$(LOCAL_PATH)/../../cocos2d/iconv \
LOCAL_WHOLE_STATIC_LIBRARIES += iconv_static
$(call import-module,iconv)

4、然后rename cocos2d\iconv\include路径下的iconv.h.in为 iconv.h,并修改内容

/* Copyright (C) 1999-2003,2005-2006,2008-2011 Free Software Foundation,Inc.
   This file is part of the GNU LIBICONV Library.
 
   The GNU LIBICONV Library is free software; you can redistribute it
   and/or modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either version 2
   of the License,or (at your option) any later version.
 
   The GNU LIBICONV Library is distributed in the hope that it will be
   useful,but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
 
   You should have received a copy of the GNU Library General Public
   License along with the GNU LIBICONV Library; see the file COPYING.LIB.
   If not,write to the Free Software Foundation,Inc.,51 Franklin Street,Fifth Floor,Boston,MA 02110-1301,USA.  */
 
/* When installed,this file is called "iconv.h". */
 
#ifndef _LIBICONV_H
#define _LIBICONV_H
 
#define _LIBICONV_VERSION 0x010E    /* version number: (major<<8) + minor */
extern int _libiconv_version; /* Likewise */
 
/* We would like to #include any system header file which could define
   iconv_t,1. in order to eliminate the risk that the user gets compilation
   errors because some other system header file includes /usr/include/iconv.h
   which defines iconv_t or declares iconv after this file,2. when compiling
   for LIBICONV_PLUG,we need the proper iconv_t type in order to produce
   binary compatible code.
   But gcc's #include_next is not portable. Thus,once libiconv's iconv.h
   has been installed in /usr/local/include,there is no way any more to
   include the original /usr/include/iconv.h. We simply have to get away
   without it.
   Ad 1. The risk that a system header file does
   #include "iconv.h"  or  #include_next "iconv.h"
   is small. They all do #include <iconv.h>.
   Ad 2. The iconv_t type is a pointer type in all cases I have seen. (It
   has to be a scalar type because (iconv_t)(-1) is a possible return value
   from iconv_open().) */
 
/* Define iconv_t ourselves. */
#undef iconv_t
#define iconv_t libiconv_t
typedef void* iconv_t;
 
/* Get size_t declaration.
   Get wchar_t declaration if it exists. */
#include <stddef.h>
 
/* Get errno declaration and values. */
#include <errno.h>
/* Some systems,like SunOS 4,don't have EILSEQ. Some systems,like BSD/OS,have EILSEQ in a different header.  On these systems,define EILSEQ
   ourselves. */
#ifndef EILSEQ
#define EILSEQ 84
#endif
 
 
#ifdef __cplusplus
extern "C" {
#endif
 
 
/* Allocates descriptor for code conversion from encoding ‘fromcode’ to
   encoding ‘tocode’. */
#ifndef LIBICONV_PLUG
#define iconv_open libiconv_open
#endif
extern iconv_t iconv_open (const char* tocode,const char* fromcode);
 
/* Converts,using conversion descriptor ‘cd’,at most ‘*inbytesleft’ bytes
   starting at ‘*inbuf’,writing at most ‘*outbytesleft’ bytes starting at
   ‘*outbuf’.
   Decrements ‘*inbytesleft’ and increments ‘*inbuf’ by the same amount.
   Decrements ‘*outbytesleft’ and increments ‘*outbuf’ by the same amount. */
#ifndef LIBICONV_PLUG
#define iconv libiconv
#endif
extern size_t iconv (iconv_t cd,const char* * inbuf,size_t *inbytesleft,char* * outbuf,size_t *outbytesleft);//iconv.c要相应修改
 
/* Frees resources allocated for conversion descriptor ‘cd’. */
#ifndef LIBICONV_PLUG
#define iconv_close libiconv_close
#endif
extern int iconv_close (iconv_t cd);
 
 
#ifdef __cplusplus
}
#endif
 
 
#ifndef LIBICONV_PLUG
 
/* Nonstandard extensions. */
 
#if USE_MBSTATE_T
#if BROKEN_WCHAR_H
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
   <wchar.h>.
   BSD/OS 4.0.1 has a bug: <stddef.h>,<stdio.h> and <time.h> must be
   included before <wchar.h>.  */
#include <stddef.h>
#include <stdio.h>
#include <time.h>
#endif
#include <wchar.h>
#endif
 
#ifdef __cplusplus
extern "C" {
#endif
 
/* A type that holds all memory needed by a conversion descriptor.
   A pointer to such an object can be used as an iconv_t. */
typedef struct {
  void* dummy1[28];
#if USE_MBSTATE_T
  mbstate_t dummy2;
#endif
} iconv_allocation_t;
 
/* Allocates descriptor for code conversion from encoding ‘fromcode’ to
   encoding ‘tocode’ into preallocated memory. Returns an error indicator
   (0 or -1 with errno set). */
#define iconv_open_into libiconv_open_into
extern int iconv_open_into (const char* tocode,const char* fromcode,iconv_allocation_t* resultp);
 
/* Control of attributes. */
#define iconvctl libiconvctl
extern int iconvctl (iconv_t cd,int request,void* argument);
 
/* Hook performed after every successful conversion of a Unicode character. */
typedef void (*iconv_unicode_char_hook) (unsigned int uc,void* data);
/* Hook performed after every successful conversion of a wide character. */
typedef void (*iconv_wide_char_hook) (wchar_t wc,void* data);
/* Set of hooks. */
struct iconv_hooks {
  iconv_unicode_char_hook uc_hook;
  iconv_wide_char_hook wc_hook;
  void* data;
};
 
/* Fallback function.  Invoked when a small number of bytes could not be
   converted to a Unicode character.  This function should process all
   bytes from inbuf and may produce replacement Unicode characters by calling
   the write_replacement callback repeatedly.  */
typedef void (*iconv_unicode_mb_to_uc_fallback)
             (const char* inbuf,size_t inbufsize,void (*write_replacement) (const unsigned int *buf,size_t buflen,void* callback_arg),void* callback_arg,void* data);
/* Fallback function.  Invoked when a Unicode character could not be converted
   to the target encoding.  This function should process the character and
   may produce replacement bytes (in the target encoding) by calling the
   write_replacement callback repeatedly.  */
typedef void (*iconv_unicode_uc_to_mb_fallback)
             (unsigned int code,void (*write_replacement) (const char *buf,void* data);
#if HAVE_WCHAR_T
/* Fallback function.  Invoked when a number of bytes could not be converted to
   a wide character.  This function should process all bytes from inbuf and may
   produce replacement wide characters by calling the write_replacement
   callback repeatedly.  */
typedef void (*iconv_wchar_mb_to_wc_fallback)
             (const char* inbuf,void (*write_replacement) (const wchar_t *buf,void* data);
/* Fallback function.  Invoked when a wide character could not be converted to
   the target encoding.  This function should process the character and may
   produce replacement bytes (in the target encoding) by calling the
   write_replacement callback repeatedly.  */
typedef void (*iconv_wchar_wc_to_mb_fallback)
             (wchar_t code,void* data);
#else
/* If the wchar_t type does not exist,these two fallback functions are never
   invoked.  Their argument list therefore does not matter.  */
typedef void (*iconv_wchar_mb_to_wc_fallback) ();
typedef void (*iconv_wchar_wc_to_mb_fallback) ();
#endif
/* Set of fallbacks. */
struct iconv_fallbacks {
  iconv_unicode_mb_to_uc_fallback mb_to_uc_fallback;
  iconv_unicode_uc_to_mb_fallback uc_to_mb_fallback;
  iconv_wchar_mb_to_wc_fallback mb_to_wc_fallback;
  iconv_wchar_wc_to_mb_fallback wc_to_mb_fallback;
  void* data;
};
 
/* Requests for iconvctl. */
#define ICONV_TRIVIALP            0  /* int *argument */
#define ICONV_GET_TRANSLITERATE   1  /* int *argument */
#define ICONV_SET_TRANSLITERATE   2  /* const int *argument */
#define ICONV_GET_DISCARD_ILSEQ   3  /* int *argument */
#define ICONV_SET_DISCARD_ILSEQ   4  /* const int *argument */
#define ICONV_SET_HOOKS           5  /* const struct iconv_hooks *argument */
#define ICONV_SET_FALLBACKS       6  /* const struct iconv_fallbacks *argument */
 
/* Listing of locale independent encodings. */
#define iconvlist libiconvlist
extern void iconvlist (int (*do_one) (unsigned int namescount,const char * const * names,void* data),void* data);
 
/* Canonicalize an encoding name.
   The result is either a canonical encoding name,or name itself. */
extern const char * iconv_canonicalize (const char * name);
 
/* Support for relocatable packages.  */
 
/* Sets the original and the current installation prefix of the package.
   Relocation simply replaces a pathname starting with the original prefix
   by the corresponding pathname with the current prefix instead.  Both
   prefixes should be directory names without trailing slash (i.e. use ""
   instead of "/").  */
extern void libiconv_set_relocation_prefix (const char *orig_prefix,const char *curr_prefix);
 
#ifdef __cplusplus
}
#endif
 
#endif
 
 
#endif /* _LIBICONV_H */
5、修改\cocos2d\iconv\lib路径下的iconv.c的内容

/*
 * Copyright (C) 1999-2008,2011 Free Software Foundation,Inc.
 * This file is part of the GNU LIBICONV Library.
 *
 * The GNU LIBICONV Library is free software; you can redistribute it
 * and/or modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either version 2
 * of the License,or (at your option) any later version.
 *
 * The GNU LIBICONV Library is distributed in the hope that it will be
 * useful,but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with the GNU LIBICONV Library; see the file COPYING.LIB.
 * If not,* Fifth Floor,USA.
 */
 
#include <iconv.h>
 
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "localcharset.h"
 
#ifdef __CYGWIN__
#include <cygwin version.h="">
#endif
 
#if ENABLE_EXTRA
/*
 * Consider all system dependent encodings,for any system,* and the extra encodings.
 */
#define USE_AIX
#define USE_OSF1
#define USE_DOS
#define USE_EXTRA
#else
/*
 * Consider those system dependent encodings that are needed for the
 * current system.
 */
#ifdef _AIX
#define USE_AIX
#endif
#if defined(__osf__) || defined(VMS)
#define USE_OSF1
#endif
#if defined(__DJGPP__) || (defined(_WIN32) && (defined(_MSC_VER) || defined(__MINGW32__)))
#define USE_DOS
#endif
#endif
 
/*
 * Data type for general conversion loop.
 */
struct loop_funcs {
  size_t (*loop_convert) (iconv_t icd,size_t *outbytesleft);
  size_t (*loop_reset) (iconv_t icd,size_t *outbytesleft);
};
 
/*
 * Converters.
 */
#include "converters.h"
 
/*
 * Transliteration tables.
 */
#include "cjk_variants.h"
#include "translit.h"
 
/*
 * Table of all supported encodings.
 */
struct encoding {
  struct mbtowc_funcs ifuncs; /* conversion multibyte -> unicode */
  struct wctomb_funcs ofuncs; /* conversion unicode -> multibyte */
  int oflags;                 /* flags for unicode -> multibyte conversion */
};
#define DEFALIAS(xxx_alias,xxx) /* nothing */
enum {
#define DEFENCODING(xxx_names,xxx,xxx_ifuncs1,xxx_ifuncs2,xxx_ofuncs1,xxx_ofuncs2) \
  ei_##xxx,#include "encodings.def"
#ifdef USE_AIX
# include "encodings_aix.def"
#endif
#ifdef USE_OSF1
# include "encodings_osf1.def"
#endif
#ifdef USE_DOS
# include "encodings_dos.def"
#endif
#ifdef USE_EXTRA
# include "encodings_extra.def"
#endif
#include "encodings_local.def"
#undef DEFENCODING
ei_for_broken_compilers_that_dont_like_trailing_commas
};
#include "flags.h"
static struct encoding const all_encodings[] = {
#define DEFENCODING(xxx_names,xxx_ofuncs2) \
  { xxx_ifuncs1,xxx_ofuncs2,ei_##xxx##_oflags },#include "encodings.def"
#ifdef USE_AIX
# include "encodings_aix.def"
#endif
#ifdef USE_OSF1
# include "encodings_osf1.def"
#endif
#ifdef USE_DOS
# include "encodings_dos.def"
#endif
#ifdef USE_EXTRA
# include "encodings_extra.def"
#endif
#undef DEFENCODING
#define DEFENCODING(xxx_names,0 },#include "encodings_local.def"
#undef DEFENCODING
};
#undef DEFALIAS
 
/*
 * Conversion loops.
 */
#include "loops.h"
 
/*
 * Alias lookup function.
 * Defines
 *   struct alias { int name; unsigned int encoding_index; };
 *   const struct alias * aliases_lookup (const char *str,unsigned int len);
 *   #define MAX_WORD_LENGTH ...
 */
#if defined _AIX
# include "aliases_sysaix.h"
#elif defined hpux || defined __hpux
# include "aliases_syshpux.h"
#elif defined __osf__
# include "aliases_sysosf1.h"
#elif defined __sun
# include "aliases_syssolaris.h"
#else
# include "aliases.h"
#endif
 
/*
 * System dependent alias lookup function.
 * Defines
 *   const struct alias * aliases2_lookup (const char *str);
 */
#if defined(USE_AIX) || defined(USE_OSF1) || defined(USE_DOS) || defined(USE_EXTRA) /* || ... */
struct stringpool2_t {
#define S(tag,name,encoding_index) char stringpool_##tag[sizeof(name)];
#include "aliases2.h"
#undef S
};
static const struct stringpool2_t stringpool2_contents = {
#define S(tag,encoding_index) name,#include "aliases2.h"
#undef S
};
#define stringpool2 ((const char *) &stringpool2_contents)
static const struct alias sysdep_aliases[] = {
#define S(tag,encoding_index) { (int)(long)&((struct stringpool2_t *)0)->stringpool_##tag,encoding_index },#include "aliases2.h"
#undef S
};
#ifdef __GNUC__
__inline
#endif
const struct alias *
aliases2_lookup (register const char *str)
{
  const struct alias * ptr;
  unsigned int count;
  for (ptr = sysdep_aliases,count = sizeof(sysdep_aliases)/sizeof(sysdep_aliases[0]); count > 0; ptr++,count--)
    if (!strcmp(str,stringpool2 + ptr->name))
      return ptr;
  return NULL;
}
#else
#define aliases2_lookup(str)  NULL
#define stringpool2  NULL
#endif
 
#if 0
/* Like !strcasecmp,except that the both strings can be assumed to be ASCII
   and the first string can be assumed to be in uppercase. */
static int strequal (const char* str1,const char* str2)
{
  unsigned char c1;
  unsigned char c2;
  for (;;) {
    c1 = * (unsigned char *) str1++;
    c2 = * (unsigned char *) str2++;
    if (c1 == 0)
      break;
    if (c2 >= 'a' && c2 <= 'z')
      c2 -= 'a'-'A';
    if (c1 != c2)
      break;
  }
  return (c1 == c2);
}
#endif
 
iconv_t iconv_open (const char* tocode,const char* fromcode)
{
  struct conv_struct * cd;
  unsigned int from_index;
  int from_wchar;
  unsigned int to_index;
  int to_wchar;
  int transliterate;
  int discard_ilseq;
 
#include "iconv_open1.h"
 
  cd = (struct conv_struct *) malloc(from_wchar != to_wchar
                                     ? sizeof(struct wchar_conv_struct)
                                     : sizeof(struct conv_struct));
  if (cd == NULL) {
    errno = ENOMEM;
    return (iconv_t)(-1);
  }
 
#include "iconv_open2.h"
 
  return (iconv_t)cd;
invalid:
  errno = EINVAL;
  return (iconv_t)(-1);
}
 
size_t iconv (iconv_t icd,size_t *outbytesleft)
{
  conv_t cd = (conv_t) icd;
  if (inbuf == NULL || *inbuf == NULL)
    return cd->lfuncs.loop_reset(icd,outbytesleft);
  else
    return cd->lfuncs.loop_convert(icd,(const char* *)inbuf,inbytesleft,outbytesleft);
}
 
int iconv_close (iconv_t icd)
{
  conv_t cd = (conv_t) icd;
  free(cd);
  return 0;
}
 
#ifndef LIBICONV_PLUG
 
/*
 * Verify that a 'struct conv_struct' and a 'struct wchar_conv_struct' each
 * fit in an iconv_allocation_t.
 * If this verification fails,iconv_allocation_t must be made larger and
 * the major version in LIBICONV_VERSION_INFO must be bumped.
 * Currently 'struct conv_struct' has 21 integer/pointer fields,and
 * 'struct wchar_conv_struct' additionally has an 'mbstate_t' field.
 */
typedef int verify_size_1[2 * (sizeof (struct conv_struct) <= sizeof (iconv_allocation_t)) - 1];
typedef int verify_size_2[2 * (sizeof (struct wchar_conv_struct) <= sizeof (iconv_allocation_t)) - 1];
 
int iconv_open_into (const char* tocode,iconv_allocation_t* resultp)
{
  struct conv_struct * cd;
  unsigned int from_index;
  int from_wchar;
  unsigned int to_index;
  int to_wchar;
  int transliterate;
  int discard_ilseq;
 
#include "iconv_open1.h"
 
  cd = (struct conv_struct *) resultp;
 
#include "iconv_open2.h"
 
  return 0;
invalid:
  errno = EINVAL;
  return -1;
}
 
int iconvctl (iconv_t icd,void* argument)
{
  conv_t cd = (conv_t) icd;
  switch (request) {
    case ICONV_TRIVIALP:
      *(int *)argument =
        ((cd->lfuncs.loop_convert == unicode_loop_convert
          && cd->iindex == cd->oindex)
         || cd->lfuncs.loop_convert == wchar_id_loop_convert
         ? 1 : 0);
      return 0;
    case ICONV_GET_TRANSLITERATE:
      *(int *)argument = cd->transliterate;
      return 0;
    case ICONV_SET_TRANSLITERATE:
      cd->transliterate = (*(const int *)argument ? 1 : 0);
      return 0;
    case ICONV_GET_DISCARD_ILSEQ:
      *(int *)argument = cd->discard_ilseq;
      return 0;
    case ICONV_SET_DISCARD_ILSEQ:
      cd->discard_ilseq = (*(const int *)argument ? 1 : 0);
      return 0;
    case ICONV_SET_HOOKS:
      if (argument != NULL) {
        cd->hooks = *(const struct iconv_hooks *)argument;
      } else {
        cd->hooks.uc_hook = NULL;
        cd->hooks.wc_hook = NULL;
        cd->hooks.data = NULL;
      }
      return 0;
    case ICONV_SET_FALLBACKS:
      if (argument != NULL) {
        cd->fallbacks = *(const struct iconv_fallbacks *)argument;
      } else {
        cd->fallbacks.mb_to_uc_fallback = NULL;
        cd->fallbacks.uc_to_mb_fallback = NULL;
        cd->fallbacks.mb_to_wc_fallback = NULL;
        cd->fallbacks.wc_to_mb_fallback = NULL;
        cd->fallbacks.data = NULL;
      }
      return 0;
    default:
      errno = EINVAL;
      return -1;
  }
}
 
/* An alias after its name has been converted from 'int' to 'const char*'. */
struct nalias { const char* name; unsigned int encoding_index; };
 
static int compare_by_index (const void * arg1,const void * arg2)
{
  const struct nalias * alias1 = (const struct nalias *) arg1;
  const struct nalias * alias2 = (const struct nalias *) arg2;
  return (int)alias1->encoding_index - (int)alias2->encoding_index;
}
 
static int compare_by_name (const void * arg1,const void * arg2)
{
  const char * name1 = *(const char **)arg1;
  const char * name2 = *(const char **)arg2;
  /* Compare alphabetically,but put "CS" names at the end. */
  int sign = strcmp(name1,name2);
  if (sign != 0) {
    sign = ((name1[0]=='C' && name1[1]=='S') - (name2[0]=='C' && name2[1]=='S'))
           * 4 + (sign >= 0 ? 1 : -1);
  }
  return sign;
}
 
void iconvlist (int (*do_one) (unsigned int namescount,void* data)
{
#define aliascount1  sizeof(aliases)/sizeof(aliases[0])
#ifndef aliases2_lookup
#define aliascount2  sizeof(sysdep_aliases)/sizeof(sysdep_aliases[0])
#else
#define aliascount2  0
#endif
#define aliascount  (aliascount1+aliascount2)
  struct nalias aliasbuf[aliascount];
  const char * namesbuf[aliascount];
  size_t num_aliases;
  {
    /* Put all existing aliases into a buffer. */
    size_t i;
    size_t j;
    j = 0;
    for (i = 0; i < aliascount1; i++) {
      const struct alias * p = &aliases[i];
      if (p->name >= 0
          && p->encoding_index != ei_local_char
          && p->encoding_index != ei_local_wchar_t) {
        aliasbuf[j].name = stringpool + p->name;
        aliasbuf[j].encoding_index = p->encoding_index;
        j++;
      }
    }
#ifndef aliases2_lookup
    for (i = 0; i < aliascount2; i++) {
      aliasbuf[j].name = stringpool2 + sysdep_aliases[i].name;
      aliasbuf[j].encoding_index = sysdep_aliases[i].encoding_index;
      j++;
    }
#endif
    num_aliases = j;
  }
  /* Sort by encoding_index. */
  if (num_aliases > 1)
    qsort(aliasbuf,num_aliases,sizeof(struct nalias),compare_by_index);
  {
    /* Process all aliases with the same encoding_index together. */
    size_t j;
    j = 0;
    while (j < num_aliases) {
      unsigned int ei = aliasbuf[j].encoding_index;
      size_t i = 0;
      do
        namesbuf[i++] = aliasbuf[j++].name;
      while (j < num_aliases && aliasbuf[j].encoding_index == ei);
      if (i > 1)
        qsort(namesbuf,i,sizeof(const char *),compare_by_name);
      /* Call the callback. */
      if (do_one(i,namesbuf,data))
        break;
    }
  }
#undef aliascount
#undef aliascount2
#undef aliascount1
}
 
/*
 * Table of canonical names of encodings.
 * Instead of strings,it contains offsets into stringpool and stringpool2.
 */
static const unsigned short all_canonical[] = {
#if defined _AIX
# include "canonical_sysaix.h"
#elif defined hpux || defined __hpux
# include "canonical_syshpux.h"
#elif defined __osf__
# include "canonical_sysosf1.h"
#elif defined __sun
# include "canonical_syssolaris.h"
#else
# include "canonical.h"
#endif
#ifdef USE_AIX
# if defined _AIX
#  include "canonical_aix_sysaix.h"
# else
#  include "canonical_aix.h"
# endif
#endif
#ifdef USE_OSF1
# if defined __osf__
#  include "canonical_osf1_sysosf1.h"
# else
#  include "canonical_osf1.h"
# endif
#endif
#ifdef USE_DOS
# include "canonical_dos.h"
#endif
#ifdef USE_EXTRA
# include "canonical_extra.h"
#endif
#if defined _AIX
# include "canonical_local_sysaix.h"
#elif defined hpux || defined __hpux
# include "canonical_local_syshpux.h"
#elif defined __osf__
# include "canonical_local_sysosf1.h"
#elif defined __sun
# include "canonical_local_syssolaris.h"
#else
# include "canonical_local.h"
#endif
};
 
const char * iconv_canonicalize (const char * name)
{
  const char* code;
  char buf[MAX_WORD_LENGTH+10+1];
  const char* cp;
  char* bp;
  const struct alias * ap;
  unsigned int count;
  unsigned int index;
  const char* pool;
 
  /* Before calling aliases_lookup,convert the input string to upper case,* and check whether it's entirely ASCII (we call gperf with option "-7"
   * to achieve a smaller table) and non-empty. If it's not entirely ASCII,* or if it's too long,it is not a valid encoding name.
   */
  for (code = name;;) {
    /* Search code in the table. */
    for (cp = code,bp = buf,count = MAX_WORD_LENGTH+10+1; ; cp++,bp++) {
      unsigned char c = * (unsigned char *) cp;
      if (c >= 0x80)
        goto invalid;
      if (c >= 'a' && c <= 'z')
        c -= 'a'-'A';
      *bp = c;
      if (c == '\0')
        break;
      if (--count == 0)
        goto invalid;
    }
    for (;;) {
      if (bp-buf >= 10 && memcmp(bp-10,"//TRANSLIT",10)==0) {
        bp -= 10;
        *bp = '\0';
        continue;
      }
      if (bp-buf >= 8 && memcmp(bp-8,"//IGNORE",8)==0) {
        bp -= 8;
        *bp = '\0';
        continue;
      }
      break;
    }
    if (buf[0] == '\0') {
      code = locale_charset();
      /* Avoid an endless loop that could occur when using an older version
         of localcharset.c. */
      if (code[0] == '\0')
        goto invalid;
      continue;
    }
    pool = stringpool;
    ap = aliases_lookup(buf,bp-buf);
    if (ap == NULL) {
      pool = stringpool2;
      ap = aliases2_lookup(buf);
      if (ap == NULL)
        goto invalid;
    }
    if (ap->encoding_index == ei_local_char) {
      code = locale_charset();
      /* Avoid an endless loop that could occur when using an older version
         of localcharset.c. */
      if (code[0] == '\0')
        goto invalid;
      continue;
    }
    if (ap->encoding_index == ei_local_wchar_t) {
      /* On systems which define __STDC_ISO_10646__,wchar_t is Unicode.
         This is also the case on native Woe32 systems and Cygwin >= 1.7,where
         we know that it is UTF-16.  */
#if ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) || (defined __CYGWIN__ && CYGWIN_VERSION_DLL_MAJOR >= 1007)
      if (sizeof(wchar_t) == 4) {
        index = ei_ucs4internal;
        break;
      }
      if (sizeof(wchar_t) == 2) {
# if WORDS_LITTLEENDIAN
        index = ei_utf16le;
# else
        index = ei_utf16be;
# endif
        break;
      }
#elif __STDC_ISO_10646__
      if (sizeof(wchar_t) == 4) {
        index = ei_ucs4internal;
        break;
      }
      if (sizeof(wchar_t) == 2) {
        index = ei_ucs2internal;
        break;
      }
      if (sizeof(wchar_t) == 1) {
        index = ei_iso8859_1;
        break;
      }
#endif
    }
    index = ap->encoding_index;
    break;
  }
  return all_canonical[index] + pool;
 invalid:
  return name;
}
 
int _libiconv_version = _LIBICONV_VERSION;
 
#if defined __FreeBSD__ && !defined __gnu_freebsd__
/* GNU libiconv is the native FreeBSD iconv implementation since 2002.
   It wants to define the symbols 'iconv_open','iconv','iconv_close'.  */
#define strong_alias(name,aliasname) _strong_alias(name,aliasname)
#define _strong_alias(name,aliasname) \
  extern __typeof (name) aliasname __attribute__ ((alias (#name)));
#undef iconv_open
#undef iconv
#undef iconv_close
strong_alias (libiconv_open,iconv_open)
strong_alias (libiconv,iconv)
strong_alias (libiconv_close,iconv_close)
#endif
 
#endif
6、修改cocos2d\iconv\libcharset\lib路径下的localcharset.c内容
/* Determine a canonical name for the current locale's character encoding.
 
   Copyright (C) 2000-2006,2008-2010 Free Software Foundation,Inc.
 
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU Library General Public License as published
   by the Free Software Foundation; either version 2,or (at your option)
   any later version.
 
   This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
 
   You should have received a copy of the GNU Library General Public
   License along with this program; if not,write to the Free Software
   Foundation,USA.  */
 
/* Written by Bruno Haible <bruno@clisp.org>.  */
 
#include <config.h>
 
/* Specification.  */
#include "localcharset.h"
 
#include <fcntl.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
#if defined __APPLE__ && defined __MACH__ && HAVE_LANGINFO_CODESET
# define DARWIN7 /* Darwin 7 or newer,i.e. MacOS X 10.3 or newer */
#endif
 
#if defined _WIN32 || defined __WIN32__
# define WIN32_NATIVE
#endif
 
#if defined __EMX__
/* Assume EMX program runs on OS/2,even if compiled under DOS.  */
# ifndef OS2
#  define OS2
# endif
#endif
 
#if !defined WIN32_NATIVE
# include <unistd.h>
# if HAVE_LANGINFO_CODESET
#  include <langinfo.h>
# else
#  if 0 /* see comment below */
#   include <locale.h>
#  endif
# endif
# ifdef __CYGWIN__
#  define WIN32_LEAN_AND_MEAN
#  include <windows.h>
# endif
#elif defined WIN32_NATIVE
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
#if defined OS2
# define INCL_DOS
# include <os2.h>
#endif
 
#if ENABLE_RELOCATABLE
# include "relocatable.h"
#else
# define relocate(pathname) (pathname)
#endif
 
/* Get LIBDIR.  */
#ifndef LIBDIR
# include "configmake.h"
#endif
 
/* Define O_nofollow to 0 on platforms where it does not exist.  */
#ifndef O_nofollow
# define O_nofollow 0
#endif
 
#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
  /* Win32,Cygwin,OS/2,DOS */
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
#endif
 
#ifndef DIRECTORY_SEPARATOR
# define DIRECTORY_SEPARATOR '/'
#endif
 
#ifndef ISSLASH
# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
#endif
 
#if HAVE_DECL_GETC_UNLOCKED
# undef getc
# define getc getc_unlocked
#endif
 
/* The following static variable is declared 'volatile' to avoid a
   possible multithread problem in the function get_charset_aliases. If we
   are running in a threaded environment,and if two threads initialize
   'charset_aliases' simultaneously,both will produce the same value,and everything will be ok if the two assignments to 'charset_aliases'
   are atomic. But I don't know what will happen if the two assignments mix.  */
#if __STDC__ != 1
# define volatile /* empty */
#endif
/* Pointer to the contents of the charset.alias file,if it has already been
   read,else NULL.  Its format is:
   ALIAS_1 '\0' CANONICAL_1 '\0' ... ALIAS_n '\0' CANONICAL_n '\0' '\0'  */
static const char * volatile charset_aliases;
 
/* Return a pointer to the contents of the charset.alias file.  */
static const char *
get_charset_aliases (void)
{
  const char *cp;
 
  cp = charset_aliases;
  if (cp == NULL)
    {
#if !(defined DARWIN7 || defined VMS || defined WIN32_NATIVE || defined __CYGWIN__)
      const char *dir;
      const char *base = "charset.alias";
      char *file_name;
 
      /* Make it possible to override the charset.alias location.  This is
         necessary for running the testsuite before "make install".  */
      dir = getenv ("CHARSETALIASDIR");
      if (dir == NULL || dir[0] == '\0')
        dir = relocate ("c");//chenhd 2014.02 modify (LIBDIR);
 
      /* Concatenate dir and base into freshly allocated file_name.  */
      {
        size_t dir_len = strlen (dir);
        size_t base_len = strlen (base);
        int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1]));
        file_name = (char *) malloc (dir_len + add_slash + base_len + 1);
        if (file_name != NULL)
          {
            memcpy (file_name,dir,dir_len);
            if (add_slash)
              file_name[dir_len] = DIRECTORY_SEPARATOR;
            memcpy (file_name + dir_len + add_slash,base,base_len + 1);
          }
      }
 
      if (file_name == NULL)
        /* Out of memory.  Treat the file as empty.  */
        cp = "";
      else
        {
          int fd;
 
          /* Open the file.  Reject symbolic links on platforms that support
             O_nofollow.  This is a security feature.  Without it,an attacker
             could retrieve parts of the contents (namely,the tail of the
             first line that starts with "* ") of an arbitrary file by placing
             a symbolic link to that file under the name "charset.alias" in
             some writable directory and defining the environment variable
             CHARSETALIASDIR to point to that directory.  */
          fd = open (file_name,O_RDONLY | (1 ? O_nofollow : 0));//(HAVE_WORKING_O_nofollow ? O_nofollow : 0));
          if (fd < 0)
            /* File not found.  Treat it as empty.  */
            cp = "";
          else
            {
              FILE *fp;
 
              fp = fdopen (fd,"r");
              if (fp == NULL)
                {
                  /* Out of memory.  Treat the file as empty.  */
                  close (fd);
                  cp = "";
                }
              else
                {
                  /* Parse the file's contents.  */
                  char *res_ptr = NULL;
                  size_t res_size = 0;
 
                  for (;;)
                    {
                      int c;
                      char buf1[50+1];
                      char buf2[50+1];
                      size_t l1,l2;
                      char *old_res_ptr;
 
                      c = getc (fp);
                      if (c == EOF)
                        break;
                      if (c == '\n' || c == ' ' || c == '\t')
                        continue;
                      if (c == '#')
                        {
                          /* Skip comment,to end of line.  */
                          do
                            c = getc (fp);
                          while (!(c == EOF || c == '\n'));
                          if (c == EOF)
                            break;
                          continue;
                        }
                      ungetc (c,fp);
                      if (fscanf (fp,"%50s %50s",buf1,buf2) < 2)
                        break;
                      l1 = strlen (buf1);
                      l2 = strlen (buf2);
                      old_res_ptr = res_ptr;
                      if (res_size == 0)
                        {
                          res_size = l1 + 1 + l2 + 1;
                          res_ptr = (char *) malloc (res_size + 1);
                        }
                      else
                        {
                          res_size += l1 + 1 + l2 + 1;
                          res_ptr = (char *) realloc (res_ptr,res_size + 1);
                        }
                      if (res_ptr == NULL)
                        {
                          /* Out of memory. */
                          res_size = 0;
                          free (old_res_ptr);
                          break;
                        }
                      strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1),buf1);
                      strcpy (res_ptr + res_size - (l2 + 1),buf2);
                    }
                  fclose (fp);
                  if (res_size == 0)
                    cp = "";
                  else
                    {
                      *(res_ptr + res_size) = '\0';
                      cp = res_ptr;
                    }
                }
            }
 
          free (file_name);
        }
 
#else
 
# if defined DARWIN7
      /* To avoid the trouble of installing a file that is shared by many
         GNU packages -- many packaging systems have problems with this --,simply inline the aliases here.  */
      cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
           "ISO8859-2" "\0" "ISO-8859-2" "\0"
           "ISO8859-4" "\0" "ISO-8859-4" "\0"
           "ISO8859-5" "\0" "ISO-8859-5" "\0"
           "ISO8859-7" "\0" "ISO-8859-7" "\0"
           "ISO8859-9" "\0" "ISO-8859-9" "\0"
           "ISO8859-13" "\0" "ISO-8859-13" "\0"
           "ISO8859-15" "\0" "ISO-8859-15" "\0"
           "KOI8-R" "\0" "KOI8-R" "\0"
           "KOI8-U" "\0" "KOI8-U" "\0"
           "CP866" "\0" "CP866" "\0"
           "CP949" "\0" "CP949" "\0"
           "CP1131" "\0" "CP1131" "\0"
           "CP1251" "\0" "CP1251" "\0"
           "eucCN" "\0" "GB2312" "\0"
           "GB2312" "\0" "GB2312" "\0"
           "eucJP" "\0" "EUC-JP" "\0"
           "eucKR" "\0" "EUC-KR" "\0"
           "Big5" "\0" "BIG5" "\0"
           "Big5HKSCS" "\0" "BIG5-HKSCS" "\0"
           "GBK" "\0" "GBK" "\0"
           "GB18030" "\0" "GB18030" "\0"
           "SJIS" "\0" "SHIFT_JIS" "\0"
           "ARMSCII-8" "\0" "ARMSCII-8" "\0"
           "PT154" "\0" "PT154" "\0"
         /*"ISCII-DEV" "\0" "?" "\0"*/
           "*" "\0" "UTF-8" "\0";
# endif
 
# if defined VMS
      /* To avoid the troubles of an extra file charset.alias_vms in the
         sources of many GNU packages,simply inline the aliases here.  */
      /* The list of encodings is taken from the OpenVMS 7.3-1 documentation
         "Compaq C Run-Time Library Reference Manual for OpenVMS systems"
         section 10.7 "Handling Different Character Sets".  */
      cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
           "ISO8859-2" "\0" "ISO-8859-2" "\0"
           "ISO8859-5" "\0" "ISO-8859-5" "\0"
           "ISO8859-7" "\0" "ISO-8859-7" "\0"
           "ISO8859-8" "\0" "ISO-8859-8" "\0"
           "ISO8859-9" "\0" "ISO-8859-9" "\0"
           /* Japanese */
           "eucJP" "\0" "EUC-JP" "\0"
           "SJIS" "\0" "SHIFT_JIS" "\0"
           "DECKANJI" "\0" "DEC-KANJI" "\0"
           "SDECKANJI" "\0" "EUC-JP" "\0"
           /* Chinese */
           "eucTW" "\0" "EUC-TW" "\0"
           "DECHANYU" "\0" "DEC-HANYU" "\0"
           "DECHANZI" "\0" "GB2312" "\0"
           /* Korean */
           "DECKOREAN" "\0" "EUC-KR" "\0";
# endif
 
# if defined WIN32_NATIVE || defined __CYGWIN__
      /* To avoid the troubles of installing a separate file in the same
         directory as the DLL and of retrieving the DLL's directory at
         runtime,simply inline the aliases here.  */
 
      cp = "CP936" "\0" "GBK" "\0"
           "CP1361" "\0" "JOHAB" "\0"
           "CP20127" "\0" "ASCII" "\0"
           "CP20866" "\0" "KOI8-R" "\0"
           "CP20936" "\0" "GB2312" "\0"
           "CP21866" "\0" "KOI8-RU" "\0"
           "CP28591" "\0" "ISO-8859-1" "\0"
           "CP28592" "\0" "ISO-8859-2" "\0"
           "CP28593" "\0" "ISO-8859-3" "\0"
           "CP28594" "\0" "ISO-8859-4" "\0"
           "CP28595" "\0" "ISO-8859-5" "\0"
           "CP28596" "\0" "ISO-8859-6" "\0"
           "CP28597" "\0" "ISO-8859-7" "\0"
           "CP28598" "\0" "ISO-8859-8" "\0"
           "CP28599" "\0" "ISO-8859-9" "\0"
           "CP28605" "\0" "ISO-8859-15" "\0"
           "CP38598" "\0" "ISO-8859-8" "\0"
           "CP51932" "\0" "EUC-JP" "\0"
           "CP51936" "\0" "GB2312" "\0"
           "CP51949" "\0" "EUC-KR" "\0"
           "CP51950" "\0" "EUC-TW" "\0"
           "CP54936" "\0" "GB18030" "\0"
           "CP65001" "\0" "UTF-8" "\0";
# endif
#endif
 
      charset_aliases = cp;
    }
 
  return cp;
}
 
/* Determine the current locale's character encoding,and canonicalize it
   into one of the canonical names listed in config.charset.
   The result must not be freed; it is statically allocated.
   If the canonical name cannot be determined,the result is a non-canonical
   name.  */
 
#ifdef STATIC
STATIC
#endif
const char *
locale_charset (void)
{
  const char *codeset;
  const char *aliases;
 
#if !(defined WIN32_NATIVE || defined OS2)
 
# if HAVE_LANGINFO_CODESET
 
  /* Most systems support nl_langinfo (CODESET) nowadays.  */
  codeset = nl_langinfo (CODESET);
 
#  ifdef __CYGWIN__
  /* Cygwin < 1.7 does not have locales.  nl_langinfo (CODESET) always
     returns "US-ASCII".  Return the suffix of the locale name from the
     environment variables (if present) or the codepage as a number.  */
  if (codeset != NULL && strcmp (codeset,"US-ASCII") == 0)
    {
      const char *locale;
      static char buf[2 + 10 + 1];
 
      locale = getenv ("LC_ALL");
      if (locale == NULL || locale[0] == '\0')
        {
          locale = getenv ("LC_CTYPE");
          if (locale == NULL || locale[0] == '\0')
            locale = getenv ("LANG");
        }
      if (locale != NULL && locale[0] != '\0')
        {
          /* If the locale name contains an encoding after the dot,return
             it.  */
          const char *dot = strchr (locale,'.');
 
          if (dot != NULL)
            {
              const char *modifier;
 
              dot++;
              /* Look for the possible @... trailer and remove it,if any.  */
              modifier = strchr (dot,'@');
              if (modifier == NULL)
                return dot;
              if (modifier - dot < sizeof (buf))
                {
                  memcpy (buf,dot,modifier - dot);
                  buf [modifier - dot] = '\0';
                  return buf;
                }
            }
        }
 
      /* Woe32 has a function returning the locale's codepage as a number:
         GetACP().  This encoding is used by Cygwin,unless the user has set
         the environment variable CYGWIN=codepage:oem (which very few people
         do).
         Output directed to console windows needs to be converted (to
         GetOEMCP() if the console is using a raster font,or to
         GetConsoleOutputCP() if it is using a TrueType font).  Cygwin does
         this conversion transparently (see winsup/cygwin/fhandler_console.cc),converting to GetConsoleOutputCP().  This leads to correct results,except when SetConsoleOutputCP has been called and a raster font is
         in use.  */
      sprintf (buf,"CP%u",GetACP ());
      codeset = buf;
    }
#  endif
 
# else
 
  /* On old systems which lack it,use setlocale or getenv.  */
  const char *locale = NULL;
 
  /* But most old systems don't have a complete set of locales.  Some
     (like SunOS 4 or DJGPP) have only the C locale.  Therefore we don't
     use setlocale here; it would return "C" when it doesn't support the
     locale name the user has set.  */
#  if 0
  locale = setlocale (LC_CTYPE,NULL);
#  endif
  if (locale == NULL || locale[0] == '\0')
    {
      locale = getenv ("LC_ALL");
      if (locale == NULL || locale[0] == '\0')
        {
          locale = getenv ("LC_CTYPE");
          if (locale == NULL || locale[0] == '\0')
            locale = getenv ("LANG");
        }
    }
 
  /* On some old systems,one used to set locale = "iso8859_1". On others,you set it to "language_COUNTRY.charset". In any case,we resolve it
     through the charset.alias file.  */
  codeset = locale;
 
# endif
 
#elif defined WIN32_NATIVE
 
  static char buf[2 + 10 + 1];
 
  /* Woe32 has a function returning the locale's codepage as a number:
     GetACP().
     When the output goes to a console window,it needs to be provided in
     GetOEMCP() encoding if the console is using a raster font,or in
     GetConsoleOutputCP() encoding if it is using a TrueType font.
     But in GUI programs and for output sent to files and pipes,GetACP()
     encoding is the best bet.  */
  sprintf (buf,GetACP ());
  codeset = buf;
 
#elif defined OS2
 
  const char *locale;
  static char buf[2 + 10 + 1];
  ULONG cp[3];
  ULONG cplen;
 
  /* Allow user to override the codeset,as set in the operating system,with standard language environment variables.  */
  locale = getenv ("LC_ALL");
  if (locale == NULL || locale[0] == '\0')
    {
      locale = getenv ("LC_CTYPE");
      if (locale == NULL || locale[0] == '\0')
        locale = getenv ("LANG");
    }
  if (locale != NULL && locale[0] != '\0')
    {
      /* If the locale name contains an encoding after the dot,return it.  */
      const char *dot = strchr (locale,'.');
 
      if (dot != NULL)
        {
          const char *modifier;
 
          dot++;
          /* Look for the possible @... trailer and remove it,if any.  */
          modifier = strchr (dot,'@');
          if (modifier == NULL)
            return dot;
          if (modifier - dot < sizeof (buf))
            {
              memcpy (buf,modifier - dot);
              buf [modifier - dot] = '\0';
              return buf;
            }
        }
 
      /* Resolve through the charset.alias file.  */
      codeset = locale;
    }
  else
    {
      /* OS/2 has a function returning the locale's codepage as a number.  */
      if (DosQueryCp (sizeof (cp),cp,&cplen))
        codeset = "";
      else
        {
          sprintf (buf,cp[0]);
          codeset = buf;
        }
    }
 
#endif
 
  if (codeset == NULL)
    /* The canonical name cannot be determined.  */
    codeset = "";
 
  /* Resolve alias. */
  for (aliases = get_charset_aliases ();
       *aliases != '\0';
       aliases += strlen (aliases) + 1,aliases += strlen (aliases) + 1)
    if (strcmp (codeset,aliases) == 0
        || (aliases[0] == '*' && aliases[1] == '\0'))
      {
        codeset = aliases + strlen (aliases) + 1;
        break;
      }
 
  /* Don't return an empty string.  GNU libc and GNU libiconv interpret
     the empty string as denoting "the locale's character encoding",thus GNU libiconv would call this function a second time.  */
  if (codeset[0] == '\0')
    codeset = "ASCII";
 
  return codeset;
}
7、然后 在iocnv下面搜索config.h,然后会搜到3个 config.h.in, 将3个文件的.in去掉。(原因是 交叉编译时有一个问题, config.h找不到, 原因是库里面所以的config.h文件名都是config.h.in

然后就可以run as了

Android版本效果图:



点击下载源码及资源


参考资源:

http://blog.csdn.net/u012945598/article/details/17000585

http://blog.csdn.net/u012945598/article/details/17037871


字体地址:http://font.niutuku.com/font/9.shtml

中文显示问题,格式转换:http://www.2cto.com/kf/201404/295851.html

中文显示问题,加载xml:http://blog.csdn.net/zhy_cheng/article/details/9736973

Actions类:http://cn.cocos2d-x.org/doc/cocos2d-x-3.0/db/d61/classcocos2d_1_1_action.html

OrbitCamera的用法:http://www.xue163.com/179/6/1794554.html

原文链接:https://www.f2er.com/cocos2dx/345149.html

猜你在找的Cocos2d-x相关文章