// // HPlainSprite.cpp // SteveMaggieCpp // // Created by Katarzyna Kalinowska-Górska on 17.05.2017. // // #include #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; }