Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Canvas, negative coordinates: Is it bad to draw paths that start off canvas, and continue on?

Tags:

html

canvas

draw

I only want to show a portion of a shape drawn on a canvas. My line is essentially this, and it works fine:

ctx.fillRect( xPosition, rectHeight - offsetV , rectWidth, rectHeight);

The second variable there is going to be negative. So, my quesiton is: is it bad practice (or am I setting myself for errors down the road) to draw a path that starts off the canvas (with a negative coordinate) and then continue drawing on to the canvas.

like image 258
pinhead Avatar asked Nov 16 '12 03:11

pinhead


1 Answers

No problem at all. If you have very large number of drawing object you can (like GameAlchemist said) prevent drawing that object .If you use canvas like map for explore (zoom out/in ctx, translate whole context) that preventing draw can cost more that clip cost. And its complicated ...

I have some expire with drawing object out of canvas. You can have a problem if you put calculation and other (no drawing) staff intro draw function.

Important :

-Make canvas draw function code clear(only draw canvas code).

-If your app no need for const update make update call only when it needs.

-Clear canvas only in (0,0,canvas.w,canvas.h)

-Use style only when it needs (stroke,fill,font etc.)

like image 95
Nikola Lukic Avatar answered Sep 22 '22 15:09

Nikola Lukic