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()>getVisibleOrigin;>getVisibleSize;
CCSize visibleSize = CCDirector::sharedDirector
Then centering is done in the following way:
float spritesWidth = 0;
for
{
std::string spriteFileName ;
CCSprite *mySprite = CCSprite::create);
//Keep reference to sprites
spritesArray~~>addObject;
spritesWidth = mySprite~~>getContentSize.width;
this~~>addChild;
}
//Scale down sprites if they are bigger than screen
float factor = 1;
//80 is an offset to make it look good
if {
factor = /lettersWidth;
spritesWidth = factor;
CCObjectoneSprite;
CCARRAY_FOREACH
{
oneSprite)>setScale;>setPosition.size.height / 2)));
}
}
//Centered sprites new origin
float centeredXOrigin = + visibleOrigin.x;
CCObject object;
CCARRAY_FOREACH
{
CCSpritemySprite = object;
mySprite
centeredXOrigin= mySprite~~>boundingBox().size.width;
}
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.