- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用受风影响的雨粒子,也就是 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/
我不完全确定我做错了什么。我之前已经多次编写过这段代码,没有出现任何问题。问题是物理世界似乎没有更新,我不知道为什么!现在我有一个 gameScene 类,它扩展了一个普通场景,这是 onCreate
好吧,我正在使用 andengine 和 box2d 扩展你看,我的物体从地面(红色矩形)飞到相机的屋顶(黄色),我不明白这是怎么回事 这是我的代码的一部分, @Override public Eng
我正在尝试使用受风影响的雨粒子,也就是 physicsWorld 重力。 我可以看到重力确实对我的 SKSpriteNode 有影响,但我无法对 SKEmitterNode 产生相同的影响。 我只是想
我的场景中有几个节点,我可以旋转和拖动它们。我已经设置了一个 physicsWorld 委托(delegate),将类型为 kinematic 的 physicsBody 添加到我的节点并检查 phy
我正在尝试确定在旋转节点的路径中是否存在可能的接触。我的想法是做一个递增的旋转(90 度我循环 10 次 9 度)并且每次都进行接触测试。我的问题是,即使我每次都调用 updateCollisionP
我正在使用 AndEngine 尝试使用加速度计移动 Sprite (球),该加速度计应该会在墙壁上反弹并撞到其他障碍物。 到目前为止,我发现了以下两种方法。 public void onAccel
这里有两个可能相关的事情: 1) 我可以使用 self、self.scene 和 myWorld 从我的 SKScene impelmentation 文件中绘制一个框并添加到子项,但不能使用 SKS
我正在尝试向场景 physicsWorld 属性添加一个关节,但我收到了 EXC_BAD_ACCESS。这是我正在使用的代码。 SKPhysicsJointFixed *fixedJoint = [S
我刚刚在将 contactDelegate 分配给自己(GameScene)时遇到了问题。 override func didMoveToView(view: SKView) { self.p
我正在使用 SceneKit 的 physicsBody 系统来检测对象之间的碰撞,并得到一些非常奇怪的结果。为了说明这一点,我有一个最小的示例,它生成两个具有运动学 physicsBodies 的球
我目前正在尝试使用 cocos2d-x 引擎制作游戏。正如我想象的那样,这款游戏需要滚动背景。然后我所做的是在表格中创建 2 个背景 Sprite : bool HelloWorld::init()
我想使用触摸拖放主体及其 Sprite 。我确实知道如何拖放 Sprite ,但是当我尝试移动 body 时它...不起作用, body 保持静止。更重要的是,有时当我触摸 body 时,整个应用程序
我正在编写的游戏中使用 Sprite Kit 的内置物理引擎。为了检查角色是否在地面上,我使用了 SKScene 的 physicsWorld 的 bodyAlongRayStart() 函数检查角色
我是一名优秀的程序员,十分优秀!