Ignifuga has built in functionality to support remote access to the running engine using:
To use RFoo, start the demo with:
Install RFoo (Using easy_install, pip, etc) and run:
You'll enter an interpreter much like the standard Python interpreter, but this one runs inside the engine. It comes pre seeded with a few useful variables (unless you specified --staticglobals on the command line), to view them type:
Some of these variables are persistent across scenes (pQuery, Gilbert, DataManager, Renderer, DONE, ERROR, etc), and others reflect entities present in the scene, which are created with a variable name that matches their id (if the id is defined).
title Entity with ID: title (2028089)
Let's now try changing the scene
for x in range(0,689, 3): title.x = x SKIP()
When you hit Enter, you'll see the main title jump to the x coordinate 0 and slowly move to the center jumping 3 pixels at a time. The SKIP() function is important here as Ignifuga's entities and the remote console run in a single cooperative thread, so basically what you are doing is releasing control so the rest of the engine can keep updating. Once the engine finishes updating, thanks to the magic of Greenlets, execution resumes on that same spot.
You can combine this technique with pQuery, to modify more than one entity at the same time.
for red in range(0,255): _('*').red = red / 255.0 SKIP()
What you'll see now is that the red component of all sprites goes to zero (blacks out) and slowly comes back. Pretty neat for 3 lines of code, right? Besides this sort of rudimentary animation method pQuery supports a full fledged "animate" method and it behaves mostly like jQuery, so that's a good place to figure out what each selector does.
pQuery also works on LibRocket elements, the selection is done depending on the context provided (the second parameter provided to pQuery, which by default is the current Scene, except for Python code ran from inside a libRocket document, in which case the default context is the current document)
# Select all entities in the Scene _('*') # Select all components in an entity _('*', title) # Select all elements in a Rocket document # The "gui" variable is also pre seeded, but in case you want to select the component manually: gui = _('#gui') _('*', gui.document) # While not technically correct, this also works, yay for syntactic sugar! _('*', gui) # Rocket document objects have a pre seeded pQuery object with the default context set to the document # So, this also selects all the elements in the document gui.pQuery('*')
Now let's try changing the menu colors:
gui = _('#gui') _('#loadBtn', gui.document).css('color', '#FF00FF')
You'll notice that the load button is now colored with an ugly violet.
gui = _('#gui') gui.pQuery('#loadBtn').css('color', '#00FF00') gui.pQuery('#loadBtn').html('reload!')
Now the load button is green and the text has changed. You can also experiment with Actions, like this:
from ignifuga.components.Action import Action Action(entity=gui, targets=['#loadBtn',], color='#00ff00', duration=5.0, relative=False, easing='outelastic').init()
For more tips and tricks on Actions, animations, pQuery, etc, see Using pQuery