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):
LineSegs.__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
self.setColor(*color)
self.setThickness(thickness)
self.moveTo(startPoint)
self.drawTo(endPoint)
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)
np.reparentTo(render)
#np.detachNode()
return task.cont
app = MyApp()
d = app.Draw()
taskMgr.add(d.gameloop,"gameloop")
run()
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!