SKShapeNode Circle not appearing circular

久未见 提交于 2019-12-25 02:04:42

问题


I am working on an app where there should be a red circle on the screen. At first when I tested with only one scene, the circle appeared circular just fine. However, I have added in another scene and now the circle appears like this:

The circle appears to be much longer in the x direction. Here is the code I use to make the circle (All of this in an 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)

Here is the code I use to transition to the scene with the ball (A different skscene):

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

Any ideas on why the ball would no longer appear as a circle? I a worried this is also going to throw off other nodes I attempt to add, and possible means the coordinate system is incorrect. I am happy to hear any ideas. Thank you!


回答1:


"All of this in an skview" are you sure you aren't doing that in a SKScene?

If the ball is indeed getting added directly to the scene I would look at the scene.scaleMode in your View Controller. Most of the time people set it to scene.scaleMode = .AspectFill but when you create a new scene you aren't setting the scaleMode. This might be as easy as making sure both scenes have the same scaleMode.

I am guessing this will fix your issue.

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

Hopefully that helps.



来源:https://stackoverflow.com/questions/29449164/skshapenode-circle-not-appearing-circular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!