0

Ok so i have paid a coder to code me a walk around map script were users can press up and down on the keyboard and walk aroud a map using jquery. But now im trying to make it so i have a up and down image and then on click it will call the up and down function. So the suer can use the up and down keys plus clicking the images.

Here is the up function im using for when the user presses the up key on the keyboard. But now some how i need to call the same function when a image is clicked..

function move(d)
{
 if(d == "UP")
 {
 var top = (parseInt(document.getElementById('move').style.top) - 10);
 var left = parseInt(document.getElementById('move').style.left);
 if(canMove(new xy(left,top)))
 {
 document.getElementById('move').style.top = (parseInt(document.getElementById('move').style.top) - 10) + 'px';
 document.player.src = "maps/sprites/playerUp.png";
 //if(lastStep != "UP") clearTimeouts();
 //setTimeout('document.player.src="playerUp.png"', 500);
 //lastStep = "UP";
 reloadF();
 }
 }

How would i do about doing that ??

Im guessing i just need to call function move(d) and set it to up some how ?? On click of image ?

2
  • 2
    this has nothing to do with PHP or jQuery (seeing that you're not using jQuery). this is only javascript. Commented Dec 31, 2012 at 23:28
  • and if you ARE going to use jQuery, this would be simple as something like $('.your-image').click(function() { move("UP"); }); Commented Dec 31, 2012 at 23:34

1 Answer 1

2
var keynum = 0;
if(window.event) { keynum = e.keyCode; } // for IE
else if(e.which) { keynum = e.which; } // for others browsers
if(keynum === 38) { // up
 //if KEY UP
}
if(keynum === 40) { // down
 //if KEY DOWN
}

I hope this help...

answered Dec 31, 2012 at 23:29
Sign up to request clarification or add additional context in comments.

2 Comments

what im trying to say is i need it so when a html button or image is clicked it called the function above....
If you can't figure that out, it's time to hire another coder.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.