CCSpriteLoader.cpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /****************************************************************************
  2. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #include "editor-support/cocosbuilder/CCSpriteLoader.h"
  21. using namespace cocos2d;
  22. #define PROPERTY_FLIP "flip"
  23. #define PROPERTY_DISPLAYFRAME "displayFrame"
  24. #define PROPERTY_COLOR "color"
  25. #define PROPERTY_OPACITY "opacity"
  26. #define PROPERTY_BLENDFUNC "blendFunc"
  27. namespace cocosbuilder {
  28. void SpriteLoader::onHandlePropTypeSpriteFrame(Node * pNode, Node * pParent, const char * pPropertyName, SpriteFrame * pSpriteFrame, CCBReader * ccbReader) {
  29. if(strcmp(pPropertyName, PROPERTY_DISPLAYFRAME) == 0) {
  30. if(pSpriteFrame != nullptr) {
  31. ((Sprite *)pNode)->setSpriteFrame(pSpriteFrame);
  32. } else {
  33. CCLOG("ERROR: SpriteFrame nullptr");
  34. }
  35. } else {
  36. NodeLoader::onHandlePropTypeSpriteFrame(pNode, pParent, pPropertyName, pSpriteFrame, ccbReader);
  37. }
  38. }
  39. void SpriteLoader::onHandlePropTypeFlip(Node * pNode, Node * pParent, const char * pPropertyName, bool * pFlip, CCBReader * ccbReader) {
  40. if(strcmp(pPropertyName, PROPERTY_FLIP) == 0) {
  41. ((Sprite *)pNode)->setFlippedX(pFlip[0]);
  42. ((Sprite *)pNode)->setFlippedY(pFlip[1]);
  43. } else {
  44. NodeLoader::onHandlePropTypeFlip(pNode, pParent, pPropertyName, pFlip, ccbReader);
  45. }
  46. }
  47. void SpriteLoader::onHandlePropTypeColor3(Node * pNode, Node * pParent, const char * pPropertyName, Color3B pColor3B, CCBReader * ccbReader) {
  48. if(strcmp(pPropertyName, PROPERTY_COLOR) == 0) {
  49. ((Sprite *)pNode)->setColor(pColor3B);
  50. } else {
  51. NodeLoader::onHandlePropTypeColor3(pNode, pParent, pPropertyName, pColor3B, ccbReader);
  52. }
  53. }
  54. void SpriteLoader::onHandlePropTypeByte(Node * pNode, Node * pParent, const char * pPropertyName, unsigned char pByte, CCBReader * ccbReader) {
  55. if(strcmp(pPropertyName, PROPERTY_OPACITY) == 0) {
  56. ((Sprite *)pNode)->setOpacity(pByte);
  57. } else {
  58. NodeLoader::onHandlePropTypeByte(pNode, pParent, pPropertyName, pByte, ccbReader);
  59. }
  60. }
  61. void SpriteLoader::onHandlePropTypeBlendFunc(Node * pNode, Node * pParent, const char * pPropertyName, BlendFunc pBlendFunc, CCBReader * ccbReader) {
  62. if(strcmp(pPropertyName, PROPERTY_BLENDFUNC) == 0) {
  63. ((Sprite *)pNode)->setBlendFunc(pBlendFunc);
  64. } else {
  65. NodeLoader::onHandlePropTypeBlendFunc(pNode, pParent, pPropertyName, pBlendFunc, ccbReader);
  66. }
  67. }
  68. }