c# - XNA small noise when sound starts or stops playing -
i made small application plays .wav files when press keys, trying play music on keyboard, there noise speakers when release key, , believe when press it. .wav file sinusoidal wave, don't think it's source of problem, clues causes sound , workarounds? noise similar momentary static gen when plug in headphones or similar.
in order solve problem, have capture 2 keyboardstates.
keyboardstate oldstate; keyboardstate currentstate; public void load() { oldstate = keyboard.getstate(); } public void update(gametime gametime) { currentstate = keyboard.getstate(); //example below if (oldstate.iskeyup(keys.space) && currentstate.iskeydown(keys.space)) { //play sound } oldstate = currentstate; }
what make sure key being pressed's old state , new 1 down. stop sound playing on , on again. @ end of update loop, set currentstate oldstate , start logic on again.
Comments
Post a Comment