K
K
Kirill2019-12-06 19:31:08
JavaScript
Kirill, 2019-12-06 19:31:08

How to remove an element from a field?

There is a code that puts a stone (Go term) on the field, the code does a great job, but there is a need to remove this stone (Go term) from the field, how can this be done?
But in order not to erase part of the field under the stone after removal.

ctx.beginPath();
      ctx.moveTo(140, 140);
      ctx.arc(140, 140, 18.5, 0, 2 * Math.PI);
      ctx.stroke();
      ctx.fill();

5dea824430446434054773.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
ⓒⓢⓢ, 2019-12-07
@Atari123

no way, redraw the canvas without a stone

R
Rustam Azizov, 2019-12-07
@UnformedVoid

You use the canvas as a state store - this is an imperative approach and therefore inconvenient. It's like jQuery, only worse because you don't have selectors. You should not rely on what is drawn on the canvas. Your canvas should just serve as a representation. Put all your data in JS as an array or an object, whichever you prefer. Next, write the code that will redraw your canvas when the state changes. There are two ways to solve problems: the first is the one that you tried to solve the issue - a direct way, the second way is to change the task so that in the new context the problem becomes impossible, meaningless, in general, ceased to exist. If you take out all the logic in JS, then the question “how to delete” will not remain with you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question