html - Can you count clicks on a certain frame in an animation in javascript? -
i'm looking build simple whack mole-esque game in javascript. right know how else except scoring. current animation code follows
<script language="javascript" type="text/javascript"> var urls; function animate(pos) { pos %= urls.length; document.images["animation"].src=urls[pos]; window.settimeout("animate(" + (pos + 1) + ");", 500); } window.onload = function() { urls = new array( "frame1.jpg","frame2.jpg" ); animate(0); } </script>
so far works, first frame hole , second groundhog/mole out of hole. need count clicks on second frame can't figure out how incorporate counter. help? (sorry if code doesn't show correctly, first time using site)
here example counts clicks on flashing animation: http://jsfiddle.net/maniator/tqqj8/
js:
function animate(pos) { pos %= urls.length; var animation = document.getelementbyid('animation'); var counter = document.getelementbyid('counter'); animation.src = urls[pos]; animation.onclick = function() { counter.innerhtml = parseint(counter.innerhtml) + 1; } settimeout(function() { animate(++pos); }, 500); }
update:
here fiddle detects click on 1 of images: http://jsfiddle.net/maniator/tqqj8/8/
Comments
Post a Comment