SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Moving The Canvas Screen Keys

    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.

    Code:
     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;
       }
    }

  2. #2
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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;
       }
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •