Created
August 23, 2013 01:58
-
-
Save febret/6314793 to your computer and use it in GitHub Desktop.
Actor picking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Question:
I would keep the actors in a python dictionary, giving each actor the same name as the sceneNode they control (see code)