Class: SFML::TransformableObject
- Inherits:
-
Object
- Object
- SFML::TransformableObject
- Includes:
- Graphics::Transformable
- Defined in:
- lib/sfml/graphics/transformable_object.rb
Overview
Standalone transformable — a pure CSFML transform container (no geometry attached). Useful as a base for custom drawables that combine a transform with their own rendering: parent the child’s vertices to this object’s ‘#transform` and you get position / rotation / scale / origin for free.
Most users want the ‘Graphics::Transformable` mixin instead — this standalone class exists for symmetry with the C++ API.
t = SFML::TransformableObject.new(position: [400, 300], rotation: 45)
t.transform #=> SFML::C::Graphics::Transform (use via RenderStates)
Constant Summary collapse
- CSFML_PREFIX =
:sfTransformable
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
- #dup ⇒ Object (also: #clone)
-
#initialize(**opts) ⇒ TransformableObject
constructor
A new instance of TransformableObject.
- #inverse_transform ⇒ Object
- #transform ⇒ Object
Methods included from Graphics::Transformable
#move, #origin, #origin=, #position, #position=, #rotate, #rotation, #rotation=, #scale, #scale=, #scale_by
Constructor Details
#initialize(**opts) ⇒ TransformableObject
Returns a new instance of TransformableObject.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sfml/graphics/transformable_object.rb', line 17 def initialize(**opts) ptr = C::Graphics.sfTransformable_create raise Error, "sfTransformable_create returned NULL" if ptr.null? @handle = FFI::AutoPointer.new(ptr, C::Graphics.method(:sfTransformable_destroy)) 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 |
Instance Attribute Details
#handle ⇒ Object (readonly)
:nodoc:
46 47 48 |
# File 'lib/sfml/graphics/transformable_object.rb', line 46 def handle @handle end |
Instance Method Details
#dup ⇒ Object Also known as: clone
36 37 38 39 40 41 42 43 |
# File 'lib/sfml/graphics/transformable_object.rb', line 36 def dup ptr = C::Graphics.sfTransformable_copy(@handle) raise Error, "sfTransformable_copy returned NULL" if ptr.null? copy = self.class.allocate copy.instance_variable_set(:@handle, FFI::AutoPointer.new(ptr, C::Graphics.method(:sfTransformable_destroy))) copy end |