テスト用の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});
});
})();
</ p>
</ p>