如何在更改SKScene的大小时修复'SKSpriteNode变形'

时间:2019-04-17 15:11:27

标签: ios swift skspritenode skscene

当我更改SKScene的大小时,我的SKSpriteNode会变形,如果我添加skScene!.scaleMode = .aspectFill

我的SKSpriteNode退出屏幕

Scene before changing size

Scene after changing size

这是我的SKScene

BallNode.swift

class BallNode: SKSpriteNode {
required init?(coder aDecoder: NSCoder!) {
    super.init(coder: aDecoder)
}

convenience public init() {
    self.init(imageNamed:"ball.png")

    let xPos = CGFloat(arc4random()%(canvasHeight))
    let yPos = CGFloat(arc4random()%(canvasWidth))

    self.position = CGPoint(x: xPos, y: yPos)
    self.yScale = 0.10
    self.xScale = 0.10
    self.physicsBody = SKPhysicsBody(circleOfRadius: self.frame.size.width/2)
    self.physicsBody!.friction = 0.0
    self.physicsBody!.restitution = 1.0
    self.physicsBody!.mass = 1.0
    self.physicsBody!.linearDamping = 0.0
    self.physicsBody!.allowsRotation = false
    self.physicsBody!.affectedByGravity = true
    self.physicsBody!.categoryBitMask = ballCategory;
    self.physicsBody!.collisionBitMask = wallCategory;
    self.physicsBody!.node?.name = "sheep"

}

override init(texture: SKTexture!, color: UIColor!, size: CGSize) {
    super.init(texture: texture, color: color, size: size)
}
}

0 个答案:

没有答案