![](/img/trans.png)
[英]In swift, how do I scale and position an SKSpriteNode to fit each iPhone?
[英]How do I resize a SKSpriteNode as a background to perfectly fit the screen in swift
我正在使用swift制作我的第一个游戏,并且我需要一个背景图片来完美适合屏幕。 现在,图像已放大。
在我的GameViewController.swift中,我添加了:
scene.size = skView.bounds.size
另外,在我的GameScene.swift中,我添加了:
class GameScene: SKScene {
let CKBackground = SKSpriteNode(imageNamed: "CKBackground")
override func didMoveToView(view: SKView) {
/* Setup your scene here */
CKBackground.anchorPoint = CGPointMake(0.5, 0.5)
CKBackground.size.height = self.size.height
CKBackground.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
self.addChild(CKBackground)
无论我尝试什么,背景都会放大。
我想通了,我还需要添加一个size.width!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.