您好,登錄后才能下訂單哦!
1、在圖層中加入兩個精靈
CCSprite *pSp1 = CCSprite::create("bg01.jpg");
CCSprite *pSp2 = CCSprite::create("bg01.jpg");
pSp1->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width/2,CCDirector::sharedDirector()->getWinSize().height/2));
pSp2->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width/2,CCDirector::sharedDirector()->getWinSize().height/2+576));//背景圖片高為576
this->addChild(pSp1,0,11);
this->addChild(pSp2,0,12);
2、啟動滾屏定時器
this->schedule(schedule_selector(GamingLayer::BackgroundScrollLogic),0.1f);
3、滾屏回調函數實現
void GamingLayer::BackgroundScrollLogic(float t)
{
CCSprite *pBg1 = (CCSprite *)getChildByTag(11);
CCSprite *pBg2 = (CCSprite *)getChildByTag(12);
pBg1->setPositionY(pBg1->getPositionY() - 10);//每次移動10個像素
pBg2->setPositionY(pBg1->getPositionY() + 576);//精靈2跟著移動
//如果第二張圖片滾動至末尾,重置精靈1的為原始位置
if(pBg2->getPositionY() <= CCDirector::sharedDirector()->getWinSize().height/2)
{
pBg1->setPositionY(CCDirector::sharedDirector()->getWinSize().height/2);
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。