当球形状击中任何其他形状时,我试图发出“轰鸣”声。这有效。但效果有点太好了……
当球静止或开始滚动时,它会与它所接触的任何物体发生永久碰撞,因此会不断发出“轰鸣”声。
我在花栗鼠文档中找不到任何内容来告诉我何时两件事永久碰撞。所以我想我必须自己想办法解决这个问题,可能是使用某种计时器来比较上次碰撞与当前碰撞。但这对我来说听起来很老套。
有人解决过这个问题吗?你是怎么解决的?
I'm trying to play a "boing" sound when a ball shape hit's any other kind of shape. Which works. But works a little too well....
When the ball comes to rest, or starts to roll, it's in a permanent collision with whatever it's touching, so the "boing" sound fires constantly.
I can't find anything in the chipmunk documentation to tell me when two things are permanently colliding. So I'm thinking I will have to somehow figure it out myself, probably with some sort of timer that compare the last collision against the current collision. But that sounds hacky to me.
Has anyone tackled this issue? How did you solve it?
发布评论
评论(3)
当接触中断时,你不能只播放“boing”声吗?
在chipmunk中有一个回调,
typedef void (*cpCollisionSeparateFunc)(cpArbiter *arb, struct cpSpace *space, void *data)
这样,每当它弹起时,你都会收到boings,但当它只是滚动。当然,当它从你的形状上滚下来时,你也会得到一个,但这可能是一个功能,具体取决于你如何看待它。
Couldn't you just play your "boing" sound when contact is BROKEN?
There is a callback for that in chipmunk,
typedef void (*cpCollisionSeparateFunc)(cpArbiter *arb, struct cpSpace *space, void *data)
That way you get boings whenever it bounces, but not when it's just rolling along. 'course, you'll also get one when it rolls off of your shape, but that could be a feature depending on how you look at it.
我不认为我要说的是一个好的做法,但我相信它会解决你的问题:
对于每个对象,保留两个状态变量:(1)最后一个对象碰撞, (2) 最后一次碰撞时间。
碰撞时,仅当碰撞对象不同(和球)或自上次碰撞以来已经过了一定的“增量时间”时才播放声音。然后记录最后一次碰撞统计数据。
这非常简单而且非常有效:
I don't think that what I'm about to say is a good practice, but I'm sure it will solve your problem:
For each object, keep two state variables: (1) The last object collided with, (2) The last collision time.
Upon collision, only play a sound if the collided object is different (and a ball) OR a certain "delta time" has elapsed since the last collision. Then record the last collision stats.
This is pretty simple and very effective:
花栗鼠的形状没有速度。他们所附着的身体拥有它。您可以像这样访问速度:“myShape.body->v”。我同意您应该能够检查速度是否超过某个阈值,以了解何时发生“影响”。您还可以检查旋转速度以查看球是否在滚动。
Shapes don't have velocity in chipmunk. The bodies they are attached to have it. You can access velocity like this: "myShape.body->v". I agree that you should just be able to check if the velocity is over a certain threshold to know when an 'impact' occurs. You can also check the rotational velocity to see if the ball is rolling.