Multi resolution help needed

  • mihir77
    Likes 0

    Problem Description

    Hi its mihir..

    Attaching the images for labels for compating on iphones and ipads as discussed on cocos forum..http://discuss.cocos2d-x.org/t/multi-resolution-help-needed/38960

    iphone’s screen shot – 

    ipad’s screenshot – lookis like this on ipad to ipad retina

     

    Heres the code for labels – 

     

       water = Label::createWithTTF("line number one", "fonts/Bariol_Regular.otf",  38 );
    water->setColor(Color3B(150,101,68));
    
    water->setPosition( Vec2(visibleSize.width /2 + origin.x, st->getPositionY()-st->getContentSize().height /2 - water->getContentSize().height /2 + origin.y) );
    
    this->addChild(water);
    
    
    food = Label::createWithTTF("line number two", "fonts/Bariol_Regular.otf",  38 );
    food->setColor(Color3B(150,101,68));
    
    food->setPosition( Vec2(visibleSize.width /2 + origin.x, water->getPositionY()-water->getContentSize().height/2 - food->getContentSize().height /2 + origin.y) );
    
    this->addChild(food);

     Can you please show me how to solve this error..Thanks a lot for tutorial..

  • Sonar Systems admin
    Likes 0

    Change the following line from:

    food->setPosition( Vec2(visibleSize.width /2 + origin.x, water->getPositionY()-water->getContentSize().height/2 - food->getContentSize().height /2 + origin.y) );
    
    to
    food->setPosition( Vec2(visibleSize.width /2 + origin.x, water->getPositionY()+water->getContentSize().height/2 + food->getContentSize().height /2 + origin.y) );
    
     
  • mihir77
    Likes 0

    Hi i added reply on cocos forum..can u please check...http://discuss.cocos2d-x.org/t/multi-resolution-help-needed/38960/14

  • Sonar Systems admin
    Likes 0

    Replied


    This reply has been verified.
  • mihir77
    Likes 0

    It is positioning corrent in all iphones and wrong in all ipad's. I tried the same code in new project and it shows correct in iphones as well as ipad.  so i think there is some error in appdelegate..my appdelegate code is the multi res 2.0 code....can u please check..

    here is the code - 

      

       auto one = Label::createWithTTF("Line one", "fonts/Bariol_Regular.otf",  38 );
        one->setColor(Color3B(150,101,68));
        one->setPosition( Vec2(visibleSize.width/2 + origin.x,  visibleSize.height - one->getContentSize().height + origin.y) );
        this->addChild(one);
        
        auto two = Label::createWithTTF("Line two", "fonts/Bariol_Regular.otf",  38 );
        two->setColor(Color3B(150,101,68));
        two->setPosition( Vec2(visibleSize.width /2 + origin.x, one->getPositionY() - one->getContentSize().height /2 - two->getContentSize().height/2  + origin.y) );
        this->addChild( two);
        
           auto three = Label::createWithTTF("Line three", "fonts/Bariol_Regular.otf",  38 );
            three->setColor(Color3B(150,101,68));
            three->setPosition( Vec2(visibleSize.width /2 + origin.x, two->getPositionY()-two->getContentSize().height /2 - three->getContentSize().height /2 + origin.y) );
            this->addChild(three);
            
            
           auto four = Label::createWithTTF("Line four", "fonts/Bariol_Regular.otf",  38 );
            four->setColor(Color3B(150,101,68));
            four->setPosition( Vec2(visibleSize.width/2 + origin.x, three->getPositionY() - three->getContentSize().height/2 - four->getContentSize().height /2 + origin.y) );
            this->addChild(four);
            
            
           auto five = Label::createWithTTF("Line five", "fonts/Bariol_Regular.otf",  38 );
            five->setColor(Color3B(150,101,68));
            five->setPosition( Vec2(visibleSize.width/2 + origin.x, four->getPositionY() - four->getContentSize().height/2 - five->getContentSize().height /2 + origin.y) );
            this->addChild(five);

    it looks like this in iphone's and ipad's..

    I tried the same code in new project and it looks same in both iphone and ipads

    Here is my appdelegate as in multi res 2.0 tutorial..

     #include "AppDelegate.h"
        #include "HelloWorldScene.h"
    
    
        USING_NS_CC;
    
        // comment out for a portrait game
        //#define IS_LANDSCAPE
    
        #ifdef IS_LANDSCAPE
        static cocos2d::Size designResolutionSize = cocos2d::Size(1136, 768);
        #else
        static cocos2d::Size designResolutionSize = cocos2d::Size(768, 1136);
        #endif
    
        AppDelegate::AppDelegate() {
            
        }
    
        AppDelegate::~AppDelegate()
        {
        }
    
        //if you want a different context,just modify the value of glContextAttrs
        //it will takes effect on all platforms
        void AppDelegate::initGLContextAttrs()
        {
            //set OpenGL context attributions,now can only set six attributions:
            //red,green,blue,alpha,depth,stencil
            GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
            
            GLView::setGLContextAttrs(glContextAttrs);
        }
    
        // If you want to use packages manager to install more packages,
        // don't modify or remove this function
        static int register_all_packages()
        {
            return 0; //flag for packages manager
        }
    
        bool AppDelegate::applicationDidFinishLaunching() {
            // initialize director
            auto director = Director::getInstance();
            auto glview = director->getOpenGLView();
            if(!glview) {
                glview = GLViewImpl::create("Fun Trees");
                director->setOpenGLView(glview);
            }
            
            // turn on display FPS
            director->setDisplayStats(true);
            
            // set FPS. the default value is 1.0/60 if you don't call this
            director->setAnimationInterval(1.0 / 60);
            
            // Set the design resolution
            glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
            
            
            
            register_all_packages();
           
            auto scene = HelloWorld::createScene();
           
    
            director->runWithScene(scene);
            
            return true;
        }
    
        // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
        void AppDelegate::applicationDidEnterBackground() {
            Director::getInstance()->stopAnimation();
            
            // if you use SimpleAudioEngine, it must be pause
            // SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
        }
    
        // this function will be called when the app is active again
        void AppDelegate::applicationWillEnterForeground() {
            Director::getInstance()->startAnimation();
            
            // if you use SimpleAudioEngine, it must resume here
            // SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
        }

    Can you please check, really stuck here..


  • Sonar Systems admin
    Likes 0

    Is this a landscape application?


    This reply has been verified.
  • mihir77
    Likes 0

    no, its portrait application..

  • mihir77
    Likes 0

    Everything works fine with multi res tutorial, just trying to put labels one after another, it overlaps in all ipad’s..Can you please check..


  • Sonar Systems admin
    Likes 0

    Try positioning 2 other items like a square sprite and see if the same happens?

  • mihir77
    Likes 0

     

    Yes the same thing happens..

    here is the screenshot

    https://drive.google.com/file/d/0B0g4BClYR8Z6QjRWQU1HZmkteDQ/view?usp=sharing

     


  • Sonar Systems admin
    Likes 0

    Even with sprites?

  • mihir77
    Likes 0

    yes sprites as well..

  • Sonar Systems admin
    Likes 0

    Can you show me please.

  • mihir77
    Likes 0

    Here is the screenshot of both – iphone and ipad

     

     

    https://drive.google.com/file/d/0B0g4BClYR8Z6ck5ZTHUxNElrT0k/view?usp=sharing

    https://drive.google.com/file/d/0B0g4BClYR8Z6QVdNQ1ZremxxaVU/view?usp=sharing

     

    This is the code – 

        bSprite = Sprite::create("menuback.png");
        bSprite->setPosition(Point(visibleSize.width - bSprite->getContentSize().width/2 + origin.x, visibleSize.height - bSprite->getContentSize().height/2+ origin.y));
        this->addChild(bSprite,1);
        
        auto aSprite = Sprite::create("profile.png");
        aSprite->setPosition(Point(visibleSize.width - bSprite->getContentSize().width/2 + origin.x, bSprite->getPositionY() - bSprite->getContentSize().height/2 - aSprite->getContentSize().height/2 + origin.y));
        this->addChild(aSprite,1);

     


  • Sonar Systems admin
    Likes 0

    I cant quite understand why this is happening, if you let me know your Skype ID we can jump on skype and I will help you resolve this.

  • mihir77
    Likes 0

    Yeah sure..My id is – mihirthakur7

    Please call or msg me anytime..


    This reply has been verified.
  • Sonar Systems admin
    Likes 0

    I have added you.

  • mihir77
    Likes 0

    Thanks for helping me out with the issue over skype call..

    Solution for others –  Do not add origin.y, if you are positioning the object in reference to previous object.


    This reply has been verified.
  • Sonar Systems admin
    Likes 0

    :D                     

Login to reply