用于处理点而不是像素的CCDirector/CCNode类别
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用于处理点而不是像素的CCDirector/CCNode类别相关的知识,希望对你有一定的参考价值。
#pragma mark CCDirector Category for Point Handling #import "cocos2d.h" @interface CCDirector (Points) - (CGSize) ptWinSize; - (CGPoint) convertToPt:(CGPoint)point; - (CGPoint) convertToPx:(CGPoint)point; @end @implementation CCDirector (Points) - (CGSize) ptWinSize { CGSize s = [self winSize]; CGPoint p = [self convertToPt:ccp(s.width, s.height)]; return CGSizeMake(p.x, p.y); } - (CGPoint) convertToPt:(CGPoint)point { return ccpMult(point, 1.0/self.contentScaleFactor); } - (CGPoint) convertToPx:(CGPoint)point { return ccpMult(point, self.contentScaleFactor); } @end #pragma mark CCNode Category for Point Handling @interface CCNode (Points) @property (assign) CGPoint ptPosition; @property (assign) CGSize ptContentSize; - (CGPoint) ptConvertToNodeSpace:(CGPoint)point; - (CGPoint) ptConvertToWorldSpace:(CGPoint)point; @end @implementation CCNode (Points) - (void) setPtPosition:(CGPoint)pos { self.position = [[CCDirector sharedDirector] convertToPx:pos]; } - (CGPoint) ptPosition { return [[CCDirector sharedDirector] convertToPt:self.position]; } - (void) setPtContentSize:(CGSize)size { CGPoint p = [[CCDirector sharedDirector] convertToPx:ccp(size.width, size.height)]; self.contentSize = CGSizeMake(p.x, p.y); } - (CGSize) ptContentSize { CGPoint p = [[CCDirector sharedDirector] convertToPt:ccp(self.contentSize.width, self.contentSize.height)]; return CGSizeMake(p.x, p.y); } - (CGPoint) ptConvertToNodeSpace:(CGPoint)point { point = [[CCDirector sharedDirector] convertToPx:point]; point = [self convertToNodeSpace:point]; point = [[CCDirector sharedDirector] convertToPt:point]; return point; } - (CGPoint) ptConvertToWorldSpace:(CGPoint)point { point = [[CCDirector sharedDirector] convertToPx:point]; point = [self convertToWorldSpace:point]; point = [[CCDirector sharedDirector] convertToPt:point]; return point; } @end
以上是关于用于处理点而不是像素的CCDirector/CCNode类别的主要内容,如果未能解决你的问题,请参考以下文章