Hi guys. I need a bit of help, migrating into Cocos2d-x is a little bit different from what I expected.
So first this is what I need to accomplish. Align a bunch of CCSprites at the bottom of the screen (centered).
Now first CCDirector winsize is not returning the expected size on iPhone. I know this is because of resoultion independecy so design resoultion is what will be returned. So I used this code to retrieve the windows:
CCPoint visibleOrigin = CCDirector::sharedDirector()
CCSize visibleSize = CCDirector::sharedDirector
Then centering is done in the following way:
float spritesWidth = 0;
std::string spriteFileName ;
CCSprite *mySprite = CCSprite::create);
//Keep reference to sprites
spritesWidth = mySprite~~>getContentSize.width;
//Scale down sprites if they are bigger than screen
float factor = 1;
//80 is an offset to make it look good
factor = /lettersWidth;
spritesWidth = factor;
>setScale;>setPosition.size.height / 2)));
//Centered sprites new origin
float centeredXOrigin = + visibleOrigin.x;
CCSpritemySprite = object;
This is not working, not sure why. Some sprites are overlapping and they are not centered correctly.
What I’m trying to do is simply add all sprite widths, then scale them and position accordingly. However the visibleOrigin and visibleSize are really confusing me. In fact, resolution independency mechanism confuses me as well. Should I use contentSize or boundingBox? Will it return the size of appropriate file (iPhone,iPad…retina?). Or it will always return the design size?
Need a little bit of explanation and help here. I’m just starting with Cocos2d-x
Thanks a lot.