implement scratch-off effect using CCLayerColors, MIT Licence, for cocos2dx-2.x
Intentionally avoid using CCRenderTexture, because it's soooo buggy on android. The GLSurfaceView onPause() trashes opengl context whenever lock screen or click home button. The sdk-15 solution almost works when android:targetSdkVersion in AndroidManifest.xml <= 12, but it fails on my device when click home and relaunch twice.
CCMaskLayer *maskLayer = CCMaskLayer::create(ccc4(255, 0, 0, 200));
addChild(maskLayer);
maskLayer->begin(); // begin
maskLayer->scratchOff(CCRectMake(100, 100, 200, 200)); // 1
CCSprite* circle = CCSprite::create("mask-circle.png");
circle->setPosition(ccp(400, 300));
circle->setScale(1.2);
maskLayer->scratchOff(circle); // 2
maskLayer->end(); // end