如何使用 c++ 在 cocos2d-x ios 游戏中使用 json 进行缩放

How to do scaling while using json in cocos2d-x ios game using c++

本文关键字:json 缩放 游戏 c++ 何使用 cocos2d-x ios      更新时间:2023-10-16

我正在使用cocostudio并从中导出一个场景,其中它导出了一个.plist,.png和一个.json文件。该场景在iPhone Retina 3.5英寸中工作正常,但在iPad和iPhone中缩放并不完美。如何在使用 .json 和导入不同设备的完整场景时控制缩放在我正在编写的初始化函数中

CCNode *pFishJoyScene = SceneReader::sharedSceneReader()->createNodeWithSceneFile("FishJoy2.json");
this->addChild(pFishJoyScene);             
cocos2d::extension::ActionManager::shareManager()->playActionByName("startMenu_1.json","Animation1"); 

早些时候我曾经使用CCSize winsize=CCDirector::sharedDirector()->getwinSize();。在使用它时,我曾经缩放所有的东西。

但是对于 json,我们不需要写这个,因为我们正在 cocostudio 中创建场景。请告诉我如何在使用 .json 时控制不同设备中的缩放

我从中获取了示例示例https://github.com/chukong/CocoStudioSamples

我运行了上面示例中名为 DemoFishing joy 的项目。如果您在不同的设备中运行此示例项目,则会导致缩放问题。请帮忙

I hope this will help you.for scaling in skeletonAnimation setScaleX() and setScaleY() are used 
      CCSkeletonAnimation* skeletonAnimRun = CCSkeletonAnimation::createWithFile("horse.json", "horse.atlas");
            skeletonAnimRun->setAnimation("run", true);
            skeletonAnimRun->timeScale = 1.0f;
            skeletonAnimRun->setScaleX(.2f);
            skeletonAnimRun->setScaleY(.2f);
            skeletonAnimRun->setPosition(x/5, y/2);
            skeletonAnimRun->setSkin("black");
            skeletonAnimRun->setSlotsToSetupPose();
            addChild(skeletonAnimRun,10);

答案是,无论我拍摄什么场景还是任何东西,我都会在节点中获取。只需扩展节点,一切都会变得完美。例如

CCNode *pFishJoyScene = SceneReader::sharedSceneReader()->createNodeWithSceneFile("FishJoy2.json");
this->addChild(pFishJoyScene);
cocos2d::extension::ActionManager::shareManager()->playActionByName("startMenu_1.json","Animation1");
CCSprite *bg=CCSprite::create("startMenuBG.png");
float rX=winSize.width/bg->getContentSize().width;
float rY = winSize.height/bg->getContentSize().height;

pFishJoyScene->setScaleX(rX);
pFishJoyScene->setScaleY(rY);

然后,您将在任何设备中看到它工作完美