天道酬勤,学无止境

cocos2d-x-2.x

如何在 cocos2d-x 中调整动画精灵的大小(How to resize the the animating sprite in cocos2d-x)

问题 我想更改正在动画的 Sprite 的大小。 我怎样才能做到这一点 ? 我试图通过使用 setScale 属性来改变它的大小,但它在这里不起作用。 我在哪里做错了? CCArray* frames = CCArray::createWithCapacity(3); CCSpriteFrameCache* frameCache = CCSpriteFrameCache::sharedSpriteFrameCache(); char file[100] = {0}; for (int i = 0; i < 3; i++) { sprintf(file, "bird%d.png", i); CCSpriteFrame* frame = frameCache->spriteFrameByName(file); frames->addObject(frame); } CCAnimation* animation = CCAnimation::createWithSpriteFrames(frames, 0.1); CCAnimate* animate = CCAnimate::create(animation); CCRepeatForever* repeat = CCRepeatForever::create(animate); bird->runAction(repeat)

2022-02-14 16:19:57    分类:技术分享    cocos2d-x   ccsprite   ccspritebatchnode   cocos2d-x-2.x

How to resize the the animating sprite in cocos2d-x

I want to change the size of a Sprite which is animating. How can I do this ? I tried to change its size by using setScale property but it is not working here. where I am doing wrong ? CCArray* frames = CCArray::createWithCapacity(3); CCSpriteFrameCache* frameCache = CCSpriteFrameCache::sharedSpriteFrameCache(); char file[100] = {0}; for (int i = 0; i < 3; i++) { sprintf(file, "bird%d.png", i); CCSpriteFrame* frame = frameCache->spriteFrameByName(file); frames->addObject(frame); } CCAnimation* animation = CCAnimation::createWithSpriteFrames(frames, 0.1); CCAnimate* animate = CCAnimate::create

2022-02-14 13:04:02    分类:问答    cocos2d-x   ccsprite   ccspritebatchnode   cocos2d-x-2.x

使用 rapidjson 从 json 文件中获取数组数据(get array data from json file using rapidjson)

问题 我是 rapidjson 的新手。 我有test.json其中包含{"points": [1,2,3,4]} 我使用以下代码获取数组"points"的数据 std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename("json/deluxe/treasurebag.json"); unsigned long bufferSize = 0; const char* mFileData = (const char*)CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(), "r", &bufferSize); std::string clearData(mFileData); size_t pos = clearData.rfind("}"); clearData = clearData.substr(0, pos+1); document.Parse<0>(clearData.c_str()); assert(document.HasMember("points")); const Value& a = document["points"]; // Using a reference for consecutive

2022-01-15 07:31:37    分类:技术分享    c++   cocos2d-x-2.x   rapidjson

get array data from json file using rapidjson

I'm new in rapidjson. I have test.json which contains {"points": [1,2,3,4]} and I use following code to get data of array "points" std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename("json/deluxe/treasurebag.json"); unsigned long bufferSize = 0; const char* mFileData = (const char*)CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(), "r", &bufferSize); std::string clearData(mFileData); size_t pos = clearData.rfind("}"); clearData = clearData.substr(0, pos+1); document.Parse<0>(clearData.c_str()); assert(document.HasMember("points")); const Value& a = document[

2022-01-15 05:56:18    分类:问答    c++   cocos2d-x-2.x   rapidjson

cocos2dx 将图像保存到画廊 android(cocos2dx save image in to gallery android)

问题 我想截屏并将其保存在图库中。 我试过的: CCSize size = CCDirector::sharedDirector()->getWinSize(); CCRenderTexture* texture = CCRenderTexture::create((int)size.width, (int)size.height, kCCTexture2DPixelFormat_RGBA8888); texture->setPosition(ccp(size.width/2, size.height/2)); texture->begin(); CCDirector::sharedDirector()->getRunningScene()->visit(); texture->end(); texture->saveToFile("scrshot.png", kCCImageFormatJPEG); 在 iOS 中它运行良好并且能够将图像保存到文档中,但问题出在 android 中: 有两种可能 1) 纹理->saveToFile("scrshot.png", kCCImageFormatJPEG); 或纹理->saveToFile("我的路径"); -> 它编译但图像保存在哪里? 2)使用JNI保存Bitmap文件-

2022-01-12 14:58:57    分类:技术分享    android   bitmap   cocos2d-x-2.x

cocos2dx save image in to gallery android

