Skip to content

Commit

Permalink
CCLayoutBox now takes into account a transform of a node
Browse files Browse the repository at this point in the history
issue #1333
  • Loading branch information
s1ddok committed Feb 6, 2016
1 parent 112f9b0 commit 4445157
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cocos2d/CCLayoutBox.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ - (void) layout
float maxHeight = 0;
for (CCNode* child in self.children)
{
float height = child.contentSizeInPoints.height;
float height = [child boundingBox].size.height;
if (height > maxHeight) maxHeight = height;
}

// Position the nodes
float width = 0;
for (CCNode* child in self.children)
{
CGSize childSize = child.contentSizeInPoints;
CGSize childSize = [child boundingBox].size;

CGPoint offset = child.anchorPointInPoints;
CGPoint offset = child.anchorPoint;
CGPoint localPos = ccp(roundf(width), roundf((maxHeight-childSize.height)/2.0f));
CGPoint position = ccpAdd(localPos, offset);
CGPoint position = ccpAdd(localPos, CGPointMake(offset.x * childSize.width, offset.y * childSize.height));

child.position = position;
child.positionType = CCPositionTypePoints;
Expand All @@ -78,19 +78,19 @@ - (void) layout
float maxWidth = 0;
for (CCNode* child in self.children)
{
float width = child.contentSizeInPoints.width;
float width = [child boundingBox].size.width;
if (width > maxWidth) maxWidth = width;
}

// Position the nodes
float height = 0;
for (CCNode* child in self.children)
{
CGSize childSize = child.contentSizeInPoints;
CGSize childSize = [child boundingBox].size;

CGPoint offset = child.anchorPointInPoints;
CGPoint offset = child.anchorPoint;
CGPoint localPos = ccp(roundf((maxWidth-childSize.width)/2.0f), roundf(height));
CGPoint position = ccpAdd(localPos, offset);
CGPoint position = ccpAdd(localPos, CGPointMake(offset.x * childSize.width, offset.y * childSize.height));

child.position = position;
child.positionType = CCPositionTypePoints;
Expand Down

0 comments on commit 4445157

Please sign in to comment.