Tag: skshapenode

两个相同节点之间的skphysicsbody碰撞

我创build了一个声明类SKShapeNode的类。 在它的init中,我设置了“SKPhysicsBody”属性。 在设置这些属性之前(将其保留为默认值),当一个球碰到另一个球时,受到碰触的两个球(例如:移动到不同的位置取决于碰撞位置)。 在设置了“physicsBody”属性之后,它将不再受到影响 – 一个球看起来比另一个球更高(如框架上的框架 – 隐藏它)。 我怎样才能设置这个属性? 我看着苹果文件,没有发现什么…这是我的代码: lass BallNode: SKShapeNode { var radius:CGFloat = 0 var color:UIColor? var strokeWidth:CGFloat = 0 private var _name:String? override init() { super.init() self.fillColor = ranColor() self.lineWidth = strokeWidth } convenience init(radius:CGFloat){ self.init(circleOfRadius: radius) self.radius = radius self.physicsBody = SKPhysicsBody.init(circleOfRadius: self.radius) self.physicsBody?.affectedByGravity = true print("ball physicsbody is […]

将SKShapeNode帧设置为calculateAccumutedFrame

这个问题已经发生了几天:我不能设置我需要的特定框架。 我需要我的SKShapeNode框架作为围绕一个圆的边界框,以便它是框架的内切圆。 蓝色是当前的框架,红色是我想要的框架。 我正在创build这样的SKShapeNode: init(level: Int, from: SKSpriteNode, fromScene: GameScene) { self.level = level self.from = from self.fromScene = fromScene bezierPath = UIBezierPath(arcCenter: CGPoint.zero, radius: CGFloat(((25 * level)) + 50), startAngle: CGFloat(GLKMathDegreesToRadians(-50)), endAngle: CGFloat(M_PI * 2), clockwise: false) let top = CGFloat((level * 25) + 50) let bottom = CGFloat((level + 1) * 25 + […]

在iOS上的SpriteKit的坐标,框架和子节点的混淆?

我还在iOS上学习SpriteKit,并一直在做大量的阅读和大量的实验。 我很困惑的东西我已经find*关于坐标,框架和子节点。 考虑这段代码,其中我正在试图围绕我的飞船精灵绘制一个绿色的框来进行debugging: func addSpaceship() { let spaceship = SKSpriteNode.init(imageNamed: "rocketship.png") spaceship.name = "spaceship" // VERSION 1 spaceship.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)) let debugFrame = SKShapeNode(rect: spaceship.frame) debugFrame.strokeColor = SKColor.greenColor() spaceship.addChild(debugFrame) // VERSION 2 // spaceship.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)) spaceship.setScale(0.50) self.addChild(spaceship) } 如果我把上面标有“VERSION 1”的行添加到飞船精灵上,我会得到: 这显然是错误的。 但是,如果我注释掉上面标记为“版本1”的行,而是使用标记为“版本2”的行,就可以得到我想要的: 请注意,标记为版本1和版本2的行的实际代码是相同的:spaceship.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame)) 那么为什么当我设定太空船精灵的位置时呢? 按照我的思路,宇宙飞船精灵的位置与debugging帧的位置无关,因为debugging帧是宇宙飞船精灵的一个子,所以它的坐标应该是相对于宇宙飞船精灵的相对位置的。 感谢WM *这与我昨天所问的一个问题有些相关: 在iOS上的SpriteKit中,缩放纹理的sprite会产生不正确的帧? 但是a)我现在明白了一个,b)这是不同的,它应该有自己的问题。 更新: […]

沿着其中心旋转SKShapeNode

我有一个SKShapeNode(在这种情况下是矩形),我试图沿着它的中心旋转。 但是它沿着屏幕的左下angular旋转。 由于我无法为SKShapeNode设置定位点,我怎样才能达到我的要求(沿着其中心旋转形状)。 这是我正在尝试的代码。 let rectangle = SKShapeNode() rectangle.path = UIBezierPath(rect: CGRectMake(view.frame.width/4, view.frame.height/2, view.frame.width/2, view.frame.width/2)).CGPath rectangle.fillColor = UIColor.yellowColor() rectangle.strokeColor = UIColor.yellowColor() let oneRevolution = SKAction.rotateByAngle(360, duration: 100.0) let repeat = SKAction.repeatActionForever(oneRevolution) rectangle.runAction(repeat)

Sprite Kit – SKShapeNodepath不绘制四曲线

我一直在研究苹果新的Sprite Kit,并且一直在使用它。 然而,当我试图绘制一个SKShapeNode的曲线path时遇到了一个问题。 它似乎只是画一条直线。 这是一个非常简单的例子,我正在尝试绘制一个CGPath的SKShapeNode : CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, 0, 0); CGPathAddQuadCurveToPoint(path, NULL, 50, 100, 100, 0); CGPathAddLineToPoint(path, NULL, 50, -100); CGPathCloseSubpath(path); SKShapeNode *shape = [[SKShapeNode alloc]init]; shape.path = path; [self addChild:shape]; CGPathRelease(path); 这是我的ASCII艺术(对不起,我没有足够的声望发布一个实际的图像呢): ——————————————————————————— | EXPECTED RESULT | ACTUAL RESULT | ——————————————————————————— | | | | __—-__ | | | / […]

为什么SKShapeNode没有定位点?

我想知道为什么SKShapeNode没有一个锚点?

Swift:从精灵套件SKShapeNode绘图中检测交集

我正在绘制Sprite Kit。 我想检测用户的图纸是否相交。 我试图跟随代码,但它不起作用。 看来sprite工具包并没有保存所有的要点: override func touchesMoved(touches: NSSet, withEvent event: UIEvent) { /* Called when a touch begins */ touch = touches.anyObject() as UITouch! for drawingPoint in drawingPoints{ if(touch.locationInNode(self) == drawingPoint){println(true)} } drawingPoints.append(touch.locationInNode(self)) }

一次绘制多个skshapenode?

您好我已经绘制skhapenodes连接我的graphics中的节点为我的视觉a *表示。 for(int x=0; x<64; x++) { for(int y=0; y<48; y++) { PathFindingNode *node = [[gridToDraw objectAtIndex:x] objectAtIndex:y]; for(int i=0; i< node.connections.count; i++) { PathFindingNode *neighbor = [node.connections objectAtIndex:i]; SKShapeNode *line = [SKShapeNode node]; CGMutablePathRef pathToDraw = CGPathCreateMutable(); CGPathMoveToPoint(pathToDraw, NULL, node.position.x, node.position.y); CGPathAddLineToPoint(pathToDraw, NULL, neighbor.position.x, neighbor.position.y); line.path = pathToDraw; line.lineWidth = 0.1f; [line setStrokeColor:[UIColor blueColor]]; […]

SpriteKit Swift节点计数问题

模拟器显示节点数,有2个节点。 但为什么呢? 因为只有一个var(球)。 有没有办法创build一个圆圈,而不是双节点。 class GameScene: SKScene { var ball = SKShapeNode(circleOfRadius: 50) override func didMoveToView(view: SKView) { ball.position = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2) ball.fillColor = SKColor.blackColor() self.addChild(ball) }