Drawing
Drawing is handled by the Scar::Objects::Camera
class. Each spaces gets a camera by default. On each frame, a space invokes all its cameras' render_view
methods. It in return renders all Entities which have a component inheriting from Scar::Components::Drawable
(which is essentially a wrapper around SF::Drawable
) in the space and calls all systems' and objects' render
methods.
You can add multiple cameras to a scene to draw different views.
Drawables
SF::Components::Drawable
defines two things: a visible
and a sf
getter. visible
can be used to turn off rendering of this drawable. sf
should be a function to return some SF::Drawable
. This would be a SF::Sprite
, SF::Shape
or any other custom subclass of SF::Drawable
.
Drawables get drawn without further need of implementing drawing logic. Also an entities' position, scale and rotation are respected when drawing drawables.
Render methods
Systems and Objects contain a #render
method. If you want to write custom rendering code, you can do it there.
Drawing Order
Each space and entity has a z
attribute. You can set it at initialization or afterwards via the z attribute, though you have to call #reorder_spaces
or #reorder_entities
on your scene or space to actually update the drawing order.
The scene renders its spaces in increasing z order, and the cameras in the spaces then draw the entities in increasing z order. The systems' render
methods get called before the drawable drawing.
Modifying the camera
You can access a spaces' camera by the #camera
getter. You can then put the camera into 'advanced' mode by setting cam#simple
to false
. Now you can alter the SF::View
attached to the camera by simply using all the stuff from the SF::View
class (more information in the CrSFML documentation), as everything is delegated to it. It gets used for the whole drawing process of the camera.
Camera example
Last updated