Hi,
I want to do something like this http://www.youtube.com/watch?v=3QzKkHi-0xo&feature=related, when i click play an animation (red arrows in this vid).
I frist did this:
from pandac.PandaModules import NodePath
from direct.actor.Actor import Actor
class Pointer:
'''The Marker'''
def __init__(self, render):
# You probably want to use a different marker model
self.render = render
# Create a NP to hold the last clicked pos (maybe we'll need this later)
self.PointerNP = NodePath('Pointer NP')
self.PointerNP.reparentTo(self.render)
self.model = 'ralph' #using ralphs model as placeholder
# Create a list to hold the pointers
self.pointerList = []
def getPos(self):
return self.PointerNP.getPos()
def point(self, pos): # this function is called when there is a click
self.PointerNP.setPos(pos) # save the last pos in case of needing it
a = Actor('models/{0}'.format(self.model),
{'run':'models/{0}-run'.format(self.model),
'walk':'models/{0}-walk'.format(self.model),
})
a.loop('run')
a.reparentTo(self.render)
a.setScale(0.5)
a.setPos(pos)
self.pointerList.append(a)
taskMgr.doMethodLater(5, self.fadeTask, 'fadeTask') # 5 secs only to test, its going to be less than .5
def fadeTask(self,task):
if self.pointerList:
print ('Deleting: ' + str(self.pointerList[0]))
self.pointerList[0].detachNode() #use detachNode() or removeNode()?
self.pointerList.pop(0)
return task.done
then I found this page http://www.panda3d.org/manual/index.php/Instancing and changed my code to:
from pandac.PandaModules import NodePath
from direct.actor.Actor import Actor
class Pointer:
'''The Marker'''
def __init__(self, render,loader):
# You probably want to use a different marker model
self.render = render
# Create a NP to hold the last clicked pos (maybe we'll need this later)
self.PointerNP = NodePath('Pointer NP')
self.PointerNP.reparentTo(self.render)
self.model = 'ralph'
self.Pointer = Actor('models/{0}'.format(self.model),
{'run':'models/{0}-run'.format(self.model),
'walk':'models/{0}-walk'.format(self.model),
})
self.Pointer.loop('run') # they are all animated at the same time.
# Create a list to hold the pointers
self.pointerList = []
def getPos(self):
return self.PointerNP.getPos()
def point(self, pos):
self.PointerNP.setPos(pos) # save the last pos in case of needing it
a = self.render.attachNewNode("Placeholder")
a.setPos(pos)
self.Pointer.instanceTo(a)
#self.Pointer.loop('run') #if uncoment the animation is restarted when i click
self.pointerList.append(a)
taskMgr.doMethodLater(5, self.fadeTask, 'fadeTask') # 5 secs only to test, its going to be less than .5
def fadeTask(self,task):
if self.pointerList:
print ('Deleting: ' + str(self.pointerList[0]))
self.pointerList[0].detachNode() #use detachNode() or removeNode()?
self.pointerList.pop(0)
return task.done
With the first code all the animations are independent, but it is a little expensive if I click alot (I know that every actor will be deleted in less than 1s but isn’t expensive to load the actor every click? and i’m concerned if its going to be a problem when i get lots of things in the scene).
So, is there anyway to improve this code?
And another thing, should I use detachNode() or removeNode()?
Thx