使用工厂方法模式管理对象

This commit is contained in:
Nomango 2018-05-17 12:22:52 +08:00
parent 012c7aad50
commit 084671fa1c
45 changed files with 900 additions and 209 deletions

View File

@ -13,6 +13,16 @@ e2d::Animate::Animate(Animation * animation)
this->setAnimation(animation); this->setAnimation(animation);
} }
e2d::Animate * e2d::Animate::create()
{
return Create<Animate>();
}
e2d::Animate * e2d::Animate::create(Animation * animation)
{
return Create<Animate>(animation);
}
e2d::Animate::~Animate() e2d::Animate::~Animate()
{ {
} }
@ -97,7 +107,7 @@ e2d::Animate * e2d::Animate::clone() const
{ {
if (_animation) if (_animation)
{ {
return new (std::nothrow) Animate(_animation); return Create<Animate>(_animation);
} }
return nullptr; return nullptr;
} }
@ -121,10 +131,10 @@ e2d::Animate * e2d::Animate::reverse() const
} }
} }
auto animation = new (std::nothrow) Animation(_animation->getInterval(), frames); auto animation = Create<Animation>(_animation->getInterval(), frames);
if (animation) if (animation)
{ {
return new (std::nothrow) Animate(animation); return Create<Animate>(animation);
} }
} }
return nullptr; return nullptr;

View File

@ -5,14 +5,19 @@ e2d::CallFunc::CallFunc(const Function& func) :
{ {
} }
e2d::CallFunc * e2d::CallFunc::create(const Function & func)
{
return Create<CallFunc>(func);
}
e2d::CallFunc * e2d::CallFunc::clone() const e2d::CallFunc * e2d::CallFunc::clone() const
{ {
return new (std::nothrow) CallFunc(_func); return Create<CallFunc>(_func);
} }
e2d::CallFunc * e2d::CallFunc::reverse() const e2d::CallFunc * e2d::CallFunc::reverse() const
{ {
return new (std::nothrow) CallFunc(_func); return Create<CallFunc>(_func);
} }
void e2d::CallFunc::_init() void e2d::CallFunc::_init()

View File

@ -6,14 +6,19 @@ e2d::Delay::Delay(double duration)
{ {
} }
e2d::Delay * e2d::Delay::create(double duration)
{
return Create<Delay>(duration);
}
e2d::Delay * e2d::Delay::clone() const e2d::Delay * e2d::Delay::clone() const
{ {
return new (std::nothrow) Delay(_delay); return Create<Delay>(_delay);
} }
e2d::Delay * e2d::Delay::reverse() const e2d::Delay * e2d::Delay::reverse() const
{ {
return new (std::nothrow) Delay(_delay); return Create<Delay>(_delay);
} }
void e2d::Delay::reset() void e2d::Delay::reset()

View File

@ -8,14 +8,19 @@ e2d::JumpBy::JumpBy(double duration, const Vector & vec, double height, int jump
{ {
} }
e2d::JumpBy * e2d::JumpBy::create(double duration, const Vector & vec, double height, int jumps)
{
return Create<JumpBy>(duration, vec, height, jumps);
}
e2d::JumpBy * e2d::JumpBy::clone() const e2d::JumpBy * e2d::JumpBy::clone() const
{ {
return new (std::nothrow) JumpBy(_duration, _deltaPos, _height, _jumps); return Create<JumpBy>(_duration, _deltaPos, _height, _jumps);
} }
e2d::JumpBy * e2d::JumpBy::reverse() const e2d::JumpBy * e2d::JumpBy::reverse() const
{ {
return new (std::nothrow) JumpBy(_duration, -_deltaPos, _height, _jumps); return Create<JumpBy>(_duration, -_deltaPos, _height, _jumps);
} }
void e2d::JumpBy::_init() void e2d::JumpBy::_init()

View File

@ -6,9 +6,14 @@ e2d::JumpTo::JumpTo(double duration, const Point & pos, double height, int jumps
{ {
} }
e2d::JumpTo * e2d::JumpTo::create(double duration, const Point & pos, double height, int jumps)
{
return Create<JumpTo>(duration, pos, height, jumps);
}
e2d::JumpTo * e2d::JumpTo::clone() const e2d::JumpTo * e2d::JumpTo::clone() const
{ {
return new (std::nothrow) JumpTo(_duration, _endPos, _height, _jumps); return Create<JumpTo>(_duration, _endPos, _height, _jumps);
} }
void e2d::JumpTo::_init() void e2d::JumpTo::_init()

View File

@ -15,6 +15,11 @@ e2d::Loop::Loop(Action * action, int times /* = -1 */)
} }
} }
e2d::Loop * e2d::Loop::create(Action * action, int times)
{
return Create<Loop>(action, times);
}
e2d::Loop::~Loop() e2d::Loop::~Loop()
{ {
} }
@ -23,7 +28,7 @@ e2d::Loop * e2d::Loop::clone() const
{ {
if (_action) if (_action)
{ {
return new (std::nothrow) Loop(_action->clone()); return Create<Loop>(_action->clone());
} }
else else
{ {
@ -33,7 +38,7 @@ e2d::Loop * e2d::Loop::clone() const
e2d::Loop * e2d::Loop::reverse() const e2d::Loop * e2d::Loop::reverse() const
{ {
return new (std::nothrow) Loop(_action); return Create<Loop>(_action);
} }
void e2d::Loop::_init() void e2d::Loop::_init()

View File

@ -7,6 +7,11 @@ e2d::MoveBy::MoveBy(double duration, Vector vector)
_deltaPos = vector; _deltaPos = vector;
} }
e2d::MoveBy * e2d::MoveBy::create(double duration, Vector vector)
{
return Create<MoveBy>(duration, vector);
}
void e2d::MoveBy::_init() void e2d::MoveBy::_init()
{ {
ActionGradual::_init(); ActionGradual::_init();
@ -29,10 +34,10 @@ void e2d::MoveBy::_update()
e2d::MoveBy * e2d::MoveBy::clone() const e2d::MoveBy * e2d::MoveBy::clone() const
{ {
return new (std::nothrow) MoveBy(_duration, _deltaPos); return Create<MoveBy>(_duration, _deltaPos);
} }
e2d::MoveBy * e2d::MoveBy::reverse() const e2d::MoveBy * e2d::MoveBy::reverse() const
{ {
return new (std::nothrow) MoveBy(_duration, -_deltaPos); return Create<MoveBy>(_duration, -_deltaPos);
} }

View File

@ -6,9 +6,14 @@ e2d::MoveTo::MoveTo(double duration, Point pos)
_endPos = pos; _endPos = pos;
} }
e2d::MoveTo * e2d::MoveTo::create(double duration, Point pos)
{
return Create<MoveTo>(duration, pos);
}
e2d::MoveTo * e2d::MoveTo::clone() const e2d::MoveTo * e2d::MoveTo::clone() const
{ {
return new (std::nothrow) MoveTo(_duration, _endPos); return Create<MoveTo>(_duration, _endPos);
} }
void e2d::MoveTo::_init() void e2d::MoveTo::_init()

View File

@ -7,6 +7,11 @@ e2d::OpacityBy::OpacityBy(double duration, double opacity)
_deltaVal = opacity; _deltaVal = opacity;
} }
e2d::OpacityBy * e2d::OpacityBy::create(double duration, double opacity)
{
return Create<OpacityBy>(duration, opacity);
}
void e2d::OpacityBy::_init() void e2d::OpacityBy::_init()
{ {
ActionGradual::_init(); ActionGradual::_init();
@ -29,10 +34,10 @@ void e2d::OpacityBy::_update()
e2d::OpacityBy * e2d::OpacityBy::clone() const e2d::OpacityBy * e2d::OpacityBy::clone() const
{ {
return new (std::nothrow) OpacityBy(_duration, _deltaVal); return Create<OpacityBy>(_duration, _deltaVal);
} }
e2d::OpacityBy * e2d::OpacityBy::reverse() const e2d::OpacityBy * e2d::OpacityBy::reverse() const
{ {
return new (std::nothrow) OpacityBy(_duration, -_deltaVal); return Create<OpacityBy>(_duration, -_deltaVal);
} }

View File

@ -7,9 +7,14 @@ e2d::OpacityTo::OpacityTo(double duration, double opacity)
_endVal = opacity; _endVal = opacity;
} }
e2d::OpacityTo * e2d::OpacityTo::create(double duration, double opacity)
{
return Create<OpacityTo>(duration, opacity);
}
e2d::OpacityTo * e2d::OpacityTo::clone() const e2d::OpacityTo * e2d::OpacityTo::clone() const
{ {
return new (std::nothrow) OpacityTo(_duration, _endVal); return Create<OpacityTo>(_duration, _endVal);
} }
void e2d::OpacityTo::_init() void e2d::OpacityTo::_init()

View File

