相关疑难解决方法(0)

在没有framedrops的情况下创建无限的cgpath

我需要不断创建一个cgpath.目前我这样做:

 func createLine(){
        var rand = randomBetweenNumbers(1, 2)
        currentY--
        if rand < 1.5{
            currentX--
            CGPathAddLineToPoint(leftPath, nil, currentX, currentY)
        }else{
            currentX++
            CGPathAddLineToPoint(leftPath, nil, currentX, currentY)
        }
        CGPathAddLineToPoint(rightPath, nil, currentX+tileSize, currentY)
        lineNode.path = leftPath
        rightNode.path = rightPath

}
Run Code Online (Sandbox Code Playgroud)

并称之为:

NSTimer.scheduledTimerWithTimeInterval(0.05, target: self, selector: Selector("startTile"), userInfo: nil, repeats: true)
Run Code Online (Sandbox Code Playgroud)

但问题是,帧随着时间的推移越来越低.有什么我必须改变,以便帧率不再下降?

我的目标是创建一个随机的无尽路径.

frame-rate infinite cgpath sprite-kit swift

8
推荐指数
1
解决办法
545
查看次数

按下时将视觉效果添加到SKSpriteNode

我正在使用Xcode 6中的第一个SpriteKit应用程序,在Swift中编码.现在我从透明的png文件中制作了一些漂亮的按钮.但我想按下按钮时显示视觉效果.

我现在如何显示静态按钮的示例:

let playButton = Button(imageNamed:"playButton")
playButton.position = CGPointMake(self.size.width/2, self.size.height/2 - playButton.size.height * 2.5 - displacement)
self.sharedInstance.addChildFadeIn(playButton, target: self)
Run Code Online (Sandbox Code Playgroud)

任何效果都足够了,可能是脉冲效应,或按下时发光.我搜索过,但我在Swift中找不到任何东西.

编辑:更多信息

    class Button: SKSpriteNode {  
        init(imageNamed: String) {
            let texture = SKTexture(imageNamed: imageNamed)
            // have to call the designated initializer for SKSpriteNode
            super.init(texture: texture, color: nil, size: texture.size())
        }
        override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
            self.runAction(SKAction.scaleTo(1.3, duration: kButtonFadingSpeed))
        }    
        override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
            self.runAction(SKAction.scaleTo(1.3, duration: kButtonFadingSpeed))
        }
         override func touchesEnded(touches: NSSet, withEvent event: …
Run Code Online (Sandbox Code Playgroud)

ios sprite-kit skspritenode swift

5
推荐指数
1
解决办法
2696
查看次数

一局中有多个skshapenode?

嗨,我为我的视觉a *表示绘制了skshapenodes连接图中的节点。

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]];
                    line.alpha = 0.1f;
                    [self addChild:line];
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

我的图中有很多节点,它绘制了将近22,000个形状。有没有一种方法可以在一次绘制调用中绘制这些形状,因为它们都是相同的,唯一的区别是它们的开始和结束位置。

如果我改为使用可以一次加载的纹理,那么如何改变它的旋转度以像上面那样连接我的所有节点。

问候,

更新:

SKShapeNode *line = [SKShapeNode node];
        CGMutablePathRef pathToDraw = CGPathCreateMutable();

        for(int x=0; x<64; x++) …
Run Code Online (Sandbox Code Playgroud)

ios ios7 sprite-kit skshapenode

1
推荐指数
1
解决办法
2712
查看次数