ToyPlainNode.cpp
1.7 KB
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
//
//  ToyPlainNode.cpp
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 17.05.2017.
//
//
#include <stdio.h>
#include "ToyPlainNode.h"
#include "ToyJSONParseUtils.h"
#include "ToyScalingUtils.h"
ToyPlainNode* ToyPlainNode::create()
{
    ToyPlainNode * node = new (std::nothrow) ToyPlainNode();
    if(node && node->init())
    {
        node->autorelease();
        return node;
    }
    CC_SAFE_DELETE(node);
    return nullptr;
}
ToyPlainNode* ToyPlainNode::createWithColour(cocos2d::Color4B color){
    auto node = create();
    if(node != nullptr){
        node->_backgroundLayer = cocos2d::LayerColor::create(color);
        node->_backgroundLayer->setAnchorPoint(cocos2d::Vec2(0.5, 0.5));
        node->_backgroundLayer->setContentSize(node->getContentSize());
        node->_backgroundLayer->setPosition(cocos2d::Vec2(node->getContentSize().width/2, node->getContentSize().height/2));
        node->addChild(node->_backgroundLayer);
    }
    return node;
}
void ToyPlainNode::loadPropertiesFromJSON(const rapidjson::Value& jsonValue, ToyLayoutViewInterface* scene, const std::string resFolder, const std::string altResFolder)
{
    this->setAnchorPoint(cocos2d::Point(0.5, 0.5));
    this->loadCommonPropertiesFromJSON(jsonValue);
    if(ToyJSONParseUtils::hasMemberBool(jsonValue, "adjustContentSizeForSmallDevices") && ToyScalingUtils::isSmallDevice()){
        auto scale = ToyScalingUtils::getScaleForSmallDevice();
        setContentSize(this->getContentSize()*scale);//,this->getContentSize().height*scale);
    }
}
void ToyPlainNode::prepareSize(const rapidjson::Value& jsonValue, float& width, float& height)
{
    width = this->getContentSize().width;
    height = this->getContentSize().height;
}