Blame view

ios/Runner/Wowgame/Classes/game_halloween/HPlainSprite.cpp 1.9 KB
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  //
  //  HPlainSprite.cpp
  //  SteveMaggieCpp
  //
  //  Created by Katarzyna Kalinowska-Górska on 17.05.2017.
  //
  //
  
  #include <stdio.h>
  #include "HPlainSprite.h"
  #include "HJSONParseUtils.h"
  #include "cocos2d.h"
  #include "HMathUtils.h"
  
  HPlainSprite* HPlainSprite::createWithTexture(cocos2d::Texture2D* texture)
  {
      HPlainSprite * sprite = new (std::nothrow) HPlainSprite();
      if(sprite && sprite->initWithTexture(texture))
      {
          sprite->autorelease();
          return sprite;
      }
      CC_SAFE_DELETE(sprite);
      return nullptr;
  }
  
  
  HPlainSprite* HPlainSprite::createWithSpritePath(std::string spritePath)
  {
      HPlainSprite * sprite = new (std::nothrow) HPlainSprite();
      if(sprite && sprite->initWithFile(spritePath))
      {
          sprite->autorelease();
          return sprite;
      }
      CC_SAFE_DELETE(sprite);
      return nullptr;
  }
  
  void HPlainSprite::loadPropertiesFromJSON(const rapidjson::Value& jsonValue, HLayoutViewInterface* scene, const std::string resFolder, const std::string altResFolder)
  {
      this->loadCommonPropertiesFromJSON(jsonValue);
      
      if(jsonValue.HasMember("flippedX")){
          const auto& flippedXJSON = jsonValue["flippedX"];
          this->setFlippedX(flippedXJSON.GetBool());
      }
  
      if(jsonValue.HasMember("flippedY")){
          const auto& flippedYJSON = jsonValue["flippedY"];
          this->setFlippedY(flippedYJSON.GetBool());
      }
      
      if(jsonValue.HasMember("color")){
          const auto& color = jsonValue["color"];
          float r = color["r"].GetFloat();
          float g = color["g"].GetFloat();
          float b = color["b"].GetFloat();
          this->setColor(cocos2d::Color3B(r,g,b));
      }
  
  }
  
  void HPlainSprite::prepareSize(const rapidjson::Value& jsonValue, float& width, float& height)
  {
      width = this->getBoundingBox().size.width;
      height = this->getBoundingBox().size.height;
  //    width = this->getContentSize().width;
  //    height = this->getContentSize().height;
  }