cocos2d-x

cocos2d-x 3.3 显示中文

佐手、 提交于 2020-01-10 18:56:02
Resources文件夹下的strings.xml: <dict> <key>targetScore</key> <string>目标分数</string> </dict> 保存为UTF-8编码格式。 c++代码: log("目标分数");//输出:?????? ValueMap valueMap=FileUtils::getInstance()->getValueMapFromFile("strings.xml"); std::string str=valueMap.at("targetScore").asString(); log(str.c_str());//输出:目标分数 Label* label=Label::createWithTTF(str.c_str(),"fonts/jianzhi.ttf",50); label->setPosition(Vec2(200,200)); addChild(label); 关于ttf字体的精简看文章 http://www.cnblogs.com/kingBook/p/5512784.html 来源: https://www.cnblogs.com/kingBook/p/5531353.html

(2)Cocos2d-x中文显示

前提是你 提交于 2020-01-10 07:48:11
  Cocos使用UTF8编码来处理文字, 要显示中文需要将中文转换为UTF8编码,这里使用xml来保存文字资源。 StringResources_zh.xml <?xml version="1.0" encoding="UTF-8"?> <plist version="1.0"> <dict> <key>hello_world</key> <string>你好,世界!</string> </dict> </plist> StringResourcesManager.h 1 #ifndef StringResourcesManager_h__ 2 #define StringResourcesManager_h__ 3 #include "cocos2d.h" 4 USING_NS_CC; 5 6 class StringResourcesManager 7 { 8 public: 9 static StringResourcesManager* GetInstance() 10 { 11 if (Instance == NULL) 12 { 13 Instance = new StringResourcesManager(); 14 } 15 return Instance; 16 } 17 18 std::string GetString(const std::string&

How to setup cocos2x console tool path?

旧街凉风 提交于 2020-01-07 07:41:41
问题 I setup cocos2d-x as outlines here: http://www.codeproject.com/Articles/801093/Writing-Games-with-Cplusplus-for-Android-on-a-Mac Setup.py had all the expected output, ./setup.py Setting up cocos2d-x... ->Check environment variable COCOS_CONSOLE_ROOT ->Search for environment variable COCOS_CONSOLE_ROOT... ->COCOS_CONSOLE_ROOT is found : /Users/john/Documents/Projects/Cocos2d/cocos2d-x-3.5/tools/cocos2d-console/bin ->Check environment variable COCOS_TEMPLATES_ROOT ->Search for environment

Cocos2d-x creating an object based upon CCLayerColor

时光怂恿深爱的人放手 提交于 2020-01-06 21:06:03
问题 Cocos2d-x 2.1rc0 OS X 10.8, XCode 4.6.2 Playing around with the HellowWorld with Box2D example to gain some concepts. Creating an class that is an extension of CCLayerColor. Previously, before I created a separate object I was doing: // background CCLayerColor *background = CCLayerColor::create(cGhostWhite); background->setContentSize(CCSizeMake(1024, 768)); background->setPosition(0,0); this->addChild(background,0); This worked. After trying to create my own object I am getting and error:

Can't use effects in Cocos2d-x 3.0 alpha 2

删除回忆录丶 提交于 2020-01-06 09:59:05
问题 Using of any effect for any sprite/layer/scene always causes this assertion in CCActionScript.cpp: void GridAction::cacheTargetAsGridNode() { _gridNodeTarget = dynamic_cast<NodeGrid*> (_target); CCASSERT(_gridNodeTarget, "GridActions can only used on NodeGrid"); } So, this code won't work because of Sprite or any other primitive are inherited from Node (not from NodeGrid). In other words, sample application won't work too: CCSprite* sp = CCSprite::create("title.jpg"); sp->setPosition(ccp(240,

Call an Objective-C function from C++ library code

时光怂恿深爱的人放手 提交于 2020-01-06 07:46:07
问题 I'd like to call a Obj-C function from my C++ code, in order to invoke a ShareKit call from a game engine. How do I perform the Obj-C function call? I'm using Cocos2d-x. 回答1: Use Objective-C++. To do that, you make a C++ file with the extension “.mm”. Within that file, both Objective-C and C++ syntax are valid, so you can #import your Objective-C headers and send messages using the [] syntax. 来源: https://stackoverflow.com/questions/24636264/call-an-objective-c-function-from-c-library-code

Object Pools in Cocos2D-X v3.0 Final - Deprecated CCArray

泪湿孤枕 提交于 2020-01-06 04:12:05
问题 In the search for true randomness using cocos2d-X, without the need of excessive conditionals; the algorithm of interest utilizes 2 CCArray(s) to allocate and combine functions on two different object pools. We Create a 'pool' for an object 'leather' and 'leatherSelection'. We Overwrite CCSprite with a custom class named 'SaddleManifold' /** On the header, using deprecated Cocos2D-x define an array of 'leather' types. CCArray * _leather; CCArray * _leatherSelection; The use of CCArray is

UnsatisfiedLinkError couldn't load game - cocos2d-x on Android

送分小仙女□ 提交于 2020-01-03 17:49:52
问题 I am trying to create a new cocos2d-x Project for Android and followed the following tutorial: Cocos2d-x Android Integration At the end, I get an error when I try to run the application stating: 10-14 21:52:37.510: E/AndroidRuntime(1568): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load game: findLibrary returned null The "game" library is loaded from the generated activity: System.loadLibrary("game"); But there isn't anything in my project as game.so. I only have libgame.so What

Using CREATE_FUNC in Cocos2dx

给你一囗甜甜゛ 提交于 2020-01-03 16:01:43
问题 Can anyone explain me why do we need to use CREATE_FUNC in Cocos2dx? I saw it in the HelloWorld samples and don't understand it clearly. Please, tell me more detail. Thanks. 回答1: We don't need to use it, it is a helper macro which expands to this : /** * define a create function for a specific type, such as CCLayer * @__TYPE__ class type to add create(), such as CCLayer */ #define CREATE_FUNC(__TYPE__) static __TYPE__* create() { __TYPE__ *pRet = new(std::nothrow) __TYPE__(); if (pRet && pRet

Using CREATE_FUNC in Cocos2dx

巧了我就是萌 提交于 2020-01-03 16:00:34
问题 Can anyone explain me why do we need to use CREATE_FUNC in Cocos2dx? I saw it in the HelloWorld samples and don't understand it clearly. Please, tell me more detail. Thanks. 回答1: We don't need to use it, it is a helper macro which expands to this : /** * define a create function for a specific type, such as CCLayer * @__TYPE__ class type to add create(), such as CCLayer */ #define CREATE_FUNC(__TYPE__) static __TYPE__* create() { __TYPE__ *pRet = new(std::nothrow) __TYPE__(); if (pRet && pRet