恢复原状在雪碧套件中的任何内容上不起作用



我尝试创建位掩码类别,将所有恢复值设置为 1 并将阳光下的其他所有内容(包括运行应用程序(和设备,但它仍然根本无法正常工作。在将一个 SKSpriteNode 设置为 1 以 dx: 100 的恢复 1 击中另一个 skspritenode 后,它仍然没有反弹!这是我的GameScene代码.swift:

import SpriteKit
import GameplayKit
class GameScene: SKScene {
override func didMove(to view: SKView) {
let Ball = SKSpriteNode()
Ball.self.childNode(withName: "Ball")
let playerPaddle = SKSpriteNode()
playerPaddle.self.childNode(withName: "playerPaddle")
let computerPaddle = SKSpriteNode()
computerPaddle.self.childNode(withName: "computerPaddle")
let ballCategory: UInt32 = 0x1 << 1
let paddleCategory: UInt32 = 0x1 << 2
let borderCategory: UInt32 = 0x1 << 3
Ball.physicsBody?.categoryBitMask = ballCategory
playerPaddle.physicsBody?.categoryBitMask = paddleCategory
computerPaddle.physicsBody?.categoryBitMask = paddleCategory
self.physicsBody?.categoryBitMask = borderCategory
let playerScore = SKLabelNode()
playerScore.fontName = "Pong Score"
playerScore.text = "0"
playerScore.fontSize = 100
playerScore.color = SKColor.white
playerScore.position = CGPoint(x: -200, y: 220)
playerScore.zPosition = 3
addChild(playerScore)
let comScore = SKLabelNode()
comScore.fontName = "Pong Score"
comScore.text = "0"
comScore.fontSize = 100
comScore.color = SKColor.white
comScore.position = CGPoint(x: 200, y: 220)
comScore.zPosition = 3
addChild(comScore)
var comScoreInt: Int = Int(comScore.text!)!
comScoreInt += 1
comScore.text = String(comScoreInt)
var playerScoreInt: Int = Int(playerScore.text!)!
playerScoreInt += 1
playerScore.text = String(playerScoreInt)
let bodyBorder = SKPhysicsBody(edgeLoopFrom: self.frame)
bodyBorder.friction = 0
bodyBorder.restitution = 1
self.physicsBody = bodyBorder
}
}

PS 大多数物理特性都在 GameScene.sks 而不是 GameScene.swift 中,但这是位掩码所在的地方。

编辑:

球配置;

位置 x:0, y:0, z:0,

旋转: 0,

尺寸: 宽:25,高:25,

锚点:x:0.5, y:0.5,

颜色:白色,

混合因子: 0,

混合模式:阿尔法,

阿尔法: 1,

Ik 约束: 最小:0, 最大:360,

比例: x:1,y:1,

物理

体型:边界直立,

仅动态检查,

摩擦力: 0,

恢复原状: 1,

利努尔湿度:0,

角阻尼: 0,

类别、碰撞和场掩码:4294967295,

接触面罩:0

初始速度: dx:100 dy:0

桨在物理方面是相同的 请帮忙!

在 GameScene.sks 中应用初始速度的 我改为在 GameScene 中应用了一个力.swift如下所示:Ball.physicsBody?.applyImpulse(CGVector(dx:50, dy:0))恢复原状开始起作用

最新更新