read sprite anchor point from plist file

This commit is contained in:
Joachim Grill 2015-12-14 15:42:18 +01:00
parent d904246aa8
commit 033b9aabf0
4 changed files with 42 additions and 0 deletions

View File

@ -1047,6 +1047,10 @@ void Sprite::setSpriteFrame(SpriteFrame *spriteFrame)
{
_polyInfo = spriteFrame->getPolygonInfo();
}
if (spriteFrame->hasAnchorPoint())
{
setAnchorPoint(spriteFrame->getAnchorPoint());
}
}
void Sprite::setDisplayFrameWithAnimationName(const std::string& animationName, ssize_t frameIndex)

View File

@ -104,6 +104,7 @@ bool SpriteFrame::initWithTexture(Texture2D* texture, const Rect& rect, bool rot
_originalSizeInPixels = originalSize;
_originalSize = CC_SIZE_PIXELS_TO_POINTS( _originalSizeInPixels );
_rotated = rotated;
_anchorPoint = Vec2(NAN, NAN);
return true;
}
@ -119,6 +120,7 @@ bool SpriteFrame::initWithTextureFilename(const std::string& filename, const Rec
_originalSizeInPixels = originalSize;
_originalSize = CC_SIZE_PIXELS_TO_POINTS( _originalSizeInPixels );
_rotated = rotated;
_anchorPoint = Vec2(NAN, NAN);
return true;
}
@ -173,6 +175,21 @@ void SpriteFrame::setOffsetInPixels(const Vec2& offsetInPixels)
_offset = CC_POINT_PIXELS_TO_POINTS( _offsetInPixels );
}
const Vec2& SpriteFrame::getAnchorPoint() const
{
return _anchorPoint;
}
void SpriteFrame::setAnchorPoint(const Vec2& anchorPoint)
{
_anchorPoint = anchorPoint;
}
bool SpriteFrame::hasAnchorPoint() const
{
return _anchorPoint.x != NAN;
}
void SpriteFrame::setTexture(Texture2D * texture)
{
if( _texture != texture ) {

View File

@ -186,6 +186,22 @@ public:
*/
void setOffset(const Vec2& offsets);
/** Get anchor point of the frame.
*
* @return The anchor point of the sprite frame.
*/
const Vec2& getAnchorPoint() const;
/** Set anchor point of the frame.
*
* @param anchorPoint The anchor point of the sprite frame.
*/
void setAnchorPoint(const Vec2& anchorPoint);
/** Check if anchor point is defined for frame.
*
* @return true if anchor point is available.
*/
bool hasAnchorPoint() const;
// Overrides
virtual SpriteFrame *clone() const override;
@ -242,6 +258,7 @@ CC_CONSTRUCTOR_ACCESS:
protected:
Vec2 _offset;
Vec2 _anchorPoint;
Size _originalSize;
Rect _rectInPixels;
bool _rotated;

View File

@ -276,6 +276,10 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Textu
initializePolygonInfo(textureSize, spriteSourceSize, vertices, verticesUV, indices, info);
spriteFrame->setPolygonInfo(info);
}
if (frameDict.find("anchor") != frameDict.end())
{
spriteFrame->setAnchorPoint(PointFromString(frameDict["anchor"].asString()));
}
}
bool flag = NinePatchImageParser::isNinePatchImage(spriteFrameName);