MySQL interesse |
|
als je naar de volgende url gaat kan je met je pijltjestoetsen een mannetje laten bewegen over de bg image, in mijn browser werkt het correct maar in andere browsers loopt hij alsmaar sneller als je een pijltje ingedrukt houdt
http://topspeedracing.be/new%20game/
mijn code:
<html>
<body onkeydown = "move(event.keyCode)" onkeyup="stopmoving();" style="background:url(images/citybg.jpg);">
<img id="blokje"></div>
<input type="hidden" id="stop" value="move">
<script type="text/javascript">
var margintop = 0;
var marginleft = 0;
var side;
function stopmoving()
{
side = document.getElementById('stop').value;
document.getElementById('blokje').src = "images/stop_"+side+".png";
document.getElementById('stop').value='stop';
}
function move(key)
{
if(key==37)
{
document.getElementById('blokje').src = "images/walk_left.gif";
document.getElementById('stop').value="walk_left";
moveLeft();
}
else if(key==38)
{
document.getElementById('blokje').src = "images/walk_up.gif";
document.getElementById('stop').value="walk_up";
moveUp();
}
else if(key==39)
{
document.getElementById('blokje').src = "images/walk_right.gif";
document.getElementById('stop').value="walk_right";
moveRight();
}
else if(key==40)
{
document.getElementById('blokje').src = "images/walk_down.gif";
document.getElementById('stop').value="walk_down";
moveDown();
}
}
function moveDown()
{
margintop = margintop+1;
document.getElementById('blokje').style.marginTop = margintop;
if(document.getElementById('stop').value!="stop")
{
setTimeout('moveDown()',5);
}
}
function moveUp()
{
margintop = margintop-1;
document.getElementById('blokje').style.marginTop = margintop;
if(document.getElementById('stop').value!="stop")
{
setTimeout('moveUp()',5);
}
}
function moveLeft()
{
marginleft = marginleft-1;
document.getElementById('blokje').style.marginLeft = marginleft;
if(document.getElementById('stop').value!="stop")
{
setTimeout('moveLeft()',5);
}
}
function moveRight()
{
marginleft = marginleft+1;
document.getElementById('blokje').style.marginLeft = marginleft;
if(document.getElementById('stop').value!="stop")
{
setTimeout('moveRight()',5);
}
}
</script>
</body>
</html>
<html> <body onkeydown = "move(event.keyCode)" onkeyup="stopmoving();" style="background:url(images/citybg.jpg);"> <img id="blokje"></div> <input type="hidden" id="stop" value="move"> <script type="text/javascript"> var margintop = 0; var marginleft = 0; var side; function stopmoving() { side = document.getElementById('stop').value; document.getElementById('blokje').src = "images/stop_"+side+".png"; document.getElementById('stop').value='stop'; } function move(key) { if(key==37) { document.getElementById('blokje').src = "images/walk_left.gif"; document.getElementById('stop').value="walk_left"; moveLeft(); } else if(key==38) { document.getElementById('blokje').src = "images/walk_up.gif"; document.getElementById('stop').value="walk_up"; moveUp(); } else if(key==39) { document.getElementById('blokje').src = "images/walk_right.gif"; document.getElementById('stop').value="walk_right"; moveRight(); } else if(key==40) { document.getElementById('blokje').src = "images/walk_down.gif"; document.getElementById('stop').value="walk_down"; moveDown(); } } function moveDown() { margintop = margintop+1; document.getElementById('blokje').style.marginTop = margintop; if(document.getElementById('stop').value!="stop") { setTimeout('moveDown()',5); } } function moveUp() { margintop = margintop-1; document.getElementById('blokje').style.marginTop = margintop; if(document.getElementById('stop').value!="stop") { setTimeout('moveUp()',5); } } function moveLeft() { marginleft = marginleft-1; document.getElementById('blokje').style.marginLeft = marginleft; if(document.getElementById('stop').value!="stop") { setTimeout('moveLeft()',5); } } function moveRight() { marginleft = marginleft+1; document.getElementById('blokje').style.marginLeft = marginleft; if(document.getElementById('stop').value!="stop") { setTimeout('moveRight()',5); } } </script> </body> </html>
|