class SFML::CircleShape
A filled circle (or regular polygon if you set point_count). Cheapest drawable that requires no asset file — perfect for placeholders.
ball = SFML::CircleShape.new( radius: 20, position: [400, 300], fill_color: SFML::Color.red, ) window.draw(ball)
Constants
- CSFML_PREFIX
Public Class Methods
Source
# File lib/sfml/graphics/circle_shape.rb, line 20 def initialize(radius: 10.0, **opts) ptr = C::Graphics.sfCircleShape_create raise GraphicsError, "sfCircleShape_create returned NULL" if ptr.null? @handle = FFI::AutoPointer.new(ptr, C::Graphics.method(:sfCircleShape_destroy)) self.radius = radius self.point_count = opts[:point_count] if opts[:point_count] self.fill_color = opts[:fill_color] if opts.key?(:fill_color) self.outline_color = opts[:outline_color] if opts.key?(:outline_color) self.outline_thickness = opts[:outline_thickness] if opts.key?(:outline_thickness) self.texture = opts[:texture] if opts.key?(:texture) self.texture_rect = opts[:texture_rect] if opts.key?(:texture_rect) self.position = opts[:position] if opts.key?(:position) self.origin = opts[:origin] if opts.key?(:origin) self.rotation = opts[:rotation] if opts.key?(:rotation) self.scale = opts[:scale] if opts.key?(:scale) end
Build a CircleShape. radius defaults to 10 px. Any of the standard styling / transform kwargs can be passed (fill_color, outline_color, outline_thickness, texture, texture_rect, position, origin, rotation, scale, point_count).
Public Instance Methods
Source
# File lib/sfml/graphics/circle_shape.rb, line 56 def fill_color = Color.from_native(C::Graphics.sfCircleShape_getFillColor(@handle)) # Set the fill color. def fill_color=(c) C::Graphics.sfCircleShape_setFillColor(@handle, c.to_native) end # Outline color (only visible when `#outline_thickness > 0`). def outline_color = Color.from_native(C::Graphics.sfCircleShape_getOutlineColor(@handle)) # Set the outline color. def outline_color=(c) C::Graphics.sfCircleShape_setOutlineColor(@handle, c.to_native) end # Outline thickness in pixels. Outline is drawn outward by default — # set negative for inward. def outline_thickness = C::Graphics.sfCircleShape_getOutlineThickness(@handle) # Set the outline thickness. def outline_thickness=(t) C::Graphics.sfCircleShape_setOutlineThickness(@handle, t.to_f) end # Returns the draw on. def draw_on(target, states_ptr = nil) # :nodoc: target._draw_native(:CircleShape, @handle, states_ptr) end attr_reader :handle # :nodoc: end
Interior fill color.
Source
# File lib/sfml/graphics/circle_shape.rb, line 59 def fill_color=(c) C::Graphics.sfCircleShape_setFillColor(@handle, c.to_native) end
Set the fill color.
Source
# File lib/sfml/graphics/circle_shape.rb, line 64 def outline_color = Color.from_native(C::Graphics.sfCircleShape_getOutlineColor(@handle)) # Set the outline color. def outline_color=(c) C::Graphics.sfCircleShape_setOutlineColor(@handle, c.to_native) end # Outline thickness in pixels. Outline is drawn outward by default — # set negative for inward. def outline_thickness = C::Graphics.sfCircleShape_getOutlineThickness(@handle) # Set the outline thickness. def outline_thickness=(t) C::Graphics.sfCircleShape_setOutlineThickness(@handle, t.to_f) end # Returns the draw on. def draw_on(target, states_ptr = nil) # :nodoc: target._draw_native(:CircleShape, @handle, states_ptr) end attr_reader :handle # :nodoc: end end
Outline color (only visible when #outline_thickness > 0).
Source
# File lib/sfml/graphics/circle_shape.rb, line 67 def outline_color=(c) C::Graphics.sfCircleShape_setOutlineColor(@handle, c.to_native) end
Set the outline color.
Source
# File lib/sfml/graphics/circle_shape.rb, line 73 def outline_thickness = C::Graphics.sfCircleShape_getOutlineThickness(@handle) # Set the outline thickness. def outline_thickness=(t) C::Graphics.sfCircleShape_setOutlineThickness(@handle, t.to_f) end # Returns the draw on. def draw_on(target, states_ptr = nil) # :nodoc: target._draw_native(:CircleShape, @handle, states_ptr) end attr_reader :handle # :nodoc: end
Outline thickness in pixels. Outline is drawn outward by default —set negative for inward.
Source
# File lib/sfml/graphics/circle_shape.rb, line 76 def outline_thickness=(t) C::Graphics.sfCircleShape_setOutlineThickness(@handle, t.to_f) end
Set the outline thickness.
Source
# File lib/sfml/graphics/circle_shape.rb, line 48 def point_count = C::Graphics.sfCircleShape_getPointCount(@handle) # Set the point count — see `#point_count`. def point_count=(n) C::Graphics.sfCircleShape_setPointCount(@handle, Integer(n)) end # Interior fill color. def fill_color = Color.from_native(C::Graphics.sfCircleShape_getFillColor(@handle)) # Set the fill color. def fill_color=(c) C::Graphics.sfCircleShape_setFillColor(@handle, c.to_native) end # Outline color (only visible when `#outline_thickness > 0`). def outline_color = Color.from_native(C::Graphics.sfCircleShape_getOutlineColor(@handle)) # Set the outline color. def outline_color=(c) C::Graphics.sfCircleShape_setOutlineColor(@handle, c.to_native) end # Outline thickness in pixels. Outline is drawn outward by default — # set negative for inward. def outline_thickness = C::Graphics.sfCircleShape_getOutlineThickness(@handle) # Set the outline thickness. def outline_thickness=(t) C::Graphics.sfCircleShape_setOutlineThickness(@handle, t.to_f) end # Returns the draw on. def draw_on(target, states_ptr = nil) # :nodoc: target._draw_native(:CircleShape, @handle, states_ptr) end attr_reader :handle # :nodoc:
Number of points used to approximate the circle. Default 30 (smooth); set to 3-8 for a regular polygon (triangle, square, …).
Source
# File lib/sfml/graphics/circle_shape.rb, line 51 def point_count=(n) C::Graphics.sfCircleShape_setPointCount(@handle, Integer(n)) end
Set the point count — see point_count.
Source
# File lib/sfml/graphics/circle_shape.rb, line 39 def radius = C::Graphics.sfCircleShape_getRadius(@handle) # Set the radius. def radius=(value) C::Graphics.sfCircleShape_setRadius(@handle, value.to_f) end # Number of points used to approximate the circle. Default 30 # (smooth); set to 3-8 for a regular polygon (triangle, square, ...). def point_count = C::Graphics.sfCircleShape_getPointCount(@handle) # Set the point count — see `#point_count`. def point_count=(n) C::Graphics.sfCircleShape_setPointCount(@handle, Integer(n)) end # Interior fill color. def fill_color = Color.from_native(C::Graphics.sfCircleShape_getFillColor(@handle)) # Set the fill color. def fill_color=(c) C::Graphics.sfCircleShape_setFillColor(@handle, c.to_native) end # Outline color (only visible when `#outline_thickness > 0`). def outline_color = Color.from_native(C::Graphics.sfCircleShape_getOutlineColor(@handle)) # Set the outline color. def outline_color=(c) C::Graphics.sfCircleShape_setOutlineColor(@handle, c.to_native) end # Outline thickness in pixels. Outline is drawn outward by default — # set negative for inward. def outline_thickness = C::Graphics.sfCircleShape_getOutlineThickness(@handle) # Set the outline thickness. def outline_thickness=(t) C::Graphics.sfCircleShape_setOutlineThickness(@handle, t.to_f) end # Returns the draw on. def draw_on(target, states_ptr = nil) # :nodoc: target._draw_native(:CircleShape, @handle, states_ptr) end attr_reader :handle
Radius in pixels.
Source
# File lib/sfml/graphics/circle_shape.rb, line 42 def radius=(value) C::Graphics.sfCircleShape_setRadius(@handle, value.to_f) end
Set the radius.