gpt4 book ai didi

Swift:SKEmitterNode 受 PhysicsWorld 重力影响?

转载 作者:行者123 更新时间:2023-11-28 05:38:21 24 4
gpt4 key购买 nike

我正在尝试使用受风影响的雨粒子,也就是 physicsWorld 重力。

我可以看到重力确实对我的 SKSpriteNode 有影响,但我无法对 SKEmitterNode 产生相同的影响。

我只是想知道这是否可能。

这是我一直在尝试的...

    override func didMove(to view: SKView) {

if let rainParticles = SKEmitterNode(fileNamed: "Rain.sks") {
rainParticles.position = CGPoint(x: size.width/2, y: size.height)
rainParticles.name = "rainParticle"
rainParticles.targetNode = scene
rainParticles.particlePositionRange =
CGVector(dx: frame.size.width, dy: frame.size.height)
rainParticles.zPosition = -1

// I don't think this is right
rainParticles.physicsBody = SKPhysicsBody(edgeLoopFrom: frame)
rainParticles.physicsBody?.affectedByGravity = true
addChild(rainParticles)
}

physicsWorld.contactDelegate = self
// gravity is pushing to the right here
physicsWorld.gravity = CGVector(dx: 20, dy: 0)
physicsWorld.speed = 0.85
}

是的,我添加了SKPhysicsContactDelegate

显然,我想忽略碰撞,所以我没有设置 collisionBitMask,而且我不想让 contactTestBitMask 的任何东西弹跳。我认为我不需要设置 categoryBitMask

最佳答案

Particles are not represented by objects in SpriteKit. This means you cannot perform node-related tasks on particles, nor can you associate physics bodies with particles to make them interact with other content. Although there is no visible class representing particles added by the emitter node, you can think of a particle as having properties like any other object.

这直接来自 SKEmitterNode 文档。粒子不会从场景的 physicsWorld 获得任何重力加速度。此外,rainParticles.physicsBody 指的是 SKEmitterNode physicsBody,而不是它的粒子。

如果您只是想让粒子模拟当前 physicsWorld 的重力:

rainParticles.xAcceleration = self.physicsWorld.gravity.dx
rainParticles.yAcceleration = self.physicsWorld.gravity.dy

关于Swift:SKEmitterNode 受 PhysicsWorld 重力影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57795835/

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