I want to take screenshots and save it in the gallery. What I have tried: CCSize size = CCDirector::sharedDirector()->getWinSize(); CCRenderTexture* texture = CCRenderTexture::create((int)size.width, (int)size.height, kCCTexture2DPixelFormat_RGBA8888); texture->setPosition(ccp(size.width/2, size.height/2)); texture->begin(); CCDirector::sharedDirector()->getRunningScene()->visit(); texture->end(); texture->saveToFile("scrshot.png", kCCImageFormatJPEG); in iOS it is working perfectly and am able to save image in to documents, but the problem is in android : There are two possibilities 1)

2022-01-10 10:55:39    分类:问答    android   bitmap   cocos2d-x-2.x

Cocos2D-x 示例应用程序在启动时崩溃(Cocos2D-x sample application crashes on launch)

问题 我尝试使用 Readme.md 文件中所述的命令行界面在我的 Android 设备上构建 Cocos2D-x testCpp 示例项目 (Cocos2D-x 2.2.2): $ cd cocos2d-x/samples/Cpp/TestCpp/proj.android/ $ export NDK_ROOT=/path/to/ndk $ ./build_native.sh $ ant debug install 如果最后一个命令导致 sdk.dir 丢失错误,请执行以下操作: $ android list target $ android update project -p . -t (id from step 6) $ android update project -p cocos2d-x/cocos2dx/platform/android/java/ -t (id from step 6) 我可以在我的设备 (Galaxy S4) 上安装该应用程序,但该应用程序在启动后立即崩溃,告诉我该应用程序已停止。 知道我能做些什么来解决这个问题吗? 我不确定如何在 CLI 中使用 logcat,所以我使用 eclipse 启动示例应用程序(这里的错误是相同的:应用程序在启动后崩溃)并发布 eclipse 显示的 logcat 信息: 03-19 10:49:22.785: W

2021-08-30 08:40:07    分类:技术分享    android   crash   cocos2d-x   cocos2d-x-2.x

Cocos2D-x sample application crashes on launch

I tried to build the Cocos2D-x testCpp sample project (Cocos2D-x 2.2.2) on my Android device using the command line interface as described in the Readme.md file: $ cd cocos2d-x/samples/Cpp/TestCpp/proj.android/ $ export NDK_ROOT=/path/to/ndk $ ./build_native.sh $ ant debug install If the last command results in sdk.dir missing error then do: $ android list target $ android update project -p . -t (id from step 6) $ android update project -p cocos2d-x/cocos2dx/platform/android/java/ -t (id from step 6) I can install the app on my device (Galaxy S4) but the application crashes immediately after

2021-06-28 05:02:36    分类:问答    android   crash   cocos2d-x   cocos2d-x-2.x

将Xcode更新为5.1(5B130a)时,EAGLView.mm中出现错误“从指针投射到较小类型'int'的信息丢失”(Error “Cast from pointer to smaller type 'int' loses information” in EAGLView.mm when update Xcode to 5.1 (5B130a))

问题 昨天,我将Xcode更新为最新版本(5.1 (5B130a))以与iOS 7.1兼容。 然后建立我的项目,当64位模拟器(例如:iPhone Retina 4英寸64位) EAGLView.mm在EAGLView.mm文件( line 408 )中出现错误"Cast from pointer to smaller type 'int' loses information" ( line 408 )已选择。 我正在使用cocos2d-x-2.2.2 。 在更新Xcode之前,我的项目仍可以在所有设备上正常构建和运行。 感谢您的所有建议。 更新:今天,我下载了最新版本的cocos2d-x(cocos2d-x 2.2.3)。 但是问题仍然存在。 这是发生错误的一些代码: /cocos2d-x-2.2.2/cocos2dx/platform/ios/EAGLView.mm:408:18: Cast from pointer to smaller type 'int' loses information // Pass the touches to the superview #pragma mark EAGLView - Touch Delegate - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

2021-04-30 17:07:38    分类:技术分享    iphone   xcode5   cocos2d-x   ios7.1   cocos2d-x-2.x

Error “Cast from pointer to smaller type 'int' loses information” in EAGLView.mm when update Xcode to 5.1 (5B130a)

Yesterday, I updated Xcode to the newest version (5.1 (5B130a)) to compatible with iOS 7.1. Then I build my project, I get the error "Cast from pointer to smaller type 'int' loses information" in EAGLView.mm file (line 408) when 64-bit simulators (e.g.: iPhone Retina 4-inch 64-bit) is selected. I'm using cocos2d-x-2.2.2. Before I update Xcode, my project still can build and run normally with all devices. Thanks for all recommendation. Update: Today, i download the latest version of cocos2d-x (cocos2d-x 2.2.3). But the problem has still happened. Here is some piece of code where that error

2021-04-14 04:47:21    分类:问答    iphone   xcode5   cocos2d-x   ios7.1   cocos2d-x-2.x