首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SKShapeNode空矩形

SKShapeNode空矩形
EN

Stack Overflow用户
提问于 2014-09-29 11:07:15
回答 1查看 2.3K关注 0票数 1

我开始学习SpriteKit,并立即遇到了一个问题。我试图用SKShapeNode绘制一个空的矩形,但它确实出现在屏幕上。如果将颜色设置为“填充”属性,则将显示矩形。我做错什么了?

代码语言:javascript
复制
    CGRect box = CGRectMake(0, 0, self.frame.size.width/2, self.frame.size.height/2);

    SKShapeNode *shapeNode = [[SKShapeNode alloc] init];
    shapeNode.path = [UIBezierPath bezierPathWithRect:box].CGPath;
    shapeNode.fillColor = nil;
    shapeNode.strokeColor = SKColor.redColor;
    shapeNode.lineWidth = 3;

    [self addChild:shapeNode];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-30 06:58:41

欢迎来到雪碧工具包,我也在学习它,而且我对shapeNodes没有太多的经验,但下面是我的建议:

代码语言:javascript
复制
//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对象的详细信息,那么我建议在这里查看:参考

如果您想要一个优秀的高质量教程的来源,我建议您在这里查看:在这里输入链接描述

我还没有测试代码,因为我目前无法测试,所以如果它不起作用,请告诉我,我会看看我能做些什么来帮助您。再次欢迎来到雪碧套件,希望这是一次愉快的体验.

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26098448

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档