我的代码位于场景中registerupdatehandler
..
if (B.collidesWith(l)){
mSound.play();
}
目前,它会一次又一次地播放,直到B
离开l
(没有碰撞)。
更新
/* The actual collision-checking. */
mScene.registerUpdateHandler(new IUpdateHandler() {
@Override
public void reset() {
}
@Override
public void onUpdate(final float pSecondsElapsed) {
if (B.collidesWith(l)){
if (!mHasPlayed) {
Log.i("CONTACT", "BETWEEN B and L!");
mSound.play();
mHasPlayed = true;
} else {
mHasPlayed = false;
}
}
}
});
答案 0 :(得分:3)
如果您已使用成员变量播放此碰撞事件的声音,请跟踪。
private boolean mHasPlayed = false;
// ... rest of code
if (B.collidesWith(l)) {
if (!mHasPlayed)
mSound.play();
mHasPlayed = true;
} else {
mHasPlayed = false;
}