@ -7,6 +7,11 @@ e2d::RotateBy::RotateBy(double duration, double rotation)
_deltaVal = rotation; _deltaVal = rotation;
} }
e2d::RotateBy * e2d::RotateBy::create(double duration, double rotation)
{
return Create<RotateBy>(duration, rotation);
}
void e2d::RotateBy::_init() void e2d::RotateBy::_init()
{ {
ActionGradual::_init(); ActionGradual::_init();
@ -29,10 +34,10 @@ void e2d::RotateBy::_update()
e2d::RotateBy * e2d::RotateBy::clone() const e2d::RotateBy * e2d::RotateBy::clone() const
{ {
return new (std::nothrow) RotateBy(_duration, _deltaVal); return Create<RotateBy>(_duration, _deltaVal);
} }
e2d::RotateBy * e2d::RotateBy::reverse() const e2d::RotateBy * e2d::RotateBy::reverse() const
{ {
return new (std::nothrow) RotateBy(_duration, -_deltaVal); return Create<RotateBy>(_duration, -_deltaVal);
} }

View File

@ -7,9 +7,14 @@ e2d::RotateTo::RotateTo(double duration, double rotation)
_endVal = rotation; _endVal = rotation;
} }
e2d::RotateTo * e2d::RotateTo::create(double duration, double rotation)
{
return Create<RotateTo>(duration, rotation);
}
e2d::RotateTo * e2d::RotateTo::clone() const e2d::RotateTo * e2d::RotateTo::clone() const
{ {
return new (std::nothrow) RotateTo(_duration, _endVal); return Create<RotateTo>(_duration, _endVal);
} }
void e2d::RotateTo::_init() void e2d::RotateTo::_init()

View File

@ -15,6 +15,16 @@ e2d::ScaleBy::ScaleBy(double duration, double scaleX, double scaleY)
_deltaY = scaleY; _deltaY = scaleY;
} }
e2d::ScaleBy * e2d::ScaleBy::create(double duration, double scale)
{
return Create<ScaleBy>(duration, scale);
}
e2d::ScaleBy * e2d::ScaleBy::create(double duration, double scaleX, double scaleY)
{
return Create<ScaleBy>(duration, scaleX, scaleY);
}
void e2d::ScaleBy::_init() void e2d::ScaleBy::_init()
{ {
ActionGradual::_init(); ActionGradual::_init();
@ -38,10 +48,10 @@ void e2d::ScaleBy::_update()
e2d::ScaleBy * e2d::ScaleBy::clone() const e2d::ScaleBy * e2d::ScaleBy::clone() const
{ {
return new (std::nothrow) ScaleBy(_duration, _deltaX, _deltaY); return Create<ScaleBy>(_duration, _deltaX, _deltaY);
} }
e2d::ScaleBy * e2d::ScaleBy::reverse() const e2d::ScaleBy * e2d::ScaleBy::reverse() const
{ {
return new (std::nothrow) ScaleBy(_duration, -_deltaX, -_deltaY); return Create<ScaleBy>(_duration, -_deltaX, -_deltaY);
} }

View File

@ -14,9 +14,19 @@ e2d::ScaleTo::ScaleTo(double duration, double scaleX, double scaleY)
_endScaleY = scaleY; _endScaleY = scaleY;
} }
e2d::ScaleTo * e2d::ScaleTo::create(double duration, double scale)
{
return Create<ScaleTo>(duration, scale);
}
e2d::ScaleTo * e2d::ScaleTo::create(double duration, double scaleX, double scaleY)
{
return Create<ScaleTo>(duration, scaleX, scaleY);
}
e2d::ScaleTo * e2d::ScaleTo::clone() const e2d::ScaleTo * e2d::ScaleTo::clone() const
{ {
return new (std::nothrow) ScaleTo(_duration, _endScaleX, _endScaleY); return Create<ScaleTo>(_duration, _endScaleX, _endScaleY);
} }
void e2d::ScaleTo::_init() void e2d::ScaleTo::_init()

View File

