gpt4 book ai didi

ios - 在 GameScene 中定位 SKSpriteNode

转载 作者:行者123 更新时间:2023-11-30 13:39:19 25 4
gpt4 key购买 nike

我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com