Jump to content

logic spacing problem


L2L2L
 Share

Recommended Posts

I rewrote your Box.toRight and Box.toLeft functions. Comments are in the code for an explanation of what it's doing.

// Boxes start out against the left edge of the canvas, with 25 pixels between each box.// This means some boxes may start off the right edge of the canvas.// The total length of the list of boxes is (number of boxes * (width of box + padding)).Box.toRight = function (canvas, box) {  if (box.x < canvas.x + canvas.width) {    // Box is on the canvas. Move it right.    box.x += 5;  } else {    // Box is off the canvas. Move it to the left end of the list of boxes.    box.x -= boxs.length * (box.width + 25);  }};Box.toLeft = function (canvas, box) {  if (box.x + box.width > canvas.x) {    // Box is on the canvas. Move it left.    box.x -= 5;  } else {    // Box is off the canvas. Move it to the right end of the list of boxes.    box.x += boxs.length * (box.width + 25);  }};
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...