You don’t really need to do all this
You just need to setup your game’s designed resolution and the adaptation policy, cocos2d will do all the work for you. In the code, you always work with your designed resolution.
For example, you have a game to be designed with 480 * 360 as resolution, and you want a background sprite which show full screen,
Firstly, you need to setup your designed resolution and the adaptation policy in the “applicationDidFinishLaunching” function:
cc.EGLView.getInstance().setDesignResolutionSize(480, 360, cc.RESOLUTION_POLICY.SHOW_ALL);
cc.RESOLUTION_POLICY.SHOW_ALL is the adaptation policy which means you want your game to be always scaled to the screen size and keep the width / height ratio.
Then you need to write your sprite like this way.
this.sprite = cc.Sprite.create(s_HelloWorld);
this.sprite.setPosition(cc.p(480 / 2, 360 / 2));
You see, you don’t need to know the screen size or the navigator size, what’s important is the resolution you designed.
Then in your game, this Hello world sprite will be automatically scaled.
This is just a brief talk about how you can achieve this, you probably need to read more in this article: http://www.cocos2d-x.org/wiki/Detailed\_explanation\_of\_Cocos2d-x\_Multi-resolution\_adaptation