port of #3144 from cocos2d-x