I'm building a menu Game Scene where I have a Logo and 4 buttons, all of those have a SKPhysicsBody with the rectangle size of the image. All of those I only set:
我正在构建一个菜单游戏场景,我有一个标志和4个按钮,所有这些都有一个SKPhysicsBody和图像的矩形大小。所有这些我只设置:
logo.physicsBody = SKPhysicsBody(rectangleOf: logo.size)
logo.physicsBody?.affectedByGravity = false
Full code of creating the objects (all are the same)
创建对象的完整代码(都是相同的)
logo = SKSpriteNode(imageNamed: "logo")
logo.anchorPoint = CGPoint.zero
logo.name = "logo"
logo.zPosition = 2
logo.size = CGSize(width: 309, height: 272)
logo.setScale(Generic.utilities.getScale())
self.addChild(logo)
logo.position = CGPoint(x: self.frame.width/2 - logo.size.width/2, y: self.frame.height - logo.size.height - 40)
logo.physicsBody = SKPhysicsBody(rectangleOf: logo.size)
logo.physicsBody?.affectedByGravity = false
and during a button press I change all the nodes affectedByGravity to true so they can fall of the screen and new elements can come in.
在按下按钮时,我将所有受重力影响的节点更改为true,这样它们就可以落在屏幕上,新的元素就会进来。
The problem I'm having is that when I run the app, the elements are all shifted/tilted on the screen and not in their original position
我遇到的问题是,当我运行应用程序时,所有的元素都在屏幕上移动/倾斜,而不是在原来的位置
All I wanted is for them to stay in their position until I click one of the buttons and then they can fall off the screen.
我想要的只是让它们保持它们的位置,直到我点击其中一个按钮,它们就会从屏幕上掉下来。
Any reason why when I set a physics body and affectedByGravity they all tilt like this?
为什么当我设置一个物理物体,受到重力影响时它们都像这样倾斜?
1 个解决方案
#1
1
Well, Thanks to @RonMyschuk and @Knight0fDragon I found out (didn't know before) that I could add to my Scene loading the following:
感谢@RonMyschuk和@Knight0fDragon,我发现(之前不知道)我可以在我的场景中添加如下内容:
skView.showsPhysics = true
Which add border lines around the physicsBody of your nodes, that way you can see them interacting. And by doing that I saw that the physicsBody of one of my nodes was completely in a different position then it should
它在节点的物理体周围添加边框线,这样你就可以看到它们相互作用。通过这样做,我发现我的一个节点的物理体完全处于不同的位置那么它就应该处于不同的位置
By taking care of this issue, everything went back to normal
解决了这个问题,一切都恢复了正常
#1
1
Well, Thanks to @RonMyschuk and @Knight0fDragon I found out (didn't know before) that I could add to my Scene loading the following:
感谢@RonMyschuk和@Knight0fDragon,我发现(之前不知道)我可以在我的场景中添加如下内容:
skView.showsPhysics = true
Which add border lines around the physicsBody of your nodes, that way you can see them interacting. And by doing that I saw that the physicsBody of one of my nodes was completely in a different position then it should
它在节点的物理体周围添加边框线,这样你就可以看到它们相互作用。通过这样做,我发现我的一个节点的物理体完全处于不同的位置那么它就应该处于不同的位置
By taking care of this issue, everything went back to normal
解决了这个问题,一切都恢复了正常