我试图通过youtube视频制作一只看起来很脆弱的鸟类( https://www.youtube.com/watch?v=D7ntzPFvMf0)它是迅速制作的2.我试图在迅速做到这一点。一切都进展顺利,直到我达到触摸开始功能。
所有先前的物理行为都像受重力影响一样。当触摸开始被点击时没有任何反应。我测试看它是否通过打印工作,它是。所以我试图让我的datBoi在点击时跳转。作为一个注释,视频让我把
datBoi.physicsBody?.applyImpulse(CGVectorMake( 0, 100))
但我用我知道的替换它
CGVector(dx: 0,dy: 100)
因为这似乎在swift 3中过期了。
这里有任何帮助,我的代码是关于datBoi对象的。
struct PhysicsCategory
{
static let datBoi : UInt32 = 0x1 << 1
static let Ground : UInt32 = 0x1 << 2
static let Wall : UInt32 = 0x1 << 3
}
class GameScene: SKScene
{
var Ground = SKSpriteNode()
var datBoi = SKSpriteNode()
override func didMove(to view: SKView)
{
datBoi = SKSpriteNode(imageNamed: "datboi")
datBoi.size = CGSize(width: 150, height: 240)
datBoi.position = CGPoint(x: -85, y: 0)
datBoi.physicsBody = SKPhysicsBody(rectangleOf: datBoi.size)
datBoi.physicsBody?.categoryBitMask = PhysicsCategory.datBoi
datBoi.physicsBody?.collisionBitMask = PhysicsCategory.Ground | PhysicsCategory.Wall
datBoi.physicsBody?.contactTestBitMask = PhysicsCategory.Ground | PhysicsCategory.Wall
datBoi.physicsBody?.affectedByGravity = true
datBoi.physicsBody?.isDynamic = true
datBoi.zPosition = 2
self.addChild(datBoi)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
datBoi.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
datBoi.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 100))
print("hi")
}
}
答案 0 :(得分:0)
Circle.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
Circle.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 74)) //Also try affected by gravity to false