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

  • SEARCH
  • Home
  • 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 7637439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:56:24+00:00 2026-05-31T07:56:24+00:00

Not much good in jQuery/javascript but trying to create a small game. here is

  • 0

Not much good in jQuery/javascript but trying to create a small game.

here is the jsfiddle link: http://jsfiddle.net/zDer5/

I am trying to move img all around the div. I am SUCCESSFULLY able to move it in all the direction and also diagonally by holding an arrow key or two for diagonal move.

But the problem is , if i hold right arrow key to move right and in between if i press up key to move diagonally up AND NOW if i release the up key ( still holding the right arrow key ) … the movement STOP, where i expected it to move right.

It happen in all the cases .. holding left,press up and release up … movement STOP.

SECOND: the image halt for second once i change the direction. any guide for smooth movement.

Thank YOU

here is the jsfiddle link: http://jsfiddle.net/zDer5/

i am also pasting the same code here

    var keys = {};

$('body').keydown(function(event){

    keys[event.which] = true;
    moveDot();
});

$(document).keyup(function (event) {
    delete keys[event.which];
    moveDot();
});

function moveDot(){


            var html = '';
                for (var i in keys) {
                    if (!keys.hasOwnProperty(i)) continue;
                        html += '<p>' + i + '</p>';

                   if(i == '37'){
                        var left = $('#dot').css("left");
                        left = parseInt(left.match(/\d+/));
                        left = left-3;
                        $('#dot').css({ 'left': left + 'px' });
                    }
                   if(i == '38'){
                        var top = $('#dot').css("top");
                        top = parseInt(top.match(/\d+/)); 
                        top = top-3;
                        $('#dot').css({ 'top': top + 'px' });
                   }
                   if(i == '39'){
                      var left2 = $('#dot').css("left");
                        left2 = parseInt(left2.match(/\d+/)); 
                        left2 = left2+3;
                        $('#dot').css({ 'left': left2 + 'px' });
                    }
                    if(i == '40'){
                        var top2 = $('#dot').css("top");
                        top2 = parseInt(top2.match(/\d+/)); 
                        top2 = top2+3;
                        $('#dot').css({ 'top': top2 + 'px' });
                    }     

                }
                $('#out').html(html);
 }

<div id="game-panel">
     <img src="http://203.157.202.2/photos2009/Pic/thumbnails/black_dot_400x400.jpg" id="dot" />
</div>

#game-panel{ position: relative; border: 2px solid #ccc; height: 200px; }
    #game-panel img{ position:absolute; }
    #dot{ left:100px; top:100px; }
  • 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-05-31T07:56:25+00:00Added an answer on May 31, 2026 at 7:56 am

    Your problem is that you break your update mechanisms on keyup. If you use an interval to control the refresh loop it works just fine. See this updated fiddle: http://jsfiddle.net/zDer5/1/

    On a side note, i can really recommend this tutorial: http://www.html5rocks.com/en/tutorials/canvas/notearsgame/ which seems to fit your needs perfectly although it takes a slightly different approach.

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

Sidebar

Related Questions

Is it good practice not to use much javascript/jquery? Should we avoid it as
I'm not too good with SQL and I know there's probably a much more
not much of a programming question, but development related still, I'm starting Android development
Probably not much more to elaborate on here - I'm using a NumericStepper control
I'm not much of a Visual Basic person, but I am tasked with maintaining
I'm not much into COM interfaces, so i have a small question, say I
Here's the code. Not much to it. <?php include("Spreadsheet/Excel/Writer.php"); $xls = new Spreadsheet_Excel_Writer(); $sheet
I mostly followed these instructions to get things spun up: http://lindsaar.net/2010/5/9/Getting-Rails-3-Edge-with-jQuery-RSpec-and-Cucumber-using-RVM If I create
Obviously, horses for courses, but what are some good ways to integrate javascript libraries
I'm really not that good at Javascript and that, so I need another bit

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.