您的位置:首页 > 移动开发 > Cocos引擎

寒風的Cocos2d之旅之如何实现屏幕滚动

2015-09-16 21:44 537 查看
核心代码如下:

auto sp1=new Sprite("文件路径");
sp1->setAnchorpoint(Vec2::ZERO);
sp1->setPosition(0,0);
sp1->setTag(101);
this->addChild(sp1);
auto sp2=new Sprite("文件路径");
sp2->setAnchorpoint(Vec2::ZERO);
sp2->setTag(102);
sp2->setPosition(0,480);
this->addChild(sp2);</span>
this->ScheduleUpDate();</span>
this->schedule(schedule_selecter(类名::gunping),0.1);
----------------------------------------
void 类名::gunping(float t){
      this->getChildByTag(101)->setPositionY(this->getChildByTag(101)->getPositionY()-1);
      if(this->getChildByTag(101)->getPositionY<-480){
            this->getChildByTag(101)->setPositionY(0);
        }
      this->getChildByTag(102)->setPositionY( this->getChildByTag(101)->getPositionY()+480);
}


大致思路如下:

实现滚屏是让两幅图片拼接在一起,一张往下一直滚动,当它的Y坐标小于一定阀值时,就让它回到刚开始的地方。与此同时,在它的上边拼接的那一张一直随第一张向下滚动,这样就无缝隙了。

本篇文章仅供参考。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: