class SFML::App

Subclass-friendly main loop. Removes the boilerplate of window creation, event pumping, clock management, and clear/display so a small app fits in a few methods.

class MyApp < SFML::App antialiasing 4 # class-level config β€” applies to every instance framerate 120 background SFML::Color.new(18, 20, 28)

def setup
  @ball = SFML::CircleShape.new(radius: 30, position: [200, 200],
                                fill_color: SFML::Color.white)
end

def update(dt)
  @ball.move([60 * dt.as_seconds, 30 * dt.as_seconds])
end

def draw
  window.draw(@ball)
end

end

MyApp.new(title: β€œHello”).run

The loop auto-handles :closed and :key_pressed/:escape by calling

quit; everything else is forwarded to on_event. Override that to handle keys, mouse, etc.

Configuration

Every constructor kwarg is also a class-level macro: declare defaults with antialiasing 4 etc. inside the class body, and MyApp.new picks them up. Per-instance kwargs still win on a case-by-case basis. Subclasses inherit their parent’s settingsβ€” set one in a base class, override in a subclass.