refactor code to use cocos2d-xs layer feature.