欢迎使用 sprite 工具包,我也在学习它,并且对 shapeNodes 没有太多经验,但这是我的建议:
//If you want the shape to be that of a rectangle I would suggest using a simpler allocation method such as the following:
SKShapeNode *shapeNode = [SKShapeNode shapeNodeWithRectOfSize:CGSizeMake(self.frame.size.width/2, self.frame.size.height/2))];
/*shapeNodeWithRectOfSize is a built in allocation method for SKShapeNodes that handles
allocation and initialization for you, and will also create the rectangle shape for you.
The CGSizeMake method will return a CGSizeMake object for you*/
/*a CGSizeMake object is an object with two properties: width, and height. It is used to hold
the dimensions of objects. self.frame.size is a CGSize object*/
/*You do not need to set the fill color to nil. This is because the default is [SKColor clearColor]
which is an empty color already*/
//Make sure that you use an initializer method when setting the colour as below
shapeNode.strokeColor = [SKColor redColor];
shapeNode.lineWidth = 3;
[self addChild:shapeNode];
如果您想参考 SKShapeNode 对象的详细信息,那么我建议您看这里:Apple - SKShapeNode Reference
如果您想要优质教程的来源,我建议您看这里:在此处输入链接描述
我还没有测试代码,因为我目前无法测试,所以如果它不起作用,请告诉我,我会看看我能做些什么来帮助你。再次欢迎使用 Sprite-Kit,希望这是一次愉快的体验。