A shaking action for Cocos2d-x. It shakes the cocos2d node.
I recommend you to use Simplex Noise version than Perlin Noise.
Clone the repo and copy source code to your project.
// Perline Noise
auto sprite = cocos2d::Sprite::create("HelloWorld.png");
sprite->runAction(ActionShake::create(2.0f/*Duration*/, 40.0f/*speed*/, 40.0f/*magnitude*/));
// Simplex Noise
auto sprite = cocos2d::Sprite::create("HelloWorld.png");
sprite->runAction(Shake::create(2.0f/*Duration*/, 40.0f/*speed*/, 40.0f/*magnitude*/));
i.e.) Duration = 2.0f, Magnitude = 40.0f, Speed = 40.0f
Perlin Noise.
Simplex Noise and Reference.
- Uses Perlin Noise and Simplex Noise
- Perlin Noise shake tested on Cocos2d-x 3.10 version.
- Simplex Noise shake tested on Cocos2d-x 3.14.1 version.
- Can be used like other built-in actions. Read comment in code for details.
- I did not write the core algorithm for Perlin Noise, but made it to work on Cocos2d-x 3.10 version because none of them out on the internet worked as described.
- I followed the pdf reference linked above to implement Simplex Noise.