Filling Out the Cases


#1


Filling Out the Cases-Super Mario


Oops, try again. Please follow the instructions on the Full Preview page to test your code.
I don't see what's wrong with my code.Help!Mario is not moving when i press the arrow buttons or the WASD buttons.

$(document).ready(function() {
    $(document).keydown(function(key) {
        switch(parseInt(key.which,10)) {
			// Left arrow key pressed
			case 37:
				$('img').animate({left: "-=10px"}, 'fast');
				break;
			// Up Arrow Pressed
			case 38:
				// Put our code here
				$('img').animate({top:"-=10px"},'fast');
				break;
			// Right Arrow Pressed
			case 39:
				// Put our code here
				$('img').animate({left:" += 10px"},'fast');
				break;
			// Down Arrow Pressed
			case 40:
				// Put our code here
				$('img').animate({top:"+=10px"}, 'fast');
				break;
		}
	});
});


#2

@creat,
As you are using the jQuery Selector $(document)
you will have to =click= once in the preview-screen
so that the preview-screen is on-focus
and then you can use the Arrow-key's.....

Use the code

$(document).ready(function() {
   $(document).keydown(function(key) {
        switch(parseInt(key.which,10)) {
       // Left arrow key pressed
       case 37:
          $('img').animate({left:"-=10px"}, 'fast');
          break;
       // Up Arrow Pressed
       case 38:
          // Put our code here
          $('img').animate({top:"-=10px"},'fast');
          break;
       // Right Arrow Pressed
       case 39:
          // Put our code here
          $('img').animate({left:"+=10px"},'fast');
          break;
       // Down Arrow Pressed
       case 40:
          // Put our code here
          $('img').animate({top:"+=10px"}, 'fast');
          break;
       }
  });
});

#3

i tried your code
it's still not working


#4

@creat
-1
You are not using my code
-2
did you mouse-click in the screen before using the Arrow-key's ??


#5

Hi Look @ ur code u write 2 times left and top once whit +10 and once white -10


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.