[SOLVED] Coordinates on a full screen NO BORDER

Hi, I am using Cocos2d-JS v3.7 and building a Cocos game for mobile only. I have set my ResolutionPolicy to NO_BORDER.

I have a button positioned cc.p(10, 10) and anchor set to (0, 0) so the button shows in the bottom left corner of the screen. With SHOW_ALL policy, the buttons has exactly 10 point spacing/padding from the edges however with NO_BORDER the button gets moved to outside the screen boundaries. This is expected because NO_BORDER expands the windowSize to fill in the entire screen space.

So my question is how do I get the bottom left corner coordinates of the physical screen space of the phone that the game is running on? I would like to know how to position my button 10 points from the bottom/left edges of the physical screen.

I have tried using getVisibilitySize() instead of getWindowSize() which I think works but then the Android buttons (back/home/running apps) offset the entire screen of the game. Is there a way with Cocos to make my game truly full screen?

You have to position sprites like this if you are using NO_BORDER

_visibleSize = cocos2d::Director::getInstance()->getVisibleSize();
_origin = cocos2d::Director::getInstance()->getVisibleOrigin();

_background->setPosition(_origin.x + _visibleSize.width / 2, _origin.y + _visibleSize.height);

Basically you need to add origin to position you want.

2 Likes

Awesome, thanks man.
That’s exactly what I needed. I knew about the getVisibleSize() but I didn’t know about the getVisibleOrigin(). I was wondering why everything was shifted on my screen.

Thanks again :smile: