effacer Object2D

Bonjour
Je place differents Object2D dans un canvas … tout va bien
mais je n’arrive pas a les retirer
Avez vous une ide … voire une solution

Merci

Efface tout et redessine tout sauf celui que tu veux enlever ?

@Jean Luc Pellerin — Un Canvas est juste une page blanche sur laquelle tu peux dessiner. Ce n’est pas un éditeur d’image. Si tu veux apporter une modification, il faut tout redessiner.

Si tu utilises des Object2D, tu peux créer un tableau stockant tous les objets que tu veux dessiner et créer un boucle dans Canvas.Paint pour dessiner chaque objet. Si tu veux en enlever un, supprime-le du tableau puis appelle Canvas.Invalidate pour tout redessiner.

Emile : Je veux supprimer certains objets seulement
Stf: merci pour le invalidate

Oui effectivement il faut tout effacer et redessiner les objets restant

Merci a vous deux

Create an array of objects MyObjects()
Add your objects to the array, and ALSO add them to a Group2D object

In the paint event, just call

g.drawobject MyGroup2DObject … at position

If you need to remove the object in A,
Delete MyObject(x) from the Group2D
and set MyObject(x) to nil in the array

Then invalidate the canvas and it will redraw the group without your removed object

Drawing the group should be faster than iterating through your array of objects and drawing those individually.
It also allows you to move everything as a single item, by changing the start position of the Group
And you can zoom in and out , or rotate by changing the scale or rotation applied to the group