Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8433611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:26:03+00:00 2026-06-10T06:26:03+00:00

I’m writing a game in javascript, and I want my character to mave under

  • 0

I’m writing a game in javascript, and I want my character to mave under blocks (isometric png images) instead of simply sliding through them. Is there a way to dynamically change my character’s position in the html as he moves up and down layers?

Current progress of the game can be seen here, to show what I want to fix: http://dl.dropbox.com/u/18785762/Rust/index.html

Character Creation and movement code:

function mainchar(){
    var mainchar = new Image();
    mainchar.id = "mainChar";
    mainchar.src = "Images/Char_01.png";
    mainchar.style.top = "62px";
    mainchar.style.left = "0px";
    mainchar.style.position = "absolute";

    window.addEventListener("keydown", movechar);

    document.body.appendChild(mainchar);
}

function movechar(e){
    var event = event || e;

    var mainChar = document.getElementById("mainChar");

    var top = Number(mainChar.style.top.replace("px",""));
    var left = Number(mainChar.style.left.replace("px",""));
    var stepSize = 32;           

    switch (event.keyCode){
        case 37:
        case 65: //left
            left = left -27;
            top = top -13;
        break;
        case 39:
        case 68: // right
            left = left + 27;
            top = top +13;
        break;
        case 38:
        case 87: // up
            left = left +27;
            top = top -13;
        break;
        case 40:
        case 83: // down
            left = left -27;
            top = top +13;
        break;    
    }

    mainChar.style.top = top + "px";
    mainChar.style.left = left + "px";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:26:05+00:00Added an answer on June 10, 2026 at 6:26 am

    http://jsfiddle.net/yRyLN/1/

    I modified the following:

    The basic concept is that the z-index is increased by 1 for each step away from the lowest block. All you need to do now is add some collision detection. Fun stuff!

    function drawlayer(level, depth) {
        var images = BlockID();
    
        var top = depth;
        var left = sidecalc(level);
        var mytop = top;
        var myleft = left;
        var y;
        for (y=0; y<level.length; ++y) {
            var row = level[y];
            var x;
            for (x=0; x < row.length; ++x) {
                var c = row.charAt(x);
                if(c != ' ') {
                    console.log(mytop + "," + myleft);
                    img_create(images[c], mytop, myleft, y + x);
                }
                mytop += 13;
                myleft += 27;
            }
            mytop = top + (y+1)*13;
            myleft = left - (y+1)*27;
        }
    }
    
    function img_create(src, top, left, zIndex) {
        console.log(top + "," + left);
        var block = new Image();
        block.src = src;
        block.style.top = top + "px";
        block.style.left = left + "px";
        block.style.position = "absolute";
        block.style.zIndex = zIndex;
        document.body.appendChild( block );
    }
    function mainchar(){
        var mainchar = new Image();
        mainchar.id = "mainChar";
        mainchar.src = "http://dl.dropbox.com/u/18785762/Rust/Images/Char_01.png";
        mainchar.style.top = "62px";
        mainchar.style.left = "0px";
        mainchar.style.position = "absolute";
        mainchar.style.zIndex = 0;
        window.addEventListener("keydown", movechar);
    
        document.body.appendChild(mainchar);
    }
    
    function movechar(e){
        var event = event || e;
    
        var mainChar = document.getElementById("mainChar");
    
        var top = Number(mainChar.style.top.replace("px",""));
        var left = Number(mainChar.style.left.replace("px",""));
        var stepSize = 32;           
        var zIndex = Number(mainChar.style.zIndex);
    
        switch (event.keyCode){
            case 37:
            case 65: //left
                left = left -27;
                top = top -13;
                zIndex -= 1;
            break;
            case 39:
            case 68: // right
                left = left + 27;
                top = top +13;
                zIndex += 1;
            break;
            case 38:
            case 87: // up
                left = left +27;
                top = top -13;
                zIndex -= 1;
            break;
            case 40:
            case 83: // down
                left = left -27;
                top = top +13;
                zIndex += 1;
            break;    
        }
    
        mainChar.style.zIndex = zIndex;
        mainChar.style.top = top + "px";
        mainChar.style.left = left + "px";
    }
    

    EDITED: http://jsfiddle.net/yRyLN/2/

    Fixed a small layering issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.