I want to write way (class is best for me) to fit any node to box (via cocos2d::Size). My attemt:
#pragma once
#include "cocos2d.h"
template <class T = cocos2d::Node> class FittableNode: public T {
static_assert(std::is_base_of<cocos2d::Node, T>::value, "ResizebleNode can work only with nodes");
public:
FittableNode() {};
virtual void ~FittableNode() {};
cocos2d::Size fitTo;
inline void resize() {
auto contentSize = getContentSize();
setScale(MIN(fitTo.height/contentSize.height, fitTo.width/contentSize.width));
};
};
But I have no idea how handle create and its variations. Can anyone help me, please?
P.S.: of course, I can use function, but it isn’t conveniently for me.