Actor classes

Frequently used methods

sphof.Actor(*args, **kwargs) An Actor class runs inside its own thread.
sphof.Actor.setup() Called a startup.
sphof.Actor.update() Called every loop
sphof.Actor.draw() Called after update
sphof.LeadActor.add_actor(actor) Add an Actor and run its threaded loop
sphof.LeadActor.run() Run the actor’s application loop
sphof.LeadActor.stop() Stop this LeadActor.

Actor class

class Actor(*args, **kwargs)

An Actor class runs inside its own thread. It’s usually started by a LeadActor!

Parameters:name (str) – Name of the node, if not given a random name will be created

By default the Actor loop runs at 60 iterations per second. This means your update and draw method is called every 1/60th second.

Warning

It is important to understand that an actor runs in a thread. Usually a thread is started by a ‘main’ thread. A sphof.LeadActor provides methods for starting and stopping Actors as the LeadActor runs in the main thread. An Actor has limitations. For example you cannot visualize directly from an Actor. To visualize what an actor draws you’ll need to handover the image to a LeadActor.

setup()

Called a startup.

Add variables you want to use througout the actor here. I.e.:

self.count = 0

and in the update() method:

self.count += 1
update()

Called every loop

draw()

Called after update

LeadActor class

class LeadActor(*args, **kwargs)

Bases: sphof.actors.Actor

A LeadActor class runs in the main thread. It inherits all methods from the Actor class but has some additional methods to start Actors

Parameters:name (str) – Name of the node, if not given a random name will be created

By default the LeadActor loop runs at 60 iterations per second. This means your update and draw method is called every 1/60th second.

stop()

Stop this LeadActor. Before stopping all Actors started from this LeadActor are stopped first

add_actor(actor)

Add an Actor and run its threaded loop

Parameters:actor (Actor) – An Actor to start in its own thread
draw()

Called after update

remove_actor(actor)

Remove and stop an Actor

Parameters:actor (Actor) – An Actor to remove and stop
run()

Run the actor’s application loop

setup()

Called a startup.

Add variables you want to use througout the actor here. I.e.:

self.count = 0

and in the update() method:

self.count += 1
update()

Called every loop

LoneActor class

class LoneActor(name, *args, **kwargs)

The LoneActor class runs an application loop.

Parameters:name (str) – Name of the node, if not given a random name will be created

By default the LoneActor loop runs at 60 iterations per second. This means your update and draw method is called every 1/60th second.

setup()

Called a startup.

Add variables you want to use througout the actor here. I.e.:

self.count = 0

and in the update() method:

self.count += 1
update()

Called every loop

draw()

Called after update