在cocos2dx v3中使用单个图像移回地面

时间:2015-07-22 09:58:46

标签: cocos2d-x-3.0

我是cocos2dx编程的新手。请允许任何人通过使用带代码的单个图像帮助我移动背景精灵但代码应该在cocos2dx-3.0中,因为我已经搜索了这个问题,但是所有代码都在旧的cocos2dx谢谢。

1 个答案:

答案 0 :(得分:0)

我以cocos2d-x Book

为例
for (int i = 0; i < 2; i ++)
{
    backgroundSpriteArray[i] = Sprite::create
    ("GameScreen/Game_Screen_Background.png");
    backgroundSpriteArray[i]->setPosition
    (Point((visibleSize.width / 2) + origin.x, (-1 *
    visibleSize.height * i) + (visibleSize.height / 2) +
    origin.y));
    this->addChild(backgroundSpriteArray[i], -2);
}

for (int i = 0; i < 2; i ++)
{
    backgroundSpriteArray[i]->setPosition
    (Point(backgroundSpriteArray[i]->getPosition().x,
    backgroundSpriteArray[i]->getPosition().y + (0.75 *
    visibleSize.height * dt)));
}

虽然背景滚动,但一旦它们消失就不会重置 在屏幕上方。在上一代码上方添加以下代码:

Size visibleSize = Director::getInstance()->
getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
for (int i = 0; i < 2; i ++)
{
if (backgroundSpriteArray[i]->getPosition().y >=
visibleSize.height + (visibleSize.height / 2) -1)
{
    backgroundSpriteArray[i]->setPosition
    (Point((visibleSize.width / 2) + origin.x, (-1 *
    visibleSize.height) + (visibleSize.height / 2)));
}
}