我需要添加5个连续的backgroundimage作为视差滚动节点。所以它看起来像滚动背景.. :; qst
我的初始代码: -
//initialise paralllax
_backgroundNode = CCParallaxNodeExtras::node();
this->addChild(_backgroundNode, 1);
//create sprites
_fogA = CCSprite::create("bg1.png");
_fogB = CCSprite::create("bg2.png");
_liany = CCSprite::create("bg3.png");
_pnie = CCSprite::create("bg4.png");
_pniw = CCSprite::create("bg5.png");
//ratio
CCPoint bgSpeed = ccp(0.05, 0.05);
// add spriet to parallax node
_backgroundNode->addChild(_fogA, 0, bgSpeed, ccp(_fogA->getContentSize().width/2,_fogA->getContentSize().height/2));
_backgroundNode->addChild(_fogB, 0, bgSpeed, ccp(_fogA->getContentSize().width, _fogB->getContentSize().height/2));
_backgroundNode->addChild(_liany, 0, bgSpeed, ccp((_fogA->getContentSize().width+_fogB->getContentSize().width), _liany->getContentSize().height/2));
_backgroundNode->addChild(_pnie, 0, bgSpeed, ccp((_fogA->getContentSize().width+_fogB->getContentSize().width+_liany->getContentSize().width), _pnie->getContentSize().height/2));
_backgroundNode->addChild(_pniw, 0, bgSpeed, ccp((_fogA->getContentSize().width+_fogB->getContentSize().width+_liany->getContentSize().width+_pnie->getContentSize().width),_pniw->getContentSize().height/2));
我的更新方法: -
//update method
void Game::processBackground(float dt)
{
// scroll 30 pixels backward in update
CCPoint backgroundScrollVert = ccp(-3000, 0);
_backgroundNode->setPosition(ccpAdd(_backgroundNode->getPosition(), ccpMult(backgroundScrollVert, dt)));
//create array objects to reset the image
CCArray * fogs = CCArray::createWithCapacity(5);
fogs->addObject(_fogA);
fogs->addObject(_fogB);
fogs->addObject(_liany);
fogs->addObject(_pnie);
fogs->addObject(_pniw);
for (int ii = 0; ii < fogs->count(); ii++)
{
CCSprite * fog = (CCSprite *)(fogs->objectAtIndex(ii));
float xPosition = _backgroundNode->convertToWorldSpace(fog->getPosition()).x - (fog->getContentSize().width/2);
float size = fog->getContentSize().width;
if (xPosition < -size)
{
_backgroundNode->incrementOffset(ccp(fog->getContentSize().width*2,0),fog);
}
}
}
有些所有5张图像都会出现,但在图像之间会出现一些黑色空间。
不是为了它的到来而不存在 ?
答案 0 :(得分:0)
我想出了答案....它在cocos2d-x 2.2.2
中工作