嘿,秀一下效果图:
让这四张美女图片,循环的向上滚动,那么如何做的呢?
首先准备四张图片分别命名:
Beauty1,Beauty2,Beauty3,Beauty4
然后在Splash类中添加_vcSprites,用来保存精灵
class SplashScene : public cocos2d::Scene
{
public:
CREATE_FUNC(SplashScene);
virtual bool init();
virtual void update(float dt);
void playerAction();
void beginGame();
private:
SplashScene();
virtual ~SplashScene();
Vector<Sprite*> _vcSprites;
int _index;
};
this->schedule(schedule_selector(SplashScene::update));
for (int j = 0; j < 2; ++j) //两分同样的精灵
{
for (int i = 0; i < 4; ++i)
{
auto fileName = String::createWithFormat("Beauty%d.png",i + 1);
auto sp = Sprite::create(fileName->getCString());
sp->setAnchorPoint(Vec2(0.5f,1.0f)); //设置锚点为上边中点
sp->setPosition(VisibleRect::top().x,VisibleRect::top().y - i * sp->getContentSize().height -j * sp->getContentSize().height * 4
);
this->addChild(sp);
_vcSprites.pushBack(sp);
}
}
然后在SplashScene::update中,实现精灵坐标的转变:
void SplashScene::update(float dt)
{
for(auto it = _vcSprites.begin(); it != _vcSprites.end(); ++it)
{
y = (*it)->getPositionY() + 3;
(*it)->setPositionY(y);
if( (*it)->getPositionY() - (*it)->getContentSize().height > VisibleRect::top().y)
{
(*it)->setPositionY(VisibleRect::top().y - (*it)->getContentSize().height * 7);
//7代表的是最后一张精灵
}
}
}
ok. 原文链接:/cocos2dx/345124.html