ios - 在 GameScene 中定位 SKSpriteNode

标签 ios iphone xcode swift ipad

我在 GameScene 中正确定位两个 SKSpriteNode 时遇到了一些问题。我的节点出现在场景中,但它们被放大并占据了整个场景的大部分。我希望输出与此类似:

enter image description here

这是我当前的代码:

let size = CGRect(x: 100, y:98, width:200, hight:271)
bottomRectangle = SKSpriteNode(imageNamed: "bottomRectangle")

bottomRectangle.zPosition = 3
bottomRectangle.size.height = self.size.height
bottomRectangle.size.width = self.size.width
bottomRectangle.position = CGPoint(x: 200, y:271)
bottomRectangle.physicsBody = SKPhysicsBody(edgeLoopFromRect: size)





self.addChild(bottomRectangle)

topRectangle = SKSpriteNode(imageNamed: "topRectangle")
topRectangle.physicsBody = SKPhysicsBody(edgeLoopFromRect: size)
topRectangle.zPosition = 4
topRectangle.size.height = self.size.height
topRectangle.size.width = self.size.width
topRectangle.position = CGPoint(x: 100, y: 98)
self.addChild(topRectangle)

最佳答案

您正在使用场景的大小,因为:

self.size.height

您必须使用局部变量:

 size.height

关于ios - 在 GameScene 中定位 SKSpriteNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35750333/

相关文章:

iphone - 我可以使用 NSDateFormatter 将此日期字符串转换为 NSDate 吗?

iphone - 为什么应用内购买沙箱总是询问 "Verification Required"?

xcode - IBOutlets 未显示

xcode - 从 Unity 到 Xcode 构建的 Unity Ads 错误

ios - Core Text设置默认颜色和特定单词的颜色

ios - 同步下载 Firebase 存储

ios - 在覆盖之前检查 Firebase 是否存在现有数据?

objective-c - 应用程序在 iPhone 5 上崩溃

iphone - openGL ES 视网膜支持

ios - 由于未捕获的异常 'NSUnknownKeyException',不断出现错误/崩溃