allow pausing of round playback

This commit is contained in:
Alyssa Milburn 2014-07-30 13:26:29 +02:00
parent 29240f7331
commit 5f41251403
2 changed files with 22 additions and 1 deletions

View File

@ -36,6 +36,9 @@ cat <<EOF >$fn
<html> <html>
<head> <head>
<title>Tanks Round $next</title> <title>Tanks Round $next</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/ui-lightness/jquery-ui.css" type="text/css">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/ui/1.11.0/jquery-ui.min.js"></script>
<script type="application/javascript" src="tanks.js"></script> <script type="application/javascript" src="tanks.js"></script>
<link rel="stylesheet" href="style.css" type="text/css"> <link rel="stylesheet" href="style.css" type="text/css">
<script type="application/javascript"> <script type="application/javascript">

View File

@ -178,10 +178,22 @@ function Tank(ctx, width, height, color, sensors) {
} }
} }
var loop_id;
var updateFunc = null;
function togglePlayback() {
console.log($("#playing").prop("checked"));
if ($("#playing").prop("checked")) {
loop_id = setInterval(updateFunc, 66);
} else {
clearInterval(loop_id);
loop_id = null;
}
$("#pauselabel").toggleClass("ui-icon-play ui-icon-pause");
}
function start(id, game) { function start(id, game) {
var canvas = document.getElementById(id); var canvas = document.getElementById(id);
var ctx = canvas.getContext('2d'); var ctx = canvas.getContext('2d');
var loop_id;
canvas.width = game[0][0]; canvas.width = game[0][0];
canvas.height = game[0][1]; canvas.height = game[0][1];
@ -238,10 +250,16 @@ function start(id, game) {
} }
} }
updateFunc = update;
loop_id = setInterval(update, 66); loop_id = setInterval(update, 66);
//loop_id = setInterval(update, 400); //loop_id = setInterval(update, 400);
if (fps) { if (fps) {
setInterval(update_fps, 1000); setInterval(update_fps, 1000);
} }
if (id === "battlefield") {
$("#game_box").append('<p><input type="checkbox" checked id="playing" onclick="togglePlayback();"><label for="playing"><span class="ui-icon ui-icon-pause" id="pauselabel"></class></label></p>');
$('#playing').button();
}
} }