@ -11,6 +11,16 @@ e2d::Sequence::Sequence(const std::vector<Action*>& actions)
this->add(actions); this->add(actions);
} }
e2d::Sequence * e2d::Sequence::create()
{
return Create<Sequence>();
}
e2d::Sequence * e2d::Sequence::create(const std::vector<Action*>& actions)
{
return Create<Sequence>(actions);
}
e2d::Sequence::~Sequence() e2d::Sequence::~Sequence()
{ {
} }
@ -97,7 +107,7 @@ void e2d::Sequence::add(const std::vector<Action*>& actions)
e2d::Sequence * e2d::Sequence::clone() const e2d::Sequence * e2d::Sequence::clone() const
{ {
auto sequence = new (std::nothrow) Sequence(); auto sequence = Create<Sequence>();
for (const auto& action : _actions) for (const auto& action : _actions)
{ {
if (action) if (action)
@ -110,7 +120,7 @@ e2d::Sequence * e2d::Sequence::clone() const
e2d::Sequence * e2d::Sequence::reverse() const e2d::Sequence * e2d::Sequence::reverse() const
{ {
auto sequence = new (std::nothrow) Sequence(); auto sequence = Create<Sequence>();
if (!_actions.empty()) if (!_actions.empty())
{ {
std::vector<Action*> newActions(_actions.size()); std::vector<Action*> newActions(_actions.size());

View File

@ -9,6 +9,16 @@ e2d::Spawn::Spawn(const std::vector<Action*>& actions)
this->add(actions); this->add(actions);
} }
e2d::Spawn * e2d::Spawn::create()
{
return Create<Spawn>();
}
e2d::Spawn * e2d::Spawn::create(const std::vector<Action*>& actions)
{
return Create<Spawn>(actions);
}
e2d::Spawn::~Spawn() e2d::Spawn::~Spawn()
{ {
} }
@ -95,7 +105,7 @@ void e2d::Spawn::add(const std::vector<Action*>& actions)
e2d::Spawn * e2d::Spawn::clone() const e2d::Spawn * e2d::Spawn::clone() const
{ {
auto spawn = new (std::nothrow) Spawn(); auto spawn = Create<Spawn>();
for (const auto& action : _actions) for (const auto& action : _actions)
{ {
if (action) if (action)
@ -108,7 +118,7 @@ e2d::Spawn * e2d::Spawn::clone() const
e2d::Spawn * e2d::Spawn::reverse() const e2d::Spawn * e2d::Spawn::reverse() const
{ {
auto spawn = new (std::nothrow) Spawn(); auto spawn = Create<Spawn>();
if (!_actions.empty()) if (!_actions.empty())
{ {
std::vector<Action*> newActions(_actions.size()); std::vector<Action*> newActions(_actions.size());

View File

@ -8,7 +8,7 @@ e2d::Collider::Collider()
, _parentNode(nullptr) , _parentNode(nullptr)
, _transformed(nullptr) , _transformed(nullptr)
, _enable(true) , _enable(true)
, _autoResize(true) , _autoResize(false)
{ {
} }

View File

@ -23,6 +23,22 @@ e2d::ColliderCircle::ColliderCircle(Node * node)
), ),
minSide / 2 minSide / 2
); );
this->setAutoResize(true);
}
e2d::ColliderCircle * e2d::ColliderCircle::create()
{
return Create<ColliderCircle>();
}
e2d::ColliderCircle * e2d::ColliderCircle::create(Point center, double radius)
{
return Create<ColliderCircle>(center, radius);
}
e2d::ColliderCircle * e2d::ColliderCircle::create(Node * node)
{
return Create<ColliderCircle>(node);
} }
e2d::ColliderCircle::~ColliderCircle() e2d::ColliderCircle::~ColliderCircle()

View File

@ -23,6 +23,22 @@ e2d::ColliderEllipse::ColliderEllipse(Node * node)
node->getWidth() / 2, node->getWidth() / 2,
node->getHeight() / 2 node->getHeight() / 2
); );
this->setAutoResize(true);
}
e2d::ColliderEllipse * e2d::ColliderEllipse::create()
{
return Create<ColliderEllipse>();
}
e2d::ColliderEllipse * e2d::ColliderEllipse::create(Point center, double radiusX, double radiusY)
{
return Create<ColliderEllipse>(center, radiusX, radiusY);
}
e2d::ColliderEllipse * e2d::ColliderEllipse::create(Node * node)
{
return Create<ColliderEllipse>(node);
} }
e2d::ColliderEllipse::~ColliderEllipse() e2d::ColliderEllipse::~ColliderEllipse()

View File

@ -16,6 +16,22 @@ e2d::ColliderRect::ColliderRect(Node * node)
: _d2dRectangle(nullptr) : _d2dRectangle(nullptr)
{ {
this->setRect(0, 0, node->getRealWidth(), node->getRealHeight()); this->setRect(0, 0, node->getRealWidth(), node->getRealHeight());
this->setAutoResize(true);
}
e2d::ColliderRect * e2d::ColliderRect::create()
{
return Create<ColliderRect>();
}
e2d::ColliderRect * e2d::ColliderRect::create(double x, double y, double width, double height)
{
return Create<ColliderRect>(x, y, width, height);
}
e2d::ColliderRect * e2d::ColliderRect::create(Node * node)
{
return Create<ColliderRect>(node);
} }
e2d::ColliderRect::~ColliderRect() e2d::ColliderRect::~ColliderRect()
@ -41,7 +57,7 @@ void e2d::ColliderRect::_resize()
{ {
if (_parentNode && _enable) if (_parentNode && _enable)
{ {
this->setRect( 0, 0, _parentNode->getRealWidth(), _parentNode->getRealHeight()); this->setRect(0, 0, _parentNode->getRealWidth(), _parentNode->getRealHeight());
} }
} }

View File

@ -5,6 +5,12 @@ e2d::Animation::Animation()
{ {
} }
e2d::Animation::Animation(const std::vector<Image*>& frames)
: _interval(1)
{
this->add(frames);
}
e2d::Animation::Animation(double interval) e2d::Animation::Animation(double interval)
: _interval(interval) : _interval(interval)
{ {
@ -16,10 +22,24 @@ e2d::Animation::Animation(double interval, const std::vector<Image*>& frames)
this->add(frames); this->add(frames);
} }
e2d::Animation::Animation(const std::vector<Image*>& frames) e2d::Animation * e2d::Animation::create()
: _interval(1)
{ {
this->add(frames); return Create<Animation>();
}
e2d::Animation * e2d::Animation::create(const std::vector<Image*>& frames)
{
return Create<Animation>(frames);
}
e2d::Animation * e2d::Animation::create(double interval)
{
return Create<Animation>(interval);
}
e2d::Animation * e2d::Animation::create(double interval, const std::vector<Image*>& frames)
{
return Create<Animation>(interval, frames);
} }
e2d::Animation::~Animation() e2d::Animation::~Animation()
@ -68,7 +88,7 @@ const std::vector<e2d::Image*>& e2d::Animation::getFrames() const
e2d::Animation * e2d::Animation::clone() const e2d::Animation * e2d::Animation::clone() const
{ {
auto animation = new (std::nothrow) Animation(_interval); auto animation = Create<Animation>(_interval);
for (auto frame : _frames) for (auto frame : _frames)
{ {
animation->add(frame); animation->add(frame);

View File

@ -28,12 +28,6 @@ e2d::Image::Image(int resNameId, const String& resType)
this->open(resNameId, resType); this->open(resNameId, resType);
} }
e2d::Image::Image(ID2D1Bitmap * bitmap)
: _bitmap(nullptr)
{
this->open(bitmap);
}
e2d::Image::Image(const String& filePath, double cropX, double cropY, double cropWidth, double cropHeight) e2d::Image::Image(const String& filePath, double cropX, double cropY, double cropWidth, double cropHeight)
: _bitmap(nullptr) : _bitmap(nullptr)
{ {
@ -48,6 +42,31 @@ e2d::Image::Image(int resNameId, const String& resType, double cropX, double cro
this->crop(cropX, cropY, cropWidth, cropHeight); this->crop(cropX, cropY, cropWidth, cropHeight);
} }
e2d::Image * e2d::Image::create()
{
return Create<Image>();
}
e2d::Image * e2d::Image::create(const String & filePath)
{
return Create<Image>(filePath);
}
e2d::Image * e2d::Image::create(int resNameId, const String & resType)
{
return Create<Image>(resNameId, resType);
}
e2d::Image * e2d::Image::create(const String & filePath, double cropX, double cropY, double cropWidth, double cropHeight)
{
return Create<Image>(filePath, cropX, cropY, cropWidth, cropHeight);
}
e2d::Image * e2d::Image::create(int resNameId, const String & resType, double cropX, double cropY, double cropWidth, double cropHeight)
{
return Create<Image>(resNameId, resType, cropX, cropY, cropWidth, cropHeight);
}
e2d::Image::~Image() e2d::Image::~Image()
{ {
} }
@ -81,20 +100,6 @@ bool e2d::Image::open(int resNameId, const String& resType)
return true; return true;
} }
bool e2d::Image::open(ID2D1Bitmap * bitmap)
{
if (bitmap)
{
if (s_vBitmaps.find(bitmap) != s_vBitmaps.end())
{
s_vBitmaps.insert(bitmap);
}
this->_setBitmap(bitmap);
return true;
}
return false;
}
void e2d::Image::crop(double x, double y, double width, double height) void e2d::Image::crop(double x, double y, double width, double height)
{ {
if (_bitmap) if (_bitmap)

View File

@ -7,7 +7,7 @@ e2d::Scene::Scene()
, _colliderVisiable(false) , _colliderVisiable(false)
, _root(nullptr) , _root(nullptr)
{ {
_root = new (std::nothrow) Node(); _root = Node::create();
if (_root) if (_root)
{ {
_root->retain(); _root->retain();
@ -19,6 +19,11 @@ e2d::Scene::Scene()
} }
} }
e2d::Scene * e2d::Scene::create()
{
return Create<Scene>();
}
e2d::Scene::~Scene() e2d::Scene::~Scene()
{ {
} }

View File

@ -78,6 +78,31 @@ e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * dis
this->setClickFunc(func); this->setClickFunc(func);
} }
e2d::Button * e2d::Button::create()
{
return Create<Button>();
}
e2d::Button * e2d::Button::create(Node * normal, const Function & func)
{
return Create<Button>(normal, func);
}
e2d::Button * e2d::Button::create(Node * normal, Node * selected, const Function & func)
{
return Create<Button>(normal, selected, func);
}
e2d::Button * e2d::Button::create(Node * normal, Node * mouseover, Node * selected, const Function & func)
{
return Create<Button>(normal, mouseover, selected, func);
}
e2d::Button * e2d::Button::create(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Function & func)
{
return Create<Button>(normal, mouseover, selected, disabled, func);
}
bool e2d::Button::isEnable() const bool e2d::Button::isEnable() const
{ {
return _enable; return _enable;

View File

@ -74,6 +74,31 @@ e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, N
this->setClickFunc(func); this->setClickFunc(func);
} }
e2d::ButtonToggle * e2d::ButtonToggle::create()
{
return Create<ButtonToggle>();
}
e2d::ButtonToggle * e2d::ButtonToggle::create(Node * onNormal, Node * offNormal, const Function & func)
{
return Create<ButtonToggle>(onNormal, offNormal, func);
}
e2d::ButtonToggle * e2d::ButtonToggle::create(Node * onNormal, Node * offNormal, Node * onSelected, Node * offSelected, const Function & func)
{
return Create<ButtonToggle>(onNormal, offNormal, onSelected, offSelected, func);
}
e2d::ButtonToggle * e2d::ButtonToggle::create(Node * onNormal, Node * offNormal, Node * onMouseOver, Node * offMouseOver, Node * onSelected, Node * offSelected, const Function & func)
{
return Create<ButtonToggle>(onNormal, offNormal, onMouseOver, offMouseOver, onSelected, offSelected, func);
}
e2d::ButtonToggle * e2d::ButtonToggle::create(Node * onNormal, Node * offNormal, Node * onMouseOver, Node * offMouseOver, Node * onSelected, Node * offSelected, Node * onDisabled, Node * offDisabled, const Function & func)
{
return Create<ButtonToggle>(onNormal, offNormal, onMouseOver, offMouseOver, onSelected, offSelected, onDisabled, offDisabled, func);
}
bool e2d::ButtonToggle::getState() const bool e2d::ButtonToggle::getState() const
{ {
return _toggle; return _toggle;

View File

@ -14,6 +14,16 @@ e2d::Menu::Menu(const std::vector<Button*>& buttons)
} }
} }
e2d::Menu * e2d::Menu::create()
{
return Create<Menu>();
}
e2d::Menu * e2d::Menu::create(const std::vector<Button*>& buttons)
{
return Create<Menu>(buttons);
}
bool e2d::Menu::isEnable() const bool e2d::Menu::isEnable() const
{ {
return _enable; return _enable;

View File

@ -38,10 +38,15 @@ e2d::Node::Node()
{ {
if (s_fDefaultColliderEnabled) if (s_fDefaultColliderEnabled)
{ {
this->setCollider(new ColliderRect(this)); this->setCollider(Create<ColliderRect>(this));
} }
} }
e2d::Node * e2d::Node::create()
{
return Create<Node>();
}
e2d::Node::~Node() e2d::Node::~Node()
{ {
} }
@ -547,19 +552,19 @@ void e2d::Node::setCollider(ColliderType nColliderType)
{ {
case ColliderType::RECT: case ColliderType::RECT:
{ {
this->setCollider(new ColliderRect(this)); this->setCollider(Create<ColliderRect>(this));
break; break;
} }
case ColliderType::CIRCLE: case ColliderType::CIRCLE:
{ {
this->setCollider(new ColliderCircle(this)); this->setCollider(Create<ColliderCircle>(this));
break; break;
} }
case ColliderType::ELLIPSE: case ColliderType::ELLIPSE:
{ {
this->setCollider(new ColliderEllipse(this)); this->setCollider(Create<ColliderEllipse>(this));
break; break;
} }

View File

@ -19,11 +19,19 @@ e2d::Circle::Circle(Point center, double radius)
this->setPivot(0.5, 0.5); this->setPivot(0.5, 0.5);
} }
e2d::Circle::Circle(double centerX, double centerY, double radius) e2d::Circle * e2d::Circle::create()
{ {
this->setRadius(radius); return Create<Circle>();
this->setPos(centerX, centerY); }
this->setPivot(0.5, 0.5);
e2d::Circle * e2d::Circle::create(double radius)
{
return Create<Circle>(radius);
}
e2d::Circle * e2d::Circle::create(Point center, double radius)
{
return Create<Circle>(center, radius);
} }
e2d::Circle::~Circle() e2d::Circle::~Circle()

View File

@ -22,12 +22,19 @@ e2d::Ellipse::Ellipse(Point center, double radiusX, double radiusY)
this->setPivot(0.5, 0.5); this->setPivot(0.5, 0.5);
} }
e2d::Ellipse::Ellipse(double centerX, double centerY, double radiusX, double radiusY) e2d::Ellipse * e2d::Ellipse::create()
{ {
this->setRadiusX(radiusX); return Create<Ellipse>();
this->setRadiusY(radiusY); }
this->setPos(centerX, centerY);
this->setPivot(0.5, 0.5); e2d::Ellipse * e2d::Ellipse::create(double radiusX, double radiusY)
{
return Create<Ellipse>(radiusX, radiusY);
}
e2d::Ellipse * e2d::Ellipse::create(Point center, double radiusX, double radiusY)
{
return Create<Ellipse>(center, radiusX, radiusY);
} }
e2d::Ellipse::~Ellipse() e2d::Ellipse::~Ellipse()

View File

@ -4,23 +4,11 @@ e2d::Rect::Rect()
{ {
} }
e2d::Rect::Rect(double width, double height)
{
this->setSize(width, height);
}
e2d::Rect::Rect(Size size) e2d::Rect::Rect(Size size)
{ {
this->setSize(size); this->setSize(size);
} }
e2d::Rect::Rect(double top, double left, double width, double height)
{
this->setPivot(0, 0);
this->setPos(top, left);
this->setSize(width, height);
}
e2d::Rect::Rect(Point topLeft, Size size) e2d::Rect::Rect(Point topLeft, Size size)
{ {
this->setPivot(0, 0); this->setPivot(0, 0);
@ -28,6 +16,21 @@ e2d::Rect::Rect(Point topLeft, Size size)
this->setSize(size); this->setSize(size);
} }
e2d::Rect * e2d::Rect::create()
{
return Create<Rect>();
}
e2d::Rect * e2d::Rect::create(Size size)
{
return Create<Rect>(size);
}
e2d::Rect * e2d::Rect::create(Point topLeft, Size size)
{
return Create<Rect>(topLeft, size);
}
e2d::Rect::~Rect() e2d::Rect::~Rect()
{ {
} }

View File

@ -6,13 +6,6 @@ e2d::RoundRect::RoundRect()
{ {
} }
e2d::RoundRect::RoundRect(double width, double height, double radiusX, double radiusY)
: _radiusX(float(radiusX))
, _radiusY(float(radiusY))
{
this->setSize(width, height);
}
e2d::RoundRect::RoundRect(Size size, double radiusX, double radiusY) e2d::RoundRect::RoundRect(Size size, double radiusX, double radiusY)
: _radiusX(float(radiusX)) : _radiusX(float(radiusX))
, _radiusY(float(radiusY)) , _radiusY(float(radiusY))
@ -20,15 +13,6 @@ e2d::RoundRect::RoundRect(Size size, double radiusX, double radiusY)
this->setSize(size); this->setSize(size);
} }
e2d::RoundRect::RoundRect(double top, double left, double width, double height, double radiusX, double radiusY)
: _radiusX(float(radiusX))
, _radiusY(float(radiusY))
{
this->setPivot(0, 0);
this->setPos(top, left);
this->setSize(width, height);
}
e2d::RoundRect::RoundRect(Point topLeft, Size size, double radiusX, double radiusY) e2d::RoundRect::RoundRect(Point topLeft, Size size, double radiusX, double radiusY)
: _radiusX(float(radiusX)) : _radiusX(float(radiusX))
, _radiusY(float(radiusY)) , _radiusY(float(radiusY))
@ -38,6 +22,21 @@ e2d::RoundRect::RoundRect(Point topLeft, Size size, double radiusX, double radiu
this->setSize(size); this->setSize(size);
} }
e2d::RoundRect * e2d::RoundRect::create()
{
return Create<RoundRect>();
}
e2d::RoundRect * e2d::RoundRect::create(Size size, double radiusX, double radiusY)
{
return Create<RoundRect>(size, radiusX, radiusY);
}
e2d::RoundRect * e2d::RoundRect::create(Point topLeft, Size size, double radiusX, double radiusY)
{
return Create<RoundRect>(topLeft, size, radiusX, radiusY);
}
e2d::RoundRect::~RoundRect() e2d::RoundRect::~RoundRect()
{ {
} }

