2010-07-22 15:54:43 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CCSpriteFrame.h"
|
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
namespace cocos2d {
|
2010-07-22 15:54:43 +08:00
|
|
|
// implementation of CCSpriteFrame
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSpriteFrame* CCSpriteFrame::frameWithTexture(CCTexture2D *pobTexture, CCRect rect)
|
2010-07-22 15:54:43 +08:00
|
|
|
{
|
|
|
|
CCSpriteFrame *pSpriteFrame = new CCSpriteFrame();;
|
2010-12-27 10:26:56 +08:00
|
|
|
pSpriteFrame->initWithTexture(pobTexture, rect);
|
2010-07-22 15:54:43 +08:00
|
|
|
pSpriteFrame->autorelease();
|
|
|
|
|
|
|
|
return pSpriteFrame;
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSpriteFrame* CCSpriteFrame::frameWithTexture(CCTexture2D* pobTexture, CCRect rect, bool rotated, CCPoint offset, CCSize originalSize)
|
2010-07-22 15:54:43 +08:00
|
|
|
{
|
|
|
|
CCSpriteFrame *pSpriteFrame = new CCSpriteFrame();;
|
2010-12-27 10:26:56 +08:00
|
|
|
pSpriteFrame->initWithTexture(pobTexture, rect, rotated, offset, originalSize);
|
2010-07-22 15:54:43 +08:00
|
|
|
pSpriteFrame->autorelease();
|
|
|
|
|
|
|
|
return pSpriteFrame;
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
bool CCSpriteFrame::initWithTexture(CCTexture2D* pobTexture, CCRect rect)
|
2010-07-22 15:54:43 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCRect rectInPixels = CC_RECT_POINTS_TO_PIXELS(rect);
|
|
|
|
return initWithTexture(pobTexture, rectInPixels, false, CCPointZero, rectInPixels.size);
|
2010-07-22 15:54:43 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
bool CCSpriteFrame::initWithTexture(CCTexture2D* pobTexture, CCRect rect, bool rotated, CCPoint offset, CCSize originalSize)
|
2010-07-22 15:54:43 +08:00
|
|
|
{
|
|
|
|
m_pobTexture = pobTexture;
|
2010-08-12 17:01:51 +08:00
|
|
|
pobTexture->retain();
|
2010-12-27 10:26:56 +08:00
|
|
|
m_obRectInPixels = rect;
|
|
|
|
m_obRect = CC_RECT_PIXELS_TO_POINTS(rect);
|
|
|
|
m_bRotated = rotated;
|
|
|
|
m_obOffsetInPixels = offset;
|
|
|
|
|
|
|
|
m_obOriginalSizeInPixels = originalSize;
|
2010-07-22 15:54:43 +08:00
|
|
|
|
2010-09-04 12:02:52 +08:00
|
|
|
return true;
|
2010-07-22 15:54:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCSpriteFrame::~CCSpriteFrame(void)
|
|
|
|
{
|
|
|
|
CCLOGINFO("cocos2d: deallocing %p", this);
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_RELEASE(m_pobTexture);
|
2010-07-22 15:54:43 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCObject* CCSpriteFrame::copyWithZone(CCZone *pZone)
|
2010-07-22 15:54:43 +08:00
|
|
|
{
|
|
|
|
CCSpriteFrame *pCopy = new CCSpriteFrame();
|
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
pCopy->initWithTexture(m_pobTexture, m_obRectInPixels, m_bRotated, m_obOffsetInPixels, m_obOriginalSizeInPixels);
|
2010-07-22 15:54:43 +08:00
|
|
|
|
|
|
|
return pCopy;
|
|
|
|
}
|
2010-08-04 15:46:12 +08:00
|
|
|
}//namespace cocos2d
|