寒風的Cocos2d之旅之如何实现屏幕滚动
发布时间:2020-12-14 16:33:42 所属栏目:百科 来源:网络整理
导读:核心代码如下: 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);thi
核心代码如下: 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坐标小于一定阀值时,就让它回到刚开始的地方。与此同时,在它的上边拼接的那一张一直随第一张向下滚动,这样就无缝隙了。 本篇文章仅供参考。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |