【问题标题】:SKShapeNode Circle not appearing circularSKShapeNode 圆没有出现圆形
【发布时间】:2015-04-05 06:10:49
【问题描述】:

我正在开发一个屏幕上应该有一个红色圆圈的应用程序。起初,当我只用一个场景进行测试时,圆圈看起来是圆形的。但是,我在另一个场景中添加了,现在圆圈看起来像这样:

圆圈在 x 方向上看起来要长得多。 这是我用来制作圆圈的代码(所有这些都在 skscene 中):

    let ball = Ball(circleOfRadius: 500)//ball is a subclass of SKShapeNode
    ball.setScale((self.frame.height / 6) / 1000)            
    ball.position = CGPointMake(self.frame.width / 4, self.frame.height / 2)
    ball.fillColor = UIColor.redColor()
    ball.strokeColor = UIColor.clearColor()
    self.addChild(ball)

这是我用来过渡到有球场景的代码(不同的场景):

func transitionToGame(){
    let reveal = SKTransition.crossFadeWithDuration(1.0)
    let gameOverScene = GameScene(size: self.size)
    self.view?.presentScene(gameOverScene, transition: reveal)
}

关于为什么球不再显示为圆形的任何想法?我担心这也会抛弃我尝试添加的其他节点,并且可能意味着坐标系不正确。我很高兴听到任何想法。谢谢!

【问题讨论】:

    标签: ios swift sprite-kit


    【解决方案1】:

    “所有这些都在 skview 中”你确定你没有在 SKScene 中这样做吗?

    如果球确实被直接添加到场景中,我会查看视图控制器中的 scene.scaleMode。大多数时候人们将它设置为scene.scaleMode = .AspectFill,但是当您创建一个新场景时,您并没有设置 scaleMode。这可能就像确保两个场景具有相同的 scaleMode 一样简单。

    我猜这会解决你的问题。

    func transitionToGame(){
        let reveal = SKTransition.crossFadeWithDuration(1.0)
        let gameOverScene = GameScene(size: self.size)
        gameOverScene.scaleMode = scene.scaleMode
        self.view?.presentScene(gameOverScene, transition: reveal)
    }
    

    希望对您有所帮助。

    【讨论】:

    • 是的,我是想写SKScene,不知道为什么要写SKView。谢谢,这很好用!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多