颤抖的精灵cocos2dx 3.0

时间:2014-06-18 10:01:08

标签: c++ opengl-es cocos2d-x

我注意到Sprite在加速时向下移动时发抖。这是整个代码: 我正在用iPhone 3gs测试这段代码,猜测为什么?

TestScene.h:

class TestScene : public Layer {
public:
    ....
    virtual void update(float delta);

    float spawnTime = 0.9;
    float untilNextSpawn = 0;

    virtual void spawn();
    float gameSpeed = 200;
    float gameAcceleration = 10;
    Vector<Sprite*> objects;
};

TestScene.cpp:

 void TestScene::update(float delta) {
     untilNextSpawn -= delta;
     if (untilNextSpawn <= 0) {
         spawn();
         untilNextSpawn = spawnTime;
     }

     gameSpeed += gameAcceleration * delta;

     for (int i = 0; i < objects.size(); i++) {
         Sprite* t = objects.at(i);
         if (t->getPosition().y <= 0)
             t->setVisible(false);
         else 
             t->setPositionY(t->getPositionY() - gameSpeed * delta);
    }
}

void TestScene::spawn() {
    Sprite* sprite = NULL;
    for (int i = 0; i < objects.size(); i++) {
        Sprite* t = objects.at(i);
        if (!t->isVisible()) {
            sprite = t; break;  
        }
    }
    if (!sprite) {
        sprite = Sprite::create("prefab_button.png");
        this->addChild(sprite);
        objects.pushBack(sprite);
    }
    sprite->setVisible(true);
    sprite->setPosition(Point(getContentSize().width / 2, getContentSize().height + 100));
}

prefab_button.png:http://i.imgur.com/oljgyZn.png

TestScene.h:http://pastebin.com/f9sSTLgp

TestScene.cpp:http://pastebin.com/siipLzx6

这是视频:https://www.youtube.com/watch?v=PYfzUnSBQ7M

0 个答案:

没有答案