2012-08-05 6 views
0

게임을 만들고 시작 화면이 나타나면 일부 음악이 재생되기 시작합니다. 이제 시작 화면에 체크 박스를 추가했습니다. 이 확인란을 선택하면 선택하지 않으면 음악을 듣고 음악을 재생할 수 없습니다. 그래서, 음악을 재생할 경우 체크 박스가 선택된 경우 gameload에체크 박스가 선택 취소되어있을 때 소리가 나지 않음

// Show the start screen and play some music. 
game.start(game.DEMO_MODE); 
if (document.getElementById('music').checked){ //check if checkbox is checked 
    music.play(); 
    music.loop(); //Loop the music 
} 

이 코드 검사 :

나는 이것에 대한 다음과 같은 코드가 있습니다. 이 알은 훌륭하지만 게임이로드 될 때만 작동합니다. 체크 박스가 선택되어 있고 시작 화면에있을 때 사람이 선택하지 않으면 음악이 계속 재생됩니다. 게임을 다시로드하지 않으면 소리가 나지 않습니다.

분명히 나는 ​​이것을 원하지 않는다. 확인란의 선택을 취소하면 소리가 멈추고 반대의 경우 소리가 멈 춥니 다.

이 문제는 jQuery의 .bind('change',function(){을 사용하여 해결할 수 있다고 생각하지만 그렇게하지 못했습니다.

jQuery(function($) { 
    // Aa key must is used for the cookie/storage 
    var storedData = getStorage('com_test_checkboxes_'); 

    $('div#musiccheck input:checkbox').bind('change',function(){ 
     // do something here tho mute or unmute the sound?? 

     // save the data on change 
     storedData.set(this.id, $(this).is(':checked')?'checked':'not'); 
    }).each(function() { 
     // on load, set the value to what we read from storage: 
     var val = storedData.get(this.id); 
     if (val == 'checked') $(this).attr('checked', 'checked'); 
     if (val == 'not') $(this).removeAttr('checked'); 
     if (val) $(this).trigger('change'); 
    }); 
}); 

이 문제를 해결하는 방법 : 나는

(이 쿠키 또는 로컬 스토리지/체크되지 않은 상태 점검의 IT는 또한 저장) 확인란에 대한 코드 ... 누군가가 여기에 추가 될 필요가 알고 희망 ?

종류와 관련,

모리스

답변

1
$("#music").on('change', function() { 
    if (this.checked) { 
     music.play(); 
     music.loop(); 
    }else{ 
     music.stop(); 
    } 
}); 
+0

이 잘 작동합니다, 감사합니다! – Maurice

관련 문제