Skip to content

Commit

Permalink
fix % position of child nodes of a SKNode
Browse files Browse the repository at this point in the history
  • Loading branch information
LearnCocos2D committed Apr 9, 2014
1 parent fa32ef3 commit 5934c5d
Showing 1 changed file with 36 additions and 1 deletion.
Expand Up @@ -31,6 +31,7 @@
static NSString* CCBReaderUserDataKeyForContentSizeType = @"CCBReader:contentSizeType";
static NSString* CCBReaderUserDataKeyForScaleType = @"CCBReader:scaleType";
static NSString* CCBReaderUserDataKeyForPositionType = @"CCBReader:positionType";
static NSString* CCBReaderUserDataKeyForContentSize = @"CCBReader:contentSize";
static NSString* CCBReaderUserDataKeyForLoadedFromCCB = @"CCBSpriteKitReader:loadedFromCCB";

@interface CCBReaderSizeType : NSObject
Expand Down Expand Up @@ -69,6 +70,18 @@ -(id) initWithPositionType:(CCPositionType)positionType
}
@end

@interface CCBReaderContentSize : NSObject
@property (nonatomic) CGSize contentSize;
@end
@implementation CCBReaderContentSize
-(id) initWithContentSize:(CGSize)contentSize
{
self = [super init];
_contentSize = contentSize;
return self;
}
@end


@implementation SKNode (CCBReader)

Expand Down Expand Up @@ -223,13 +236,35 @@ -(void) setContentSize:(CGSize)contentSize
{
[(id)self setSize:contentSize];
}
else
{
NSMutableDictionary* userData = [self getOrCreateUserData];
CCBReaderContentSize* contentSizeProxy = [userData objectForKey:CCBReaderUserDataKeyForContentSize];
if (contentSizeProxy == nil)
{
contentSizeProxy = [[CCBReaderContentSize alloc] initWithContentSize:contentSize];
[userData setObject:contentSizeProxy forKey:CCBReaderUserDataKeyForContentSize];
}
else
{
contentSizeProxy.contentSize = contentSize;
}
}
}
-(CGSize) contentSize
{
if ([self respondsToSelector:@selector(setSize:)])
{
return [(id)self size];
}
else
{
CCBReaderContentSize* contentSizeProxy = [[self getOrCreateUserData] objectForKey:CCBReaderUserDataKeyForContentSize];
if (contentSizeProxy)
{
return contentSizeProxy.contentSize;
}
}

return self.frame.size;
}
Expand Down Expand Up @@ -380,7 +415,7 @@ -(CGSize) contentSizeFromParent
}
else
{
parentSize = parent.frame.size;
parentSize = parent.contentSize;
}
}

Expand Down

0 comments on commit 5934c5d

Please sign in to comment.