Skip to content

Instantly share code, notes, and snippets.

@febret
Created August 23, 2013 01:58
Show Gist options
  • Save febret/6314793 to your computer and use it in GitHub Desktop.
Save febret/6314793 to your computer and use it in GitHub Desktop.
Actor picking
# Actor dictionary
actors = {}
# create a custom actor class
class Pickable(Actor):
node = None
def __init__(self):
# create something
node = SphereNode.create(1,2)
node.setSelectable(True)
# NOTE: each node has a unique name by default. if you want you
# can re-name the node before this line doung node.setName('blahblah')
actors[node.getName()] = self
def picked():
print("Can't touch this!")
#[...]
def onObjectSelected(node, distance):
if(node != None and node.getName() in actors):
actors[node.getName()].picked()
def onEvent():
e = getEvent()
# When the confirm button is pressed:
if(e.isButtonDown(Event.Button5)):
r = getRayFromEvent(e)
if(r[0]): querySceneRay(r[1], r[2], onObjectSelected)
setEventFunction(onEvent)
@febret
Copy link
Author

febret commented Dec 29, 2014

Question:

what is a good way to refer back to an Actor given a picked object?
Lets say I write an Actor that encapsulates a finite state machine and it controls a scenenode- like moves it around the scene. Now lets say I pick that scenenode and decide I want to move it somewhere. It would be nice if I can alert the Actor that it's being picked and act accordingly.

I would keep the actors in a python dictionary, giving each actor the same name as the sceneNode they control (see code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment