O'Reilly Forums: Moving The Canvas Screen Keys - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Moving The Canvas Screen Keys

#1 User is offline   redok 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 16-January 13

Posted 16 January 2013 - 02:01 AM

Hi everybody.
Can someone please explain to me a short example of how to move the screen in the X-axis on the canvas? - As this is a gaming platform.
I know how to move the image/object canvas, of course, with the help function setInterval() and var keyCode.

Example: I have a canvas object, where the width is 500, the height is 300, and for that I have a map generated at 2000px.
I created a form/image to move. I would like the arrow keys to move screen.

 function KeyDown(e) 
 {
    switch(e.keyCode) 
    {
      //left
      case 37:
      x_right -= 5;
      // instructions to move the screen...
      break;
      
      //right
      case 39:
      x_right += 5;
      // instructions to move the screen...
      break;
   }
}

0

#2 User is offline   redok 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 16-January 13

Posted 17 January 2013 - 07:39 AM

Ok I know how to do it, it simple...
Just keep the form and assign a new change to the site.
Code:
function KeyDown(e) 
 {
    switch(e.keyCode) 
    {
      //left
      case 37:
      //x_right -= 0;
      x_form += 5;
      break;
      
      //right
      case 39:
      //x_right += 0;
      x_form += 5;
      break;
   }

}
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users