How to erase the node to make the object acts like moving?

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from random import randint, random
from pandac.PandaModules import LineSegs
from panda3d.core import Point3D, NodePath
from direct.showbase.ShowBase import ShowBase 

class MyApp(DirectObject):

    class Draw(LineSegs):
        var = 0;

        def __init__(self):

        def drawLine(self,startPoint,endPoint,color=None,thickness=None):            
            if color is None: color = (0.5,1,1,1)
            if thickness is None: thickness = 1                    

	def gameloop(self,task):
            self.var += 0.0001
            change = self.var
            self.drawLine((-0.2-change,1,0.2), (-0.2-change,1,-0.2))
            node = self.create()
            np = NodePath(node)
            return task.cont

app = MyApp()
d = app.Draw()


My code draws the line in different position, and I want to erase the previous line when a new line appear, but I dont know how to acheive this, if I put the detachNode() right after the reparentTo(render), there is no line at all cuz I think it’s being remove immediately. Is there any better way to do this?

Thank you!

what you want to do sounds like a perfect job for a “meshdrawer”. you may whish to search the forum and the api docs about it. was made for stuff like particles and motion trails.

Is meshdrawer has any function that can erase the previous line?

I also try to remove the line by write another line which color is as same as the background, but it doesnt work, it seems like the line cant be covered.

There is no need to remove and recreate the line, you can move the points at any time. Use the setVertex function on the LineSegs object to move the points.
It is in the reference here:!panda3d.core.LineSegs

That works, thanks!