Actors can be scaled, rotated, and moved.
Call actor.set_scale()
to increase or decrease the apparent size of the actor.
Note that this will not change the result of actor.get_width()
and
actor.get_height()
because it only changes the size of the actor as seen by the user.
Calling actor.set_scale()
again will replace the first scale rather than multiplying it.
Call actor.set_rotation()
to rotate the actor around an axis, specifying either
X_AXIS
, Y_AXIS
or Z_AXIS
and the desired angle. Only two of
the x, y, and z coordinates are used, depending on the specified axis. For instance, when using X_AXIS
, the y and z parameters specify the center of rotation on
the plane of the x axis.
Like the actor.set_scale()
, this does not affect the position, width, or height of the actor as
returned by functions such as actor.get_x()
.
Actors
may be "clipped" so that only one rectangular part of the actor is visible,
by calling actor.set_clip()
, providing a position relative to the actor, along with the size.
For instance, you might implement scrolling by creating a large container actor and setting a clip rectangle so that only
a small part of the whole is visible at any one time. Scrolling up could then be implemented by moving the actor down while
moving the clip up. Clipping can be reverted by calling actor.remove_clip()
.
The area outside of the clip does not consume video memory and generally does not require much processing.
PyClutter does not have a translation function that behaves similarly to
actor.set_scale()
and actor.set_rotation()
, but you can move the actor by
calling actor.move_by()
or actor.set_depth
.
Unlike the scaling and rotation functions, actor.move_by()
does change the result of
functions such as actor.get_x()
.
The following example demonstrates two unmoving actors in a stage, using rotation, scaling and movement:
File: main.py
import sys import clutter def main(): stage_color = clutter.Color(0, 0, 0, 255) actor_color = clutter.Color(255, 255, 255, 153) # Get the stage and set its size and color stage = clutter.Stage() stage.set_size(200, 200) stage.set_color(stage_color) # Add a rectangle to the stage rect = clutter.Rectangle(actor_color) rect.set_size(100, 100) rect.set_position(20, 20) stage.add(rect) rect.show() # Rotate it 20 degrees away from us around the x axis # (around its top edge) rect.set_rotation(clutter.X_AXIS, -20, 0, 0, 0) # Add a label to the stage label = clutter.Text("Sans 12", "Some Text", actor_color) label.set_size(500, 500) label.set_position(20, 150) stage.add(label) label.show() # Scale it 300% along the x axis label.set_scale(3., 1.) # Move it up and to the right label.move_by(10, -10) # Move it along the z axis, further from the viewer label.set_depth(-20) # Show the stage stage.connect("destroy", clutter.main_quit) stage.show_all() # Start the main loop, so we can respond to events clutter.main() return 0 if __name__ == '__main__': sys.exit(main())