头文件中增加:
void backgroundMove(float dt);
cocos2d::Sprite* background1;
cocos2d::Sprite* background2;
init函数中增加:
background1 = Sprite::create("background.png");
background2 = Sprite::create("background.png");
background1->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
background2->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
background1->setPosition(Point::ZERO);
this->addChild(background1,0);
this->addChild(background2,0);
this->schedule(schedule_selector(Welcome::backgroundMove),0.01f);
实现backgroundMove函数
void Welcome::backgroundMove(float dt)
{
background1->setPositionX(background1->getPositionX()-2.0f);
background2->setPositionX(background1->getPositionX() + background1->getContentSize().width-2.0f);
if(background2->getPositionX()<=0)
{
background1->setPositionX(0);
}
}