View File

@ -2,7 +2,7 @@
e2d::Shape::Shape() e2d::Shape::Shape()
: _style(ShapeStyle::SOLID) : _style(ShapeStyle::SOLID)
, _fillColor(Color::WHITE) , _fillColor(Color::BLUE, 0.3)
, _lineColor(Color::BLUE, 0.5) , _lineColor(Color::BLUE, 0.5)
, _strokeWidth(1) , _strokeWidth(1)
{ {

View File

@ -38,6 +38,36 @@ e2d::Sprite::Sprite(int resNameId, const String& resType, double x, double y, do
crop(x, y, width, height); crop(x, y, width, height);
} }
e2d::Sprite * e2d::Sprite::create()
{
return Create<Sprite>();
}
e2d::Sprite * e2d::Sprite::create(Image * image)
{
return Create<Sprite>(image);
}
e2d::Sprite * e2d::Sprite::create(const String & filePath)
{
return Create<Sprite>(filePath);
}
e2d::Sprite * e2d::Sprite::create(int resNameId, const String & resType)
{
return Create<Sprite>(resNameId, resType);
}
e2d::Sprite * e2d::Sprite::create(const String & filePath, double x, double y, double width, double height)
{
return Create<Sprite>(filePath, x, y, width, height);
}
e2d::Sprite * e2d::Sprite::create(int resNameId, const String & resType, double x, double y, double width, double height)
{
return Create<Sprite>(resNameId, resType, x, y, width, height);
}
e2d::Sprite::~Sprite() e2d::Sprite::~Sprite()
{ {
} }
@ -60,7 +90,7 @@ bool e2d::Sprite::open(const String& filePath)
{ {
if (!_image) if (!_image)
{ {
_image = new (std::nothrow) Image(); _image = Create<Image>();
_image->retain(); _image->retain();
} }
@ -76,7 +106,7 @@ bool e2d::Sprite::open(int resNameId, const String& resType)
{ {
if (!_image) if (!_image)
{ {
_image = new (std::nothrow) Image(); _image = Create<Image>();
_image->retain(); _image->retain();
} }

View File

@ -74,6 +74,31 @@ e2d::Text::Text(
_reset(); _reset();
} }
e2d::Text * e2d::Text::create()
{
return Create<Text>();
}
e2d::Text * e2d::Text::create(const String & text)
{
return Create<Text>(text);
}
e2d::Text * e2d::Text::create(TextStyle textStyle)
{
return Create<Text>(textStyle);
}
e2d::Text * e2d::Text::create(const String & text, TextStyle textStyle)
{
return Create<Text>(text, textStyle);
}
e2d::Text * e2d::Text::create(const String & text, const String & fontFamily, double fontSize, UINT32 color, UINT32 fontWeight, bool italic, TextAlign alignment, bool wrapping, double wrappingWidth, double lineSpacing, bool hasUnderline, bool hasStrikethrough, bool hasOutline, UINT32 outlineColor, UINT32 outlineWidth)
{
return Create<Text>(text, fontFamily, fontSize, color, fontWeight, italic, alignment, wrapping, wrappingWidth, lineSpacing, hasUnderline, hasStrikethrough, hasOutline, outlineColor, outlineWidth);
}
e2d::Text::~Text() e2d::Text::~Text()
{ {
SafeReleaseInterface(_textFormat); SafeReleaseInterface(_textFormat);

View File

@ -442,7 +442,7 @@ bool MusicPlayer::_readMMIO()
// 的数据,这个数据就是额外分配的大小 // 的数据,这个数据就是额外分配的大小
if (pcmWaveFormat.wf.wFormatTag == WAVE_FORMAT_PCM) if (pcmWaveFormat.wf.wFormatTag == WAVE_FORMAT_PCM)
{ {
_pwfx = (WAVEFORMATEX*)new (std::nothrow) CHAR[sizeof(WAVEFORMATEX)]; _pwfx = (WAVEFORMATEX*) new (std::nothrow) CHAR[sizeof(WAVEFORMATEX)];
// 拷贝数据 // 拷贝数据
memcpy(_pwfx, &pcmWaveFormat, sizeof(pcmWaveFormat)); memcpy(_pwfx, &pcmWaveFormat, sizeof(pcmWaveFormat));
@ -455,7 +455,7 @@ bool MusicPlayer::_readMMIO()
if (mmioRead(_hmmio, (CHAR*)&cbExtraBytes, sizeof(WORD)) != sizeof(WORD)) if (mmioRead(_hmmio, (CHAR*)&cbExtraBytes, sizeof(WORD)) != sizeof(WORD))
return TraceError(L"mmioRead"); return TraceError(L"mmioRead");
_pwfx = (WAVEFORMATEX*)new (std::nothrow) CHAR[sizeof(WAVEFORMATEX) + cbExtraBytes]; _pwfx = (WAVEFORMATEX*) new (std::nothrow) CHAR[sizeof(WAVEFORMATEX) + cbExtraBytes];
// 拷贝数据 // 拷贝数据
memcpy(_pwfx, &pcmWaveFormat, sizeof(pcmWaveFormat)); memcpy(_pwfx, &pcmWaveFormat, sizeof(pcmWaveFormat));

View File

@ -6,6 +6,11 @@ e2d::TransitionEmerge::TransitionEmerge(double duration)
{ {
} }
e2d::TransitionEmerge * e2d::TransitionEmerge::create(double duration)
{
return Create<TransitionEmerge>(duration);
}
void e2d::TransitionEmerge::_init(Scene * prev, Scene * next) void e2d::TransitionEmerge::_init(Scene * prev, Scene * next)
{ {
Transition::_init(prev, next); Transition::_init(prev, next);

View File

@ -17,6 +17,16 @@ e2d::TransitionFade::TransitionFade(double fadeOutDuration, double fadeInDuratio
{ {
} }
e2d::TransitionFade * e2d::TransitionFade::create(double duration)
{
return Create<TransitionFade>(duration);
}
e2d::TransitionFade * e2d::TransitionFade::create(double fadeOutDuration, double fadeInDuration)
{
return Create<TransitionFade>(fadeOutDuration, fadeInDuration);
}
void e2d::TransitionFade::_init(Scene * prev, Scene * next) void e2d::TransitionFade::_init(Scene * prev, Scene * next)
{ {
Transition::_init(prev, next); Transition::_init(prev, next);

View File

@ -7,6 +7,11 @@ e2d::TransitionMove::TransitionMove(double duration, Direction direction)
{ {
} }
e2d::TransitionMove * e2d::TransitionMove::create(double moveDuration, Direction direction)
{
return Create<TransitionMove>(moveDuration, direction);
}
void e2d::TransitionMove::_init(Scene * prev, Scene * next) void e2d::TransitionMove::_init(Scene * prev, Scene * next)
{ {
Transition::_init(prev, next); Transition::_init(prev, next);

View File

@ -122,12 +122,17 @@ class MoveBy :
public ActionGradual public ActionGradual
{ {
public: public:
// 创建相对位移动作
MoveBy( MoveBy(
double duration, /* 持续时长 */ double duration, /* 持续时长 */
Vector vector /* 移动距离 */ Vector vector /* 移动距离 */
); );
// 创建相对位移动作
static MoveBy * create(
double duration, /* 持续时长 */
Vector vector /* 移动距离 */
);
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual MoveBy * clone() const override; virtual MoveBy * clone() const override;
@ -152,12 +157,17 @@ class MoveTo :
public MoveBy public MoveBy
{ {
public: public:
// 创建位移动作
MoveTo( MoveTo(
double duration, /* 持续时长 */ double duration, /* 持续时长 */
Point pos /* 目的坐标 */ Point pos /* 目的坐标 */
); );
// 创建位移动作
static MoveTo * create(
double duration, /* 持续时长 */
Point pos /* 目的坐标 */
);
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual MoveTo * clone() const override; virtual MoveTo * clone() const override;
@ -182,7 +192,6 @@ class JumpBy :
public ActionGradual public ActionGradual
{ {
public: public:
// 创建相对跳跃动作
JumpBy( JumpBy(
double duration, /* 持续时长 */ double duration, /* 持续时长 */
const Vector& vec, /* 跳跃距离 */ const Vector& vec, /* 跳跃距离 */
@ -190,6 +199,14 @@ public:
int jumps /* 跳跃次数 */ int jumps /* 跳跃次数 */
); );
// 创建相对跳跃动作
static JumpBy * create(
double duration, /* 持续时长 */
const Vector& vec, /* 跳跃距离 */
double height, /* 跳跃高度 */
int jumps /* 跳跃次数 */
);
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual JumpBy * clone() const override; virtual JumpBy * clone() const override;
@ -217,7 +234,6 @@ class JumpTo :
public JumpBy public JumpBy
{ {
public: public:
// 创建位移动作
JumpTo( JumpTo(
double duration, /* 持续时长 */ double duration, /* 持续时长 */
const Point& pos, /* 目的坐标 */ const Point& pos, /* 目的坐标 */
@ -225,6 +241,14 @@ public:
int jumps /* 跳跃次数 */ int jumps /* 跳跃次数 */
); );
// 创建位移动作
static JumpTo * create(
double duration, /* 持续时长 */
const Point& pos, /* 目的坐标 */
double height, /* 跳跃高度 */
int jumps /* 跳跃次数 */
);
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual JumpTo * clone() const override; virtual JumpTo * clone() const override;
@ -249,19 +273,30 @@ class ScaleBy :
public ActionGradual public ActionGradual
{ {
public: public:
// 创建相对缩放动作
ScaleBy( ScaleBy(
double duration, /* 持续时长 */ double duration, /* 持续时长 */
double scale /* 缩放比例变化 */ double scale /* 缩放比例变化 */
); );
// 创建相对缩放动作
ScaleBy( ScaleBy(
double duration, /* 持续时长 */ double duration, /* 持续时长 */
double scaleX, /* 横向缩放比例变化 */ double scaleX, /* 横向缩放比例变化 */
double scaleY /* 纵向缩放比例变化 */ double scaleY /* 纵向缩放比例变化 */
); );
// 创建相对缩放动作
static ScaleBy * create(
double duration, /* 持续时长 */
double scale /* 缩放比例变化 */
);
// 创建相对缩放动作
static ScaleBy * create(
double duration, /* 持续时长 */
double scaleX, /* 横向缩放比例变化 */
double scaleY /* 纵向缩放比例变化 */
);
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual ScaleBy * clone() const override; virtual ScaleBy * clone() const override;
@ -288,19 +323,30 @@ class ScaleTo :
public ScaleBy public ScaleBy
{ {
public: public:
// 创建缩放动作
ScaleTo( ScaleTo(
double duration, /* 持续时长 */ double duration, /* 持续时长 */
double scale /* 缩放至目标比例 */ double scale /* 缩放至目标比例 */
); );
// 创建缩放动作
ScaleTo( ScaleTo(
double duration, /* 持续时长 */ double duration, /* 持续时长 */
double scaleX, /* 横向缩放至目标比例 */ double scaleX, /* 横向缩放至目标比例 */
double scaleY /* 纵向缩放至目标比例 */ double scaleY /* 纵向缩放至目标比例 */
); );
// 创建缩放动作
static ScaleTo * create(
double duration, /* 持续时长 */
double scale /* 缩放至目标比例 */
);
// 创建缩放动作
static ScaleTo * create(
double duration, /* 持续时长 */
double scaleX, /* 横向缩放至目标比例 */
double scaleY /* 纵向缩放至目标比例 */
);
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual ScaleTo * clone() const override; virtual ScaleTo * clone() const override;
@ -326,12 +372,17 @@ class OpacityBy :
public ActionGradual public ActionGradual
{ {
public: public:
// 创建透明度相对渐变动作
OpacityBy( OpacityBy(
double duration, /* 持续时长 */ double duration, /* 持续时长 */
double opacity /* 透明度相对变化值 */ double opacity /* 透明度相对变化值 */
); );
// 创建透明度相对渐变动作
static OpacityBy * create(
double duration, /* 持续时长 */
double opacity /* 透明度相对变化值 */
);
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual OpacityBy * clone() const override; virtual OpacityBy * clone() const override;
@ -356,12 +407,17 @@ class OpacityTo :
public OpacityBy public OpacityBy
{ {
public: public:
// 创建透明度渐变动作
OpacityTo( OpacityTo(
double duration, /* 持续时长 */ double duration, /* 持续时长 */
double opacity /* 透明度渐变至目标值 */ double opacity /* 透明度渐变至目标值 */
); );
// 创建透明度渐变动作
static OpacityTo * create(
double duration, /* 持续时长 */
double opacity /* 透明度渐变至目标值 */
);
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual OpacityTo * clone() const override; virtual OpacityTo * clone() const override;
@ -416,12 +472,17 @@ class RotateBy :
public ActionGradual public ActionGradual
{ {
public: public:
// 创建相对旋转动作
RotateBy( RotateBy(
double duration, /* 持续时长 */ double duration, /* 持续时长 */
double rotation /* 旋转角度变化值 */ double rotation /* 旋转角度变化值 */
); );
// 创建相对旋转动作
static RotateBy * create(
double duration, /* 持续时长 */
double rotation /* 旋转角度变化值 */
);
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual RotateBy * clone() const override; virtual RotateBy * clone() const override;
@ -446,12 +507,17 @@ class RotateTo :
public RotateBy public RotateBy
{ {
public: public:
// 创建旋转动作
RotateTo( RotateTo(
double duration, /* 持续时长 */ double duration, /* 持续时长 */
double rotation /* 旋转角度至目标值 */ double rotation /* 旋转角度至目标值 */
); );
// 创建旋转动作
static RotateTo * create(
double duration, /* 持续时长 */
double rotation /* 旋转角度至目标值 */
);
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual RotateTo * clone() const override; virtual RotateTo * clone() const override;
@ -476,11 +542,15 @@ class Delay :
public Action public Action
{ {
public: public:
// 创建延时动作
Delay( Delay(
double duration /* 延迟时长(秒) */ double duration /* 延迟时长(秒) */
); );
// 创建延时动作
static Delay * create(
double duration /* 延迟时长(秒) */
);
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual Delay * clone() const override; virtual Delay * clone() const override;
@ -511,12 +581,17 @@ class Loop :
public Action public Action
{ {
public: public:
// 创建循环动作
Loop( Loop(
Action * action, /* 执行循环的动作 */ Action * action, /* 执行循环的动作 */
int times = -1 /* 循环次数 */ int times = -1 /* 循环次数 */
); );
// 创建循环动作
static Loop * create(
Action * action, /* 执行循环的动作 */
int times = -1 /* 循环次数 */
);
virtual ~Loop(); virtual ~Loop();
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
@ -553,11 +628,15 @@ class CallFunc :
public Action public Action
{ {
public: public:
// 创建执行函数对象的动作
CallFunc( CallFunc(
const Function& func /* 函数对象 */ const Function& func /* 函数对象 */
); );
// 创建执行函数对象的动作
static CallFunc * create(
const Function& func /* 函数对象 */
);
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual CallFunc * clone() const override; virtual CallFunc * clone() const override;
@ -581,14 +660,20 @@ class Sequence :
public Action public Action
{ {
public: public:
// 创建顺序动作
Sequence(); Sequence();
// 创建顺序动作
Sequence( Sequence(
const std::vector<Action*>& actions /* 动作列表 */ const std::vector<Action*>& actions /* 动作列表 */
); );
// 创建顺序动作
static Sequence * create();
// 创建顺序动作
static Sequence * create(
const std::vector<Action*>& actions /* 动作列表 */
);
virtual ~Sequence(); virtual ~Sequence();
// 在结尾添加动作 // 在结尾添加动作
@ -634,14 +719,20 @@ class Spawn :
public Action public Action
{ {
public: public:
// 创建同步动作
Spawn(); Spawn();
// 创建同步动作
Spawn( Spawn(
const std::vector<Action*>& actions /* 动作列表 */ const std::vector<Action*>& actions /* 动作列表 */
); );
// 创建同步动作
static Spawn * create();
// 创建同步动作
static Spawn * create(
const std::vector<Action*>& actions /* 动作列表 */
);
virtual ~Spawn(); virtual ~Spawn();
// 在结尾添加动作 // 在结尾添加动作
@ -686,14 +777,20 @@ class Animate :
public Action public Action
{ {
public: public:
// 创建精灵动作
Animate(); Animate();
// 创建精灵动作
Animate( Animate(
Animation * animation Animation * animation
); );
// 创建精灵动作
static Animate * create();
// 创建精灵动作
static Animate * create(
Animation * animation
);
virtual ~Animate(); virtual ~Animate();
// 获取动画 // 获取动画

View File

@ -74,15 +74,13 @@ protected:
}; };
// 矩形 // 矩形碰撞体
class ColliderRect : class ColliderRect :
public Collider public Collider
{ {
public: public:
// 创建一个默认矩形
ColliderRect(); ColliderRect();
// 根据左上角坐标和宽高创建矩形
ColliderRect( ColliderRect(
double x, double x,
double y, double y,
@ -90,14 +88,29 @@ public:
double height double height
); );
// 创建一个和节点位置大小相同的矩形
ColliderRect( ColliderRect(
Node * node Node * node
); );
// 创建一个默认矩形碰撞体
static ColliderRect * create();
// 根据左上角坐标和宽高创建矩形碰撞体
static ColliderRect * create(
double x,
double y,
double width,
double height
);
// 创建一个和节点位置大小相同的矩形碰撞体
static ColliderRect * create(
Node * node
);
virtual ~ColliderRect(); virtual ~ColliderRect();
// 修改矩形大小 // 修改矩形碰撞体大小
void setRect( void setRect(
double left, double left,
double top, double top,
@ -117,28 +130,39 @@ protected:
}; };
// 圆形 // 圆形碰撞体
class ColliderCircle : class ColliderCircle :
public Collider public Collider
{ {
public: public:
// 创建一个默认圆形
ColliderCircle(); ColliderCircle();
// 根据圆心和半径创建圆形
ColliderCircle( ColliderCircle(
Point center, Point center,
double radius double radius
); );
// 创建一个和节点位置大小相同的圆形
ColliderCircle( ColliderCircle(
Node * node Node * node
); );
// 创建一个默认圆形碰撞体
static ColliderCircle * create();
// 根据圆心和半径创建圆形碰撞体
static ColliderCircle * create(
Point center,
double radius
);
// 创建一个和节点位置大小相同的圆形碰撞体
static ColliderCircle * create(
Node * node
);
virtual ~ColliderCircle(); virtual ~ColliderCircle();
// 修改圆形大小 // 修改圆形碰撞体大小
void setCircle( void setCircle(
Point center, Point center,
double radius double radius
@ -156,29 +180,41 @@ protected:
}; };
// 椭圆形 // 椭圆形碰撞体
class ColliderEllipse : class ColliderEllipse :
public Collider public Collider
{ {
public: public:
// 创建一个默认椭圆
ColliderEllipse(); ColliderEllipse();
// 根据圆心和半径创建椭圆
ColliderEllipse( ColliderEllipse(
Point center, Point center,
double radiusX, double radiusX,
double radiusY double radiusY
); );
// 创建一个和节点位置大小相同的椭圆
ColliderEllipse( ColliderEllipse(
Node * node Node * node
); );
// 创建一个默认椭圆碰撞体
static ColliderEllipse * create();
// 根据圆心和半径创建椭圆碰撞体
static ColliderEllipse * create(
Point center,
double radiusX,
double radiusY
);
// 创建一个和节点位置大小相同的椭圆碰撞体
static ColliderEllipse * create(
Node * node
);
virtual ~ColliderEllipse(); virtual ~ColliderEllipse();
// 修改椭圆大小 // 修改椭圆碰撞体大小
void setEllipse( void setEllipse(
Point center, Point center,
double radiusX, double radiusX,

View File

@ -603,26 +603,17 @@ class Image :
public Object public Object
{ {
public: public:
// 创建一个空的图片对象
Image(); Image();
// 加载图片文件
Image( Image(
const String& filePath /* 图片文件路径 */ const String& filePath /* 图片文件路径 */
); );
// 加载图片资源
Image( Image(
int resNameId, /* 图片资源名称 */ int resNameId, /* 图片资源名称 */
const String& resType /* 图片资源类型 */ const String& resType /* 图片资源类型 */
); );
// 加载位图
Image(
ID2D1Bitmap * bitmap /* 位图资源 */
);
// 加载图片文件并裁剪
Image( Image(
const String& filePath, /* 图片文件路径 */ const String& filePath, /* 图片文件路径 */
double cropX, /* 裁剪位置 X 坐标 */ double cropX, /* 裁剪位置 X 坐标 */
@ -631,7 +622,6 @@ public:
double cropHeight /* 裁剪高度 */ double cropHeight /* 裁剪高度 */
); );
// 加载图片资源并裁剪
Image( Image(
int resNameId, /* 图片资源名称 */ int resNameId, /* 图片资源名称 */
const String& resType, /* 图片资源类型 */ const String& resType, /* 图片资源类型 */
@ -641,6 +631,39 @@ public:
double cropHeight /* 裁剪高度 */ double cropHeight /* 裁剪高度 */
); );
// 创建一个空的图片对象
static Image * create();
// 加载图片文件
static Image * create(
const String& filePath /* 图片文件路径 */
);
// 加载图片资源
static Image * create(
int resNameId, /* 图片资源名称 */
const String& resType /* 图片资源类型 */
);
// 加载图片文件并裁剪
static Image * create(
const String& filePath, /* 图片文件路径 */
double cropX, /* 裁剪位置 X 坐标 */
double cropY, /* 裁剪位置 Y 坐标 */
double cropWidth, /* 裁剪宽度 */
double cropHeight /* 裁剪高度 */
);
// 加载图片资源并裁剪
static Image * create(
int resNameId, /* 图片资源名称 */
const String& resType, /* 图片资源类型 */
double cropX, /* 裁剪位置 X 坐标 */
double cropY, /* 裁剪位置 Y 坐标 */
double cropWidth, /* 裁剪宽度 */
double cropHeight /* 裁剪高度 */
);
virtual ~Image(); virtual ~Image();
// 加载图片文件 // 加载图片文件
@ -654,11 +677,6 @@ public:
const String& resType /* 图片资源类型 */ const String& resType /* 图片资源类型 */
); );
// 加载位图
bool open(
ID2D1Bitmap * bitmap /* 位图资源 */
);
// 将图片裁剪为矩形 // 将图片裁剪为矩形
void crop( void crop(
double cropX, /* 裁剪位置 X 坐标 */ double cropX, /* 裁剪位置 X 坐标 */
@ -731,25 +749,40 @@ class Animation :
public Object public Object
{ {
public: public:
// 创建帧动画
Animation(); Animation();
// 创建帧动画
Animation( Animation(
const std::vector<Image*>& frames /* 关键帧数组 */ const std::vector<Image*>& frames /* 关键帧数组 */
); );
// 创建特定帧间隔的帧动画
Animation( Animation(
double interval /* 帧间隔(秒) */ double interval /* 帧间隔(秒) */
); );
// 创建特定帧间隔的帧动画
Animation( Animation(
double interval, /* 帧间隔(秒) */ double interval, /* 帧间隔(秒) */
const std::vector<Image*>& frames /* 关键帧数组 */ const std::vector<Image*>& frames /* 关键帧数组 */
); );
// 创建帧动画
static Animation * create();
// 创建帧动画
static Animation * create(
const std::vector<Image*>& frames /* 关键帧数组 */
);
// 创建特定帧间隔的帧动画
static Animation * create(
double interval /* 帧间隔(秒) */
);
// 创建特定帧间隔的帧动画
static Animation * create(
double interval, /* 帧间隔(秒) */
const std::vector<Image*>& frames /* 关键帧数组 */
);
virtual ~Animation(); virtual ~Animation();
// 添加关键帧 // 添加关键帧
@ -799,6 +832,9 @@ class Scene :
public: public:
Scene(); Scene();
// 创建场景
static Scene * create();
virtual ~Scene(); virtual ~Scene();
// 重写这个函数,它将在进入这个场景时自动执行 // 重写这个函数,它将在进入这个场景时自动执行
@ -879,7 +915,23 @@ protected:
}; };
template <class Type> template <typename Type, typename... Types>
inline Type * Create(Types&&... args)
{
auto newObj = new (std::nothrow) Type(std::forward<Types>(args)...);
if (newObj)
{
newObj->autorelease();
return newObj;
}
else
{
return nullptr;
}
}
template <typename Type>
inline void SafeRelease(Type*& p) inline void SafeRelease(Type*& p)
{ {
if (p != nullptr) if (p != nullptr)

View File

@ -21,6 +21,9 @@ class Node :
public: public:
Node(); Node();
// 创建空节点
static Node * create();
virtual ~Node(); virtual ~Node();
// 更新节点 // 更新节点
@ -473,26 +476,21 @@ class Sprite :
public Node public Node
{ {
public: public:
// 创建一个空精灵
Sprite(); Sprite();
// 从 Image 对象创建精灵
Sprite( Sprite(
Image * image Image * image
); );
// 加载图片文件
Sprite( Sprite(
const String& filePath /* 图片文件路径 */ const String& filePath /* 图片文件路径 */
); );
// 加载图片资源
Sprite( Sprite(
int resNameId, /* 图片资源名称 */ int resNameId, /* 图片资源名称 */
const String& resType /* 图片资源类型 */ const String& resType /* 图片资源类型 */
); );
// 加载图片文件
Sprite( Sprite(
const String& filePath, /* 图片文件路径 */ const String& filePath, /* 图片文件路径 */
double x, double x,
@ -501,7 +499,6 @@ public:
double height double height
); );
// 加载图片资源
Sprite( Sprite(
int resNameId, /* 图片资源名称 */ int resNameId, /* 图片资源名称 */
const String& resType, /* 图片资源类型 */ const String& resType, /* 图片资源类型 */
@ -511,6 +508,44 @@ public:
double height double height
); );
// 创建一个空精灵
static Sprite * create();
// 从 Image 对象创建精灵
static Sprite * create(
Image * image
);
// 加载图片文件
static Sprite * create(
const String& filePath /* 图片文件路径 */
);
// 加载图片资源
static Sprite * create(
int resNameId, /* 图片资源名称 */
const String& resType /* 图片资源类型 */
);
// 加载图片文件
static Sprite * create(
const String& filePath, /* 图片文件路径 */
double x,
double y,
double width,
double height
);
// 加载图片资源
static Sprite * create(
int resNameId, /* 图片资源名称 */
const String& resType, /* 图片资源类型 */
double x,
double y,
double width,
double height
);
virtual ~Sprite(); virtual ~Sprite();
// 加载图片文件 // 加载图片文件
@ -589,6 +624,39 @@ public:
UINT32 outlineWidth = 1.0 /* 描边线宽 */ UINT32 outlineWidth = 1.0 /* 描边线宽 */
); );
static Text * create();
static Text * create(
const String& text /* 文字内容 */
);
static Text * create(
TextStyle textStyle /* 文字样式 */
);
static Text * create(
const String& text, /* 文字内容 */
TextStyle textStyle /* 文字样式 */
);
static Text * create(
const String& text, /* 文字内容*/
const String& fontFamily, /* 字体 */
double fontSize = 22, /* 字号 */
UINT32 color = Color::WHITE, /* 颜色 */
UINT32 fontWeight = FontWeight::NORMAL, /* 粗细值 */
bool italic = false, /* 斜体 */
TextAlign alignment = TextAlign::LEFT, /* 对齐方式 */
bool wrapping = false, /* 打开自动换行 */
double wrappingWidth = 0.0, /* 自动换行宽度 */
double lineSpacing = 0.0, /* 行间距 */
bool hasUnderline = false, /* 下划线 */
bool hasStrikethrough = false, /* 删除线 */
bool hasOutline = true, /* 显示描边 */
UINT32 outlineColor = Color::BLACK, /* 描边颜色 */
UINT32 outlineWidth = 1.0 /* 描边线宽 */
);
virtual ~Text(); virtual ~Text();
// 获取文本 // 获取文本
@ -743,23 +811,19 @@ class Button :
public Node public Node
{ {
public: public:
// 创建一个空按钮
Button(); Button();
// 创建按钮
Button( Button(
Node * normal, /* 普通状态 */ Node * normal, /* 普通状态 */
const Function& func = nullptr /* 按钮点击后的执行函数 */ const Function& func = nullptr /* 按钮点击后的执行函数 */
); );
// 创建按钮
Button( Button(
Node * normal, /* 普通状态 */ Node * normal, /* 普通状态 */
Node * selected, /* 鼠标按下状态 */ Node * selected, /* 鼠标按下状态 */
const Function& func = nullptr /* 按钮点击后的执行函数 */ const Function& func = nullptr /* 按钮点击后的执行函数 */
); );
// 创建按钮
Button( Button(
Node * normal, /* 普通状态 */ Node * normal, /* 普通状态 */
Node * mouseover, /* 鼠标移入状态 */ Node * mouseover, /* 鼠标移入状态 */
@ -767,7 +831,6 @@ public:
const Function& func = nullptr /* 按钮点击后的执行函数 */ const Function& func = nullptr /* 按钮点击后的执行函数 */
); );
// 创建按钮
Button( Button(
Node * normal, /* 普通状态 */ Node * normal, /* 普通状态 */
Node * mouseover, /* 鼠标移入状态 */ Node * mouseover, /* 鼠标移入状态 */
@ -776,6 +839,39 @@ public:
const Function& func = nullptr /* 按钮点击后的执行函数 */ const Function& func = nullptr /* 按钮点击后的执行函数 */
); );
// 创建一个空按钮
static Button * create();
// 创建按钮
static Button * create(
Node * normal, /* 普通状态 */
const Function& func = nullptr /* 按钮点击后的执行函数 */
);
// 创建按钮
static Button * create(
Node * normal, /* 普通状态 */
Node * selected, /* 鼠标按下状态 */
const Function& func = nullptr /* 按钮点击后的执行函数 */
);
// 创建按钮
static Button * create(
Node * normal, /* 普通状态 */
Node * mouseover, /* 鼠标移入状态 */
Node * selected, /* 鼠标按下状态 */
const Function& func = nullptr /* 按钮点击后的执行函数 */
);
// 创建按钮
static Button * create(
Node * normal, /* 普通状态 */
Node * mouseover, /* 鼠标移入状态 */
Node * selected, /* 鼠标移入状态 */
Node * disabled, /* 按钮禁用状态 */
const Function& func = nullptr /* 按钮点击后的执行函数 */
);
// 获取按钮状态是启用还是禁用 // 获取按钮状态是启用还是禁用
bool isEnable() const; bool isEnable() const;
@ -841,17 +937,14 @@ class ButtonToggle :
public Button public Button
{ {
public: public:
// 创建一个空的开关按钮
ButtonToggle(); ButtonToggle();
// 创建开关按钮
ButtonToggle( ButtonToggle(
Node * onNormal, /* 按钮打开时,普通状态 */ Node * onNormal, /* 按钮打开时,普通状态 */
Node * offNormal, /* 按钮关闭时,普通状态 */ Node * offNormal, /* 按钮关闭时,普通状态 */
const Function& func = nullptr /* 按钮点击后的执行函数 */ const Function& func = nullptr /* 按钮点击后的执行函数 */
); );
// 创建开关按钮
ButtonToggle( ButtonToggle(
Node * onNormal, /* 按钮打开时,普通状态 */ Node * onNormal, /* 按钮打开时,普通状态 */
Node * offNormal, /* 按钮关闭时,普通状态 */ Node * offNormal, /* 按钮关闭时,普通状态 */
@ -860,7 +953,6 @@ public:
const Function& func = nullptr /* 按钮点击后的执行函数 */ const Function& func = nullptr /* 按钮点击后的执行函数 */
); );
// 创建开关按钮
ButtonToggle( ButtonToggle(
Node * onNormal, /* 按钮打开时,普通状态 */ Node * onNormal, /* 按钮打开时,普通状态 */
Node * offNormal, /* 按钮关闭时,普通状态 */ Node * offNormal, /* 按钮关闭时,普通状态 */
@ -871,7 +963,6 @@ public:
const Function& func = nullptr /* 按钮点击后的执行函数 */ const Function& func = nullptr /* 按钮点击后的执行函数 */
); );
// 创建开关按钮
ButtonToggle( ButtonToggle(
Node * onNormal, /* 按钮打开时,普通状态 */ Node * onNormal, /* 按钮打开时,普通状态 */
Node * offNormal, /* 按钮关闭时,普通状态 */ Node * offNormal, /* 按钮关闭时,普通状态 */
@ -884,6 +975,49 @@ public:
const Function& func = nullptr /* 按钮点击后的执行函数 */ const Function& func = nullptr /* 按钮点击后的执行函数 */
); );
// 创建一个空的开关按钮
static ButtonToggle * create();
// 创建开关按钮
static ButtonToggle * create(
Node * onNormal, /* 按钮打开时,普通状态 */
Node * offNormal, /* 按钮关闭时,普通状态 */
const Function& func = nullptr /* 按钮点击后的执行函数 */
);
// 创建开关按钮
static ButtonToggle * create(
Node * onNormal, /* 按钮打开时,普通状态 */
Node * offNormal, /* 按钮关闭时,普通状态 */
Node * onSelected, /* 按钮打开时,鼠标按下状态 */
Node * offSelected, /* 按钮关闭时,鼠标按下状态 */
const Function& func = nullptr /* 按钮点击后的执行函数 */
);
// 创建开关按钮
static ButtonToggle * create(
Node * onNormal, /* 按钮打开时,普通状态 */
Node * offNormal, /* 按钮关闭时,普通状态 */
Node * onMouseOver, /* 按钮打开时,鼠标移入状态 */
Node * offMouseOver, /* 按钮关闭时,鼠标移入状态 */
Node * onSelected, /* 按钮打开时,鼠标按下状态 */
Node * offSelected, /* 按钮关闭时,鼠标按下状态 */
const Function& func = nullptr /* 按钮点击后的执行函数 */
);
// 创建开关按钮
static ButtonToggle * create(
Node * onNormal, /* 按钮打开时,普通状态 */
Node * offNormal, /* 按钮关闭时,普通状态 */
Node * onMouseOver, /* 按钮打开时,鼠标移入状态 */
Node * offMouseOver, /* 按钮关闭时,鼠标移入状态 */
Node * onSelected, /* 按钮打开时,鼠标按下状态 */
Node * offSelected, /* 按钮关闭时,鼠标按下状态 */
Node * onDisabled, /* 按钮打开时,禁用状态 */
Node * offDisabled, /* 按钮关闭时,禁用状态 */
const Function& func = nullptr /* 按钮点击后的执行函数 */
);
// 获取开关状态(打开或关闭) // 获取开关状态(打开或关闭)
bool getState() const; bool getState() const;
@ -952,14 +1086,20 @@ class Menu :
public Node public Node
{ {
public: public:
// 创建空菜单
Menu(); Menu();
// 创建菜单
Menu( Menu(
const std::vector<Button*>& buttons /* 按钮数组 */ const std::vector<Button*>& buttons /* 按钮数组 */
); );
// 创建空菜单
static Menu * create();
// 创建菜单
static Menu * create(
const std::vector<Button*>& buttons /* 按钮数组 */
);
// 获取菜单是否禁用 // 获取菜单是否禁用
bool isEnable() const; bool isEnable() const;

View File

@ -69,23 +69,22 @@ class Rect :
public: public:
Rect(); Rect();
Rect(
double width, /* 宽度 */
double height /* 高度 */
);
Rect( Rect(
Size size /* 宽度和高度 */ Size size /* 宽度和高度 */
); );
Rect( Rect(
double top, /* 左上角横坐标 */ Point topLeft, /* 左上角坐标 */
double left, /* 左上角纵坐标 */ Size size /* 宽度和高度 */
double width, /* 宽度 */
double height /* 高度 */
); );
Rect( static Rect * create();
static Rect * create(
Size size /* 宽度和高度 */
);
static Rect * create(
Point topLeft, /* 左上角坐标 */ Point topLeft, /* 左上角坐标 */
Size size /* 宽度和高度 */ Size size /* 宽度和高度 */
); );
@ -108,13 +107,6 @@ class RoundRect :
public: public:
RoundRect(); RoundRect();
RoundRect(
double width, /* 宽度 */
double height, /* 高度 */
double radiusX, /* 圆角半径 */
double radiusY /* 圆角半径 */
);
RoundRect( RoundRect(
Size size, /* 宽度和高度 */ Size size, /* 宽度和高度 */
double radiusX, /* 圆角半径 */ double radiusX, /* 圆角半径 */
@ -122,15 +114,21 @@ public:
); );
RoundRect( RoundRect(
double top, /* 左上角横坐标 */ Point topLeft, /* 左上角坐标 */
double left, /* 左上角纵坐标 */ Size size, /* 宽度和高度 */
double width, /* 宽度 */
double height, /* 高度 */
double radiusX, /* 圆角半径 */ double radiusX, /* 圆角半径 */
double radiusY /* 圆角半径 */ double radiusY /* 圆角半径 */
); );
RoundRect( static RoundRect * create();
static RoundRect * create(
Size size, /* 宽度和高度 */
double radiusX, /* 圆角半径 */
double radiusY /* 圆角半径 */
);
static RoundRect * create(
Point topLeft, /* 左上角坐标 */ Point topLeft, /* 左上角坐标 */
Size size, /* 宽度和高度 */ Size size, /* 宽度和高度 */
double radiusX, /* 圆角半径 */ double radiusX, /* 圆角半径 */
@ -184,9 +182,14 @@ public:
double radius /* 半径 */ double radius /* 半径 */
); );
Circle( static Circle * create();
double centerX, /* 圆心横坐标 */
double centerY, /* 圆心纵坐标 */ static Circle * create(
double radius /* 半径 */
);
static Circle * create(
Point center, /* 圆心坐标 */
double radius /* 半径 */ double radius /* 半径 */
); );
@ -230,9 +233,15 @@ public:
double radiusY /* 纵轴半径 */ double radiusY /* 纵轴半径 */
); );
Ellipse( static Ellipse * create();
double centerX, /* 圆心横坐标 */
double centerY, /* 圆心纵坐标 */ static Ellipse * create(
double radiusX, /* 横轴半径 */
double radiusY /* 纵轴半径 */
);
static Ellipse * create(
Point center, /* 圆心坐标 */
double radiusX, /* 横轴半径 */ double radiusX, /* 横轴半径 */
double radiusY /* 纵轴半径 */ double radiusY /* 纵轴半径 */
); );

View File

@ -51,8 +51,7 @@ private:
// 音乐播放器 // 音乐播放器
class Music : class Music
public Object
{ {
friend Game; friend Game;

View File

@ -66,17 +66,26 @@ class TransitionFade :
public Transition public Transition
{ {
public: public:
// 创建淡入淡出式的场景切换动作
TransitionFade( TransitionFade(
double duration /* 动作持续时长 */ double duration /* 动作持续时长 */
); );
// 创建淡入淡出式的场景切换动作
TransitionFade( TransitionFade(
double fadeOutDuration, /* 前一场景淡出动作持续时长 */ double fadeOutDuration, /* 前一场景淡出动作持续时长 */
double fadeInDuration /* 后一场景淡入动作持续时长 */ double fadeInDuration /* 后一场景淡入动作持续时长 */
); );
// 创建淡入淡出式的场景切换动作
static TransitionFade * create(
double duration /* 动作持续时长 */
);
// 创建淡入淡出式的场景切换动作
static TransitionFade * create(
double fadeOutDuration, /* 前一场景淡出动作持续时长 */
double fadeInDuration /* 后一场景淡入动作持续时长 */
);
protected: protected:
// 更新动作 // 更新动作
virtual void _updateCustom() override; virtual void _updateCustom() override;
@ -99,11 +108,15 @@ class TransitionEmerge :
public Transition public Transition
{ {
public: public:
// 创建浮现式的场景切换动作
TransitionEmerge( TransitionEmerge(
double duration /* 浮现动作持续时长 */ double duration /* 浮现动作持续时长 */
); );
// 创建浮现式的场景切换动作
static TransitionEmerge * create(
double duration /* 浮现动作持续时长 */
);
protected: protected:
// 更新动作 // 更新动作
virtual void _updateCustom() override; virtual void _updateCustom() override;
@ -121,12 +134,17 @@ class TransitionMove :
public Transition public Transition
{ {
public: public:
// 创建移动式的场景切换动作
TransitionMove( TransitionMove(
double moveDuration, /* 场景移动动作持续时长 */ double moveDuration, /* 场景移动动作持续时长 */
Direction direction = Direction::LEFT /* 场景移动方向 */ Direction direction = Direction::LEFT /* 场景移动方向 */
); );
// 创建移动式的场景切换动作
static TransitionMove * create(
double moveDuration, /* 场景移动动作持续时长 */
Direction direction = Direction::LEFT /* 场景移动方向 */
);
protected: protected:
// 更新动作 // 更新动作
virtual void _updateCustom() override; virtual void _updateCustom() override;