scar
  • The scar game library
  • Application Structure
    • App
    • Scenes
    • Spaces
    • Entities
    • Components
    • Systems
    • Objects
    • Drawing
    • Events
  • Builtin Features
    • Actions
    • Assets
    • Config
    • Input
    • Logger
    • Music
    • Tweens
    • Util
    • Vectors & Rects
  • Builtin Components
    • Text
    • Sprite
    • Animated Sprite
  • Builtin Systems
    • Animate Sprites
Powered by GitBook
On this page
  • Drawables
  • Render methods
  • Drawing Order
  • Modifying the camera
  • Camera example

Was this helpful?

  1. Application Structure

Drawing

PreviousObjectsNextEvents

Last updated 5 years ago

Was this helpful?

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 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 and 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 ), as everything is delegated to it. It gets used for the whole drawing process of the camera.

Camera example

cam = scene["background"].camera
cam.simple = false
cam.reset(Rectf.new(50, 50, 400, 400))
cam.rotate(10)
cam.viewport = Rectf.new(0.1, 0.1, 0.6, 0.6)

Entities
space
entity
CrSFML documentation