How would I go about adding a clicking event handler on a Actor?
Do you mean, how do you respond if the user clicks on your actor onscreen? Try taking a look at the “Chessboard” sample, which demonstrates using picking to select pieces of a chessboard.
Found out that accept() only works on actors and not loader.LoadModel()
accept() works on anything that inherits from DirectObject, which includes Actor, but not NodePath. Usually you would make your world object inherit from DirectObject, and use “self.accept()”. If you don’t want to do that for whatever reason, you can always use “base.accept()”, as the base instance inherits from DirectObject.
In the chess piece demo it uses a cheap but effective highlighting trick, combined to with an array of all the pieces in order to select what piece is being moved. How would I know what was being clicked, because with Actor1.accept(“mouse1”,handleClick) It’s reacting everywhere I click.
Right, so you do want to do picking? I’d thought when you started talking about accept() you were just wanting to handle a generic click event, because that’s all that accept() does.
In order to detect click on a specific object, you have to use the collision system and make that object collidable (at least to the CollisionRay you use to detect it). The chessboard demo does exactly this, with the board squares. It could just as easily have done it with the chess pieces instead.
In order to make your actor pickable, you have to do this same thing with your actor. This means either enable collide-with-geom on the actor (expensive!) or put a cheaper collision solid around the actor, for instance a tube.