module SFML::Graphics::Transformable
Shared transform interface for Sprite, CircleShape, RectangleShape (and Text once added). Including class must: 1. Define a constant CSFML_PREFIX (Symbol), e.g. :sfCircleShape 2. Hold the FFI handle in @handle
All wrappers go through C::Graphics.public_send so the same Ruby code picks up sfSprite, sfCircleShape_, sfRectangleShape* etc. without repetition. The cost (~1Β΅s of method dispatch on a typical call) is negligible against any GPU work, but the wins on maintainability are large β adding a new shape becomes ~5 lines.
Public Instance Methods
Source
# File lib/sfml/graphics/transformable.rb, line 56 def move(offset) _csfml(:move, @handle, _coerce_vec2(offset).to_native_f) self end
Translate by offset (relative move). Chainable β returns self.
Source
# File lib/sfml/graphics/transformable.rb, line 46 def origin Vector2.from_native(_csfml(:getOrigin, @handle)) end
The local origin (pivot for rotation/scale). Default is [0, 0]β set it to the centre of the bounding box for βrotate in placeβ.
Source
# File lib/sfml/graphics/transformable.rb, line 51 def origin=(value) _csfml(:setOrigin, @handle, _coerce_vec2(value).to_native_f) end
Set the origin β accepts Vector2 or [x, y] Array.
Source
# File lib/sfml/graphics/transformable.rb, line 15 def position Vector2.from_native(_csfml(:getPosition, @handle)) end
Current 2D position as a Vector2.
Source
# File lib/sfml/graphics/transformable.rb, line 20 def position=(value) _csfml(:setPosition, @handle, _coerce_vec2(value).to_native_f) end
Move to absolute [x, y] β accepts Vector2 or [x, y] Array.
Source
# File lib/sfml/graphics/transformable.rb, line 62 def rotate(degrees) _csfml(:rotate, @handle, degrees.to_f) self end
Rotate by degrees (relative). Chainable.
Source
# File lib/sfml/graphics/transformable.rb, line 25 def rotation _csfml(:getRotation, @handle) end
Current rotation in degrees (counter-clockwise positive).
Source
# File lib/sfml/graphics/transformable.rb, line 30 def rotation=(degrees) _csfml(:setRotation, @handle, degrees.to_f) end
Set absolute rotation in degrees.
Source
# File lib/sfml/graphics/transformable.rb, line 35 def scale Vector2.from_native(_csfml(:getScale, @handle)) end
Current scale factors as a Vector2 ([1, 1] means original size).
Source
# File lib/sfml/graphics/transformable.rb, line 40 def scale=(value) _csfml(:setScale, @handle, _coerce_vec2(value).to_native_f) end
Set the scale β accepts Vector2 or [sx, sy] Array.
Source
# File lib/sfml/graphics/transformable.rb, line 68 def scale_by(factors) _csfml(:scale, @handle, _coerce_vec2(factors).to_native_f) self end
Multiply current scale by factors (relative scale). Chainable.