我有一个 Tile 类,它是 SKShapeNode 的子类
@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;