Jump to content
ChidoriSoul

Javascript Move by Arrow Keys

Recommended Posts

So, as of now, I'm trying to make a Javascript map so that a character image can be placed on it, and the person who is controlling the character can use their arrow keys to navigate through the map. I've heard this can be done, but if at any possibilty, is it possible to make it so that some parts of the "map" image can not be put on, like a house or something.

Share this post


Link to post
Share on other sites

It's possible. But you'll have to find out how to make the system yourself. Javascript does not have any native functions or libraries to make games: You have to think of the math and logic of the program on your own.

Share this post


Link to post
Share on other sites

Thats the thing, I'm pretty basic with Javascript, I was just hoping someone will give me something to start with, as I have previously stated, I am bad at Javascript.

Edited by ChidoriSoul

Share this post


Link to post
Share on other sites

If you want to embark on such a project as described, maybe you should aim to improve your general JavaScript knowledge first?

Share this post


Link to post
Share on other sites

I'm not like super bad as having no experience at all, I do have some experience using Javascript for Proxy Blocking, javascript stopping, etc. I just didn't know how to "move" an image/slide an image across a div/background image.

Share this post


Link to post
Share on other sites
I'm not like super bad as having no experience at all, I do have some experience using Javascript for Proxy Blocking, javascript stopping, etc. I just didn't know how to "move" an image/slide an image across a div/background image.
You'd have to use absolute positioning to do that. When the arrow key is pressed you modify the appropriate top/left/right/bottom properties to move the image in the desired direction.As for having collidable objects, you could have an array with coordinates of the objects on the map. Then anytime the character should be moved, first check the destination. Test that destination against the array of coordinates to make sure it's not within any of them, and if it is don't move the character. Not guaranteeing that this is the best solution (because it most likely isn't) but it is an option.

Share this post


Link to post
Share on other sites

Each key on a keyboard is given a value.37: left38: up39: right40: downRead this

<script type="text/javascript">function displayunicode(e){var unicode=e.keyCode? e.keyCode : e.charCodealert(unicode)}</script><form><input type="text" size="2" maxlength="1" onkeyup="displayunicode(event); this.select()" /></form>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...