1
縮放我有一個瓷磚類,這是SKShapeNodeSKShapeNode設置SKAction從中心
@interface Tile : SKShapeNode
的子類,我實例化類,如下所示:
// Tile.h
-(instancetype) addHiddenTileToSpace:(NSString *)letter withIndex:(int)i withPositionInWord:(int)p;
我在執行文件我有
// Tile.m
-(instancetype) addHiddenTileToSpace:(NSString *)letter withIndex:(int)i withPositionInWord:(int)p{
if(self == [super init]){
self.name = @"Tile";
// self.hidden = YES;
if (p == 0) {
self.firstLetter = YES;
}
else{
self.firstLetter = NO;
}
self.positionInAnswer = i;
self.character = letter;
[self setPath:CGPathCreateWithRoundedRect(CGRectMake(0, 0, 60, 60), 4, 4, nil)];
self.strokeColor = self.fillColor = [UIColor colorWithRed:66.0f/255.0f
green:74.0f/255.0f
blue:84.0f/255.0f
alpha:1];
SKLabelNode *characterNode = [[SKLabelNode alloc] initWithFontNamed:@"Avenir-Medium"];
characterNode.text = [letter uppercaseString];
characterNode.fontSize = 40;
characterNode.fontColor = [UIColor colorWithRed:216.0f/255.0f
green:216.0f/255.0f
blue:216.0f/255.0f
alpha:1];
characterNode.position = CGPointMake(30, 15);
[self addChild:characterNode];
}
return self;
}
問題是我想動畫/縮放該節點,但它從節點的座標(0,0)縮放而不是從其中心縮放。我已經在其他地方看過我應該使用+ (instancetype)shapeNodeWithPath:(CGPathRef)path centered:(BOOL)centered
方法並將中心設置爲YES
但是,在上面的實例中,我不確定如何使用shapeNodeWithPath方法初始化SKSHapeNode。或者是否有其他方式可以設置Tile.center = YES;
你爲什麼使用SKShapeNode作爲簡單的瓷磚? – sangony 2015-03-02 18:45:28