Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.lang.javascript > #8051

Re: Canvas di HTML5, cancellazione contenuto

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Alessandro Pellizzari <shuriken@amiran.it>
Newsgroups it.comp.lang.javascript
Subject Re: Canvas di HTML5, cancellazione contenuto
Date Fri, 29 Jul 2016 14:40:36 +0100
Lines 39
Message-ID <e014mkFaqurU1@mid.individual.net> (permalink)
References <G8Imz.47842$pt.5792@tornado.fastwebnet.it>
Mime-Version 1.0
Content-Type text/plain; charset=iso-8859-15; format=flowed
Content-Transfer-Encoding 8bit
X-Trace individual.net Gh443bEh3eE0+IOJiM92FQ3nBgNwnBrjUGDDVLCS+qrStVvVg=
Cancel-Lock sha1:dTVcEhQo1BzCkyy/H8nZkMeFqc0=
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:45.0) Gecko/20100101 Thunderbird/45.2.0
In-Reply-To <G8Imz.47842$pt.5792@tornado.fastwebnet.it>
Xref csiph.com it.comp.lang.javascript:8051

Show key headers only | View raw


On 29/07/2016 13:40, leonardo.1+++ wrote:

> perché disegna di nuovo anche il segmento precedentemente cancellato?

> $(document).ready(function() {
>
> var canvas = document.getElementById("myCanvas");
> var ctx = canvas.getContext("2d");

Qui stai ottenendo un context

> $("#Cancella").click(function(){  // alert("fatto click sul Cancella");
>  ctx.clearRect(0, 0, canvas.width, canvas.height);

E qui lo usi.

>   });
>
> $("#Esegui").click(function(){// alert("fatto click sul Esegui");
>
> var canvas = document.getElementById("myCanvas");
> var ctx = canvas.getContext("2d");

Qui ne chiedi un altro. Puoi usare lo stesso che hai già creato fuori 
dalla funzione.

Ma non è qui il tuo problema, questa è solo "ottimizzazione". :)

> ctx.moveTo($x1,$y1);
> ctx.lineTo($x2,$y1);
> ctx.stroke();

Qui non stai svuotando il buffer dei segmenti.
Prima di fare il moveTo() devi chiamare beginPath() per svuotare il 
buffer, altrimenti ti ridisegna tutto ogni volta.

Bye.

Back to it.comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Canvas di HTML5, cancellazione contenuto "leonardo.1+++" <leonardo.1@fastwebnet.it> - 2016-07-29 14:40 +0200
  Re: Canvas di HTML5, cancellazione contenuto Alessandro Pellizzari <shuriken@amiran.it> - 2016-07-29 14:40 +0100
    Re: Canvas di HTML5, cancellazione contenuto "leonardo.1+++" <leonardo.1@fastwebnet.it> - 2016-07-29 16:33 +0200

csiph-web