cocos2dx源码:相框PhotoFrame
发布时间:2020-12-14 17:09:47 所属栏目:百科 来源:网络整理
导读:头文件PhotoFrame.h #ifndef _PHOTOFRAME_H_ # define _PHOTOFRAME_H_ #include "cocos2d.h" #include "GmbsCocos.h" #include "extensions/cocos-ext.h" using namespace cocos2d::ui;NS_CC_BEGINclass PhotoFrame : public LayerColor{ public : ~ PhotoFr
头文件PhotoFrame.h #ifndef _PHOTOFRAME_H_
#define _PHOTOFRAME_H_
#include "cocos2d.h"
#include "GmbsCocos.h"
#include "extensions/cocos-ext.h"
using namespace cocos2d::ui;
NS_CC_BEGIN
class PhotoFrame : public LayerColor
{
public:
~PhotoFrame();
static PhotoFrame* create(const char* filename,const Color4B& color = Color4B(255,255,0));
virtual bool init(const char* filename);
void decorate(Node* photo,float horiz = 0,float vert = 0);
void inflate(float wInf,float hInf);
protected:
ui::Scale9Sprite* m_frameSprite;
};
NS_CC_END
#endif
cpp文件PhotoFrame.cpp #include "PhotoFrame.h"
NS_CC_BEGIN
PhotoFrame::~PhotoFrame()
{
}
PhotoFrame* PhotoFrame::create(const char* filename,const Color4B& color)
{
PhotoFrame* pobLayer = new PhotoFrame();
if (pobLayer && pobLayer->initWithColor(color) && pobLayer->init(filename))
{
pobLayer->autorelease();
return pobLayer;
}
else
{
CC_SAFE_DELETE(pobLayer);
return NULL;
}
}
bool PhotoFrame::init(const char* filename)
{
m_frameSprite = ui::Scale9Sprite::create(filename);
this->addChild(m_frameSprite);
return true;
}
void PhotoFrame::decorate(Node* photo,float wInf,float hInf)
{
photo->addChild(this);
Size size = photo->getContentSize();
size.width += wInf;
size.height += hInf;
this->setContentSize(size);
m_frameSprite->setContentSize(size);
GmbsPoint pt;
pt.reset(m_frameSprite);
pt.xMiddleAlign(this).yMiddleAlign(this);
m_frameSprite->setPosition(pt);
pt.reset(this);
pt.xMiddleAlign(photo).yMiddleAlign(photo);
this->setPosition(pt);
}
void PhotoFrame::inflate(float wInf,float hInf)
{
Size size = this->getContentSize();
size.width += wInf;
size.height += hInf;
this->setContentSize(size);
m_frameSprite->setContentSize(size);
GmbsPoint pt;
Node* photo = getParent();
pt.reset(m_frameSprite);
pt.xMiddleAlign(photo).yMiddleAlign(photo);
m_frameSprite->setPosition(pt);
pt.reset(this);
pt.xMiddleAlign(photo).yMiddleAlign(photo);
this->setPosition(pt);
}
NS_CC_END
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |