// on "init" you need to initialize your instance bool HelloWorld::init() { bool bRet = false; do { CC_BREAK_IF(!CCLayer::init()); // 添加关闭按钮 CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); CC_BREAK_IF(!pCloseItem); pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) ); // 添加到菜单中 CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); CC_BREAK_IF(!pMenu); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); float width = visibleSize.width; float originX = CCDirector::sharedDirector()->getVisibleOrigin().x + width - 100 * 2; float originY = CCDirector::sharedDirector()->getVisibleOrigin().y; float height = visibleSize.height; // grossini m_pGrossiniSprite = CCSprite::create(s_pathGrossini); CC_BREAK_IF(!m_pGrossiniSprite); m_pGrossiniSprite->retain(); // 内存管理,需要保留 m_pGrossiniSprite->setPosition(ccp(originX / 3.f, originY + height / 2.f)); this->addChild(m_pGrossiniSprite); /// CCMoveTo 表示将精灵的位置移动到500, 500的位置,不管当前什么位置 CCFiniteTimeAction *pMoveTo = CCMoveTo::create(3.5f, ccp(500, 500)); CCFiniteTimeAction *pMoveBack = CCMoveTo::create(3.5, ccp(originX / 3.f, originY + height / 2.f)); m_pGrossiniSprite->runAction(CCSequence::create(pMoveTo, pMoveBack, NULL)); // tamara m_pTamaraSprite = CCSprite::create(s_pathGrossinisSister1); CC_BREAK_IF(!m_pTamaraSprite); m_pTamaraSprite->retain(); // 内存管理,需要保留 m_pTamaraSprite->setPosition(ccp(originX / 3 * 2.f, originY + height / 2.f)); this->addChild(m_pTamaraSprite); /// CCMoveBy 表示从当前位置开始,x方向向右移动300,y方向向下移动200 CCFiniteTimeAction *pMoveBy = CCMoveBy::create(3.5f, ccp(300, -200)); CCFiniteTimeAction *pMoveByBack = CCMoveTo::create(3.5, ccp(originX / 3 * 2.f, originY + height / 2.f)); m_pTamaraSprite->runAction(CCSequence::create(pMoveBy, pMoveByBack, NULL)); // kathia m_pKathiaSprite = CCSprite::create(s_pathGrossinisSister2); CC_BREAK_IF(!m_pKathiaSprite); m_pKathiaSprite->retain(); // 内存管理,需要保留 m_pKathiaSprite->setPosition(ccp(originX / 3.f * 3, originY + height / 2.f)); this->addChild(m_pKathiaSprite); /// CCRotateTo 表示旋转到指定的角度(180) /// CCRotateBy 表示从当前角度,继续再旋转指定的角度(180),那么最终角度为180 + (-45) = 135 CCFiniteTimeAction *pRotateTo = CCRotateTo::create(3.5, 180); CCFiniteTimeAction *pRotateBy = CCRotateBy::create(3.5, -45); m_pKathiaSprite->runAction(CCSequence::create(pRotateTo, pRotateBy, NULL)); bRet = true; } while (0); return bRet; }
看注释!!!!
源代码:http://download.csdn.net/detail/woaifen3344/7188071