테스트 용으로 92 이미지 PNG 파일을 찾는 데 어려움이있어서 더 짧은 파일로 처리해야했습니다. http://jsfiddle.net/Yhrbb/
예제의 코드는 다음과 같습니다 : 다음 동작하는 예제입니다
(function() {
var total = 92;
var play_on_click = 72;
var played = 0;
$('#fly').click(function() {
if (played >= total) {
return;
}
var current_play;
if (play_on_click > (total - played)) {
current_play = total - played;
}
else {
current_play = play_on_click;
}
played += current_play;
$('#bird').sprite({fps: 12, no_of_frames: 3, play_frames: current_play});
});
})();
당신이 그렇게 좋아 위해 우리는 일을 적응할 수 : 일단 우리가 도달
(function() {
var total = 92;
var play_on_click = 72;
var played = 0;
$('#stacheguy2').click(function() {
if (played >= total) {
return;
}
var current_play;
if (play_on_click > (total - played)) {
current_play = total - played;
}
else {
current_play = play_on_click;
}
played += current_play;
$(this).sprite({fps: 30, no_of_frames: 92, play_frames: current_play});
});
})();
주 총 프레임 수는 return
이고 추가 클릭 수는 무시됩니다. if (played >= total)
입니다. 그 시점에서 played
을 재설정하거나 원하는 다른 작업을 수행 할 수 있습니다. 이것이 작동하지 않는다면 jsfiddle에서 사용할 PNG 파일이나 비슷한 파일을 게시하는 것이 좋습니다. http://jsfiddle.net/dNYks/
(function() {
var play_on_click = [32, 21, 10, 20];
var play_index = 0;
$('#fly').click(function() {
var current_play = play_on_click[play_index];
play_index++;
if (play_index > play_on_click.length-1) {
play_index = 0;
}
$('#bird').sprite({fps: 12, no_of_frames: 3, play_frames: current_play});
});
})();
우리는 당신의 마크 업을 일치하도록이 코드를 적용 할 수 있습니다 : 당신은 당신이 할 수있는 클릭 각각의 프레임 구성 수를 재생하고 싶다면
배열
와 프레임 수를 설정 그래서 같은 :
(function() {
var play_on_click = [32, 21, 10, 20];
var play_index = 0;
$('#stacheguy2').click(function() {
var current_play = play_on_click[play_index];
play_index++;
if (play_index > play_on_click.length-1) {
play_index = 0;
}
$(this).sprite(fps: 30, no_of_frames: 92, play_frames: current_play});
});
})();
고마워요! 네, 확실히 성공했습니다. 실례지만, 다른 질문을해야합니다. 객체를 다시 클릭 할 수있게하려면 무엇을 작성해야합니까? (그리고이 기존 코드에 어떻게 추가해야합니까?) 그리고 더 구체적으로 말하자면, 가능한 한 새로운 클릭마다 더 많은 애니메이션을 수행 할 수 있기를 바랍니다. –
3 번 클릭하면 어떤 일이 발생하기를 원하십니까? (첫 번째 시간은 72 프레임, 두 번째 시간은 나머지를 재생합니다)?72 개, 나머지 72 개, 나머지 72 개 등을 반복하고 싶습니까? – Cymen
다음 스프라이트 시트의 다음 프레임을 수행 할 수 있도록 스프라이트 시트에 프레임을 더 추가하고 싶습니다. 예를 들어 ... 첫 번째 클릭 = 프레임 1 - 70, 두 번째 클릭 = 프레임 71-92, 세 번째 클릭 = 프레임 93-103 등. –