Abd*_*iri 5 javascript html5 phaser-framework
使用Phaser API时,我在碰撞中遇到了一些问题。
我有以下代码:
game.physics.arcade.collide(sprite1, sprite2, this.collision, null, this);
collsion: function(){
//Play a sound;
}
Run Code Online (Sandbox Code Playgroud)
这里的问题是当两个精灵碰撞时,声音会继续播放。它们只有在不碰撞时才会停止。但是我只想播放一次声音。
自己测试后编辑。
尝试重叠:
create : function() {
...
this.timeDelay = 0;
}
game.physics.arcade.overlap(sprite1, sprite2, this.overlap, null, this);
overlap: function(){
if (game.time.now > this.timeDelay){
game.sound.play("sound");
// wait 1 second
timeDelay = game.time.now + 1000
}
}
Run Code Online (Sandbox Code Playgroud)