I’m creating a basic game that draws squares at random positions on a canvas, but sometimes the shape gets cut off because it’s outside of the canvas’ boundaries. Can any one explain how I could go about getting the square to be drawn on the other side of the canvas (similar to how it’s done in asteroids)? The searches I’ve come up with haven’t been helpful. Any help is appreciated.
Share
OK I think I’ve solved this one. Basically this code only draws the square whilst it is inside the canvas, if it leaves the canvas it checks which boundaries it is leaving and updates the position. The looped variable is needed because otherwise the square will be always leaving the canvas.
I’d do a JSFiddle but requestAnimationFrame doesn’t play nice with it.