Fixes ShaderRetroEffect crashes. (#18237)

This commit is contained in:
James Chen 2017-09-08 01:10:40 -05:00 committed by minggo
parent 46e70d3c71
commit d13c01230f
2 changed files with 12 additions and 9 deletions

View File

@ -573,13 +573,16 @@ void ShaderRetroEffect::update(float dt)
for (int i = 0; i < letterCount; ++i)
{
auto sprite = _label->getLetter(i);
auto oldPosition = sprite->getPosition();
sprite->setPosition(Vec2( oldPosition.x, sinf( _accum * 2 + i/2.0) * 20 ));
// add fabs() to prevent negative scaling
float scaleY = ( sinf( _accum * 2 + i/2.0 + 0.707) );
sprite->setScaleY(scaleY);
if (sprite != nullptr)
{
auto oldPosition = sprite->getPosition();
sprite->setPosition(Vec2( oldPosition.x, sinf( _accum * 2 + i/2.0) * 20 ));
// add fabs() to prevent negative scaling
float scaleY = ( sinf( _accum * 2 + i/2.0 + 0.707) );
sprite->setScaleY(scaleY);
}
}
}

View File

@ -106,8 +106,8 @@ public:
ShaderRetroEffect();
virtual std::string title() const override;
virtual std::string subtitle() const override;
bool init() override;
void update(float dt) override;
virtual bool init() override;
virtual void update(float dt) override;
protected:
cocos2d::Label* _label;
float _accum;