Lance Gray wrote:
I’ve read the code, and here are my questions.
- I am using v2.0.1 but I don’t have
CCDirector::sharedDirector( ) -> getVisibleSize( );. How do I get that?
- What does
getVisibleSize( ) return?
- Is there a way to position sprites at a certain location from another sprite’s position? My setup is this. I have a background image which fills the screen (after it gets rescaled, depending on size). Then I want to position the Close Button on the lower right corner of the Background Image, not the screen itself.
CCDirector::sharedDirector()->getWinSize(); which returns a CCSize with width and height variables you can use to position stuff at different fractions of the screen. You could for example do
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
sprite->setPosition( ccp(winSize.width * 0.5, winSize.height * 0.5) );
to position “sprite” at the middle of the screen.
To instead position “sprite” at the lower right corner of the background sprite “background” you could do
sprite->setPosition( ccp(background->getPositionX() + background->getContentSize().width * 0.5 * background->getScaleX(),
background->getPositionY() - background->getContentSize().height * 0.5 * background->getScaleY()) );
assuming the sprite “background” is centered at it’s position, ie. having anchorPoint = (0,0).