cocos2d-x 学习笔记(ActionsTest)

时间:2023-02-06 19:54:20

添加图片

m_grossini = CCSprite::create(s_pPathGrossini);
m_grossini->retain();

m_grossini->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height/3));

为什么要retain()?
因为介于cocos特殊的内存管理机制,就像java一样,当调用autoRelease时会释放“没人认领”的对象,但如果retain了候就不会被autoRelease盯上。
但之后一定要调用release

m_grossini->release();

添加文字

std::string str = title();
const char * pTitle = str.c_str();
CCLabelTTF* label = CCLabelTTF::create(pTitle, "Arial", 32);
addChild(label, 1);
label->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y - 30) );

添加下面的“上一个”“重放”“下一个”菜单系统

    CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(ActionsDemo::backCallback) );
CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(ActionsDemo::restartCallback) );
CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(ActionsDemo::nextCallback) );

CCMenu *menu = CCMenu::create(item1, item2, item3, NULL);

menu->setPosition(CCPointZero);

item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));

item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));

item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));

addChild(menu, 1);