Search code examples
c++jsoncocos2d-x

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


I am using cocostudio and exporting a scene from it where it exports a .plist ,.png and a .json file.The scene is working fine in iphone retina 3.5 inch but the scaling is not perfect in ipad and iphone.How to we control scaling while using .json and importing a complete scene uin diffrent devices in the init function I am writing

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

Earlier I used to use CCSize winsize=CCDirector::sharedDirector()->getwinSize();.While using this I used to scale all the things.

But in case of json we dont need to write this as we are creating a scene in cocostudio.Please tell me how to control the scaling in different devices while using .json

I have taken sample examples from https://github.com/chukong/CocoStudioSamples

I run a project named in the above sample DemoFishingjoy.If you run this sample project in different devices it will lead to scaling problems.Please help


Solution

  • Well the answer is that whatever i take whether its a scene or anything i take it in a node.Just scale the node and everything will be perfect.For example

    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);
    

    Then you will see in any device that it works perfect