Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not really sure if what you mean exactly is, once the big white diagnal lines are all the way off the top right corner of page, that's when you want them to start back at the bottom left ? right?</p> <p>What you need to do is check if the line is beyond the width and height of the canvas, and in your case, the window itself since the canvas fills the browser window. So you need to do a series of conditionals. You check if the line x + line width is > canvas width and line.y + line height is > canvas height. If both are true then set the x and y of the line to - what it is at that time. So something like:</p> <pre><code>if( line.x + line.width &gt; canvas.width &amp;&amp; line.y + line.height &lt; 0) { line.x = -0; line.y = canvasHeight + line.height; } </code></pre> <p>This is how I recycle circles that come in from the right side of the screen and once they exit the left side they start over on the right.</p> <pre><code>if( d.x + d.radius &lt; 0 ) { d.radius = 5+(Math.random()*10); d.x = cwidth + d.radius; d.y = Math.floor(Math.random()*cheight); d.vX = -5-(Math.random()*5); } </code></pre> <p>The first thing is just psuedo, you should take a look at a thing I made to use as a starting point for things like this. The structure of your code could use some more organization, canvas gets real complex real quick. Using the arrow keys, move the square off any one of the 4 sides and see it come in on opposite side. <a href="http://anti-code.com/games/envy/envy.html" rel="nofollow">http://anti-code.com/games/envy/envy.html</a></p> <p>Fork if you want: <a href="https://github.com/jaredwilli/envy" rel="nofollow">https://github.com/jaredwilli/envy</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload