class SFML::Shape

Abstract callback-driven shape β€” for when neither CircleShape, RectangleShape, nor ConvexShape fits. Subclass and override point_count (returns Integer) and point(i) (returns a Vector2 or [x, y]). CSFML asks Ruby every frame for the point list, so you can drive geometry from live data.

class Pentagon < SFML::Shape def point_count = 5 def point(i) angle = i * 2 * Math::PI / 5 - Math::PI / 2 [Math.cos(angle) * 50, Math.sin(angle) * 50] end end

pent = Pentagon.new(fill_color: SFML::Color.red, position: [400, 300]) window.draw(pent)

When your underlying geometry changes (e.g. the data feeding point updates), call update to invalidate the cached outline / bounds β€” otherwise the next draw will still use the previously sampled points.

CAVEATS * Callbacks run on whichever thread invokes the draw. With single-threaded rendering (the SFML default) this is fine; if you’re driving the renderer from a different thread, make sure point_count / point are thread-safe. * Keep a Ruby reference to the Shape β€” if it’s GC’d while CSFML still holds the function pointers, the next draw crashes.