大家都知道飞机大战看起来十飞机在不断的飞行但是它的位置是保持在屏幕范围内的,为什么看起来有飞行的效果?
飞机的相对位置十不变的(没有触摸移动),看起来我前进飞行的原因是屏幕的图片在向下移动,
那么我们可以想像到先添加一张图片让图片按照y轴方向向下移动。
但是一张图的大小是有限度的一定时间过后就会移除屏幕,所以我们可以在他移除屏幕之前接上一张图片02,在01,移除屏幕之后在接到02后面这样循环达到2张图循环播放的效果(根据屏幕图片的大小可以用2,3。。张图来达到无缝循环)。
不烦代码如下:
auto bk01=Sprite::create("img_bg_level_1.jpg");
this->addChild(bk01);
bk01->setAnchorPoint(Vec2::ZERO);
bk01->setPosition(Vec2::ZERO);
bk01->setTag(10);
auto bk02=Sprite::create("img_bg_level_1.jpg");
this->addChild(bk02);
bk02->setAnchorPoint(Vec2::ZERO);
bk02->setTag(11);
auto bk03=Sprite::create("img_bg_level_1.jpg");
this->addChild(bk03);
bk03->setAnchorPoint(Vec2::ZERO);
bk03->setTag(12);
void Game::update(float t)
{
count=count+1;
if(count%2==0)
{
auto spbk=this->getChildByTag(10);
auto spbk02=this->getChildByTag(11);
auto spbk03=this->getChildByTag(12);
spbk->setPositionY(spbk->getPositionY()-10);
spbk02->setPositionY(spbk->getPositionY()+spbk->getContentSize().height);
spbk03->setPositionY(spbk02->getPositionY()+spbk02->getContentSize().height);
if(spbk02->getPositionY()<=0)
{
spbk->setPositionY(0);
}
count=0;
}