Class: SFML::Sprite
- Inherits:
-
Object
- Object
- SFML::Sprite
- Defined in:
- ext/graphics/sprite.c,
ext/graphics/sprite.c
Overview
A drawable representation of a Texture (or a sub-rectangle of one), positioned, rotated, scaled and tinted like any other Transformable object.
Includes Drawable.
Instance Attribute Summary collapse
-
#color ⇒ Color
Returns the object's color.
-
#origin ⇒ Vector2
Returns the object's origin.
-
#position ⇒ Vector2
Returns the object's position.
-
#rotation ⇒ Float
Returns the object's rotation, in degrees.
-
#scale ⇒ Vector2
Returns the object's scale factors.
-
#texture ⇒ Texture?
Returns the object's texture, or
nilif it has none. -
#texture_rect ⇒ Rect
Returns the sub-rectangle of the texture displayed on the object.
Instance Method Summary collapse
-
#copy ⇒ Sprite
Returns a deep copy of the object.
-
#draw(target, state) ⇒ nil
Part of the Drawable interface; call Target#draw instead of this directly.
-
#global_bounds ⇒ Rect
Returns the bounding box after the transform is applied.
-
#new(texture) ⇒ Sprite
constructor
CSFML requires a texture at creation time -- its C API unconditionally dereferences a NULL texture argument rather than tolerating one, so unlike most other constructors here, the texture is not optional.
-
#inverse_transform ⇒ Array<Float>
Returns the 3x3 row-major inverse of the object's transform matrix.
-
#local_bounds ⇒ Rect
Returns the bounding box in local (untransformed) coordinates.
-
#transform ⇒ Array<Float>
Returns the object's 3x3 row-major transform matrix.
-
#move(offset) ⇒ self
Moves the object by
offset. -
#rotate(angle) ⇒ self
Rotates the object by
angledegrees. -
#scale!(factors) ⇒ self
Scales the object by
factorsrelative to its current scale. -
#transform ⇒ Array<Float>
Returns the object's 3x3 row-major transform matrix.
Constructor Details
#new(texture) ⇒ Sprite
CSFML requires a texture at creation time -- its C API unconditionally dereferences a NULL texture argument rather than tolerating one, so unlike most other constructors here, the texture is not optional.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'ext/graphics/sprite.c', line 93
static VALUE Sprite_initialize(VALUE self, VALUE rb_texture) {
Sprite* ptr;
if (!rb_obj_is_kind_of(rb_texture, Get_Klass_Texture())) {
raise_invalid_argument_class(Get_Klass_Texture());
}
TypedData_Get_Struct(self, Sprite, &Sprite_data_type, ptr);
ptr->sprite = sfSprite_create(Get_Texture_Struct(rb_texture));
ptr->rb_texture = rb_texture;
if (ptr->sprite == NULL) {
rb_raise(rb_eRuntimeError, "failed to create sprite");
}
return self;
}
|
Instance Attribute Details
#color ⇒ Color
Returns the object's color.
394 395 396 |
# File 'ext/graphics/sprite.c', line 394 static VALUE Sprite_get_color(VALUE self) { return color_to_rb(sfSprite_getColor(Get_Sprite_Struct(self))); } |
#origin ⇒ Vector2
Returns the object's origin.
394 395 396 |
# File 'ext/graphics/sprite.c', line 394 static VALUE Sprite_get_origin(VALUE self) { return vec2f_to_rb(sfSprite_getOrigin(Get_Sprite_Struct(self))); } |
#position ⇒ Vector2
Returns the object's position.
394 395 396 |
# File 'ext/graphics/sprite.c', line 394 static VALUE Sprite_get_position(VALUE self) { return vec2f_to_rb(sfSprite_getPosition(Get_Sprite_Struct(self))); } |
#rotation ⇒ Float
Returns the object's rotation, in degrees.
394 395 396 |
# File 'ext/graphics/sprite.c', line 394 static VALUE Sprite_get_rotation(VALUE self) { return DBL2NUM(sfSprite_getRotation(Get_Sprite_Struct(self))); } |
#scale ⇒ Vector2
Returns the object's scale factors.
394 395 396 |
# File 'ext/graphics/sprite.c', line 394 static VALUE Sprite_get_scale(VALUE self) { return vec2f_to_rb(sfSprite_getScale(Get_Sprite_Struct(self))); } |
#texture ⇒ Texture?
Returns the object's texture, or nil if it has none.
394 395 396 |
# File 'ext/graphics/sprite.c', line 394
static VALUE Sprite_get_texture(VALUE self) {
return Get_Sprite(self)->rb_texture;
}
|
#texture_rect ⇒ Rect
Returns the sub-rectangle of the texture displayed on the object.
394 395 396 |
# File 'ext/graphics/sprite.c', line 394 static VALUE Sprite_get_texture_rect(VALUE self) { return int_rect_to_rb(sfSprite_getTextureRect(Get_Sprite_Struct(self))); } |
Instance Method Details
#copy ⇒ Sprite
Returns a deep copy of the object.
118 119 120 121 122 |
# File 'ext/graphics/sprite.c', line 118
static VALUE Sprite_copy(VALUE self) {
Sprite* ptr = Get_Sprite(self);
return Sprite_wrap(Get_Klass_Sprite(), sfSprite_copy(ptr->sprite));
}
|
#draw(target, state) ⇒ nil
Part of the Drawable interface; call Target#draw instead of this directly.
381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'ext/graphics/sprite.c', line 381
static VALUE Sprite_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
TargetView view = Get_RenderTarget_View(rb_target);
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
raise_invalid_argument_class(Get_Klass_RenderState());
}
TARGET_DRAW(view, sfRenderWindow_drawSprite, sfRenderTexture_drawSprite,
Get_Sprite_Struct(self), Get_RenderState_Struct(rb_state));
return Qnil;
}
|
#global_bounds ⇒ Rect
Returns the bounding box after the transform is applied.
367 368 369 |
# File 'ext/graphics/sprite.c', line 367 static VALUE Sprite_get_global_bounds(VALUE self) { return rect_to_rb(sfSprite_getGlobalBounds(Get_Sprite_Struct(self))); } |
#inverse_transform ⇒ Array<Float>
Returns the 3x3 row-major inverse of the object's transform matrix.
345 346 347 |
# File 'ext/graphics/sprite.c', line 345 static VALUE Sprite_get_inverse_transform(VALUE self) { return Transform_MatrixToArray(sfSprite_getInverseTransform(Get_Sprite_Struct(self)).matrix); } |
#local_bounds ⇒ Rect
Returns the bounding box in local (untransformed) coordinates.
356 357 358 |
# File 'ext/graphics/sprite.c', line 356 static VALUE Sprite_get_local_bounds(VALUE self) { return rect_to_rb(sfSprite_getLocalBounds(Get_Sprite_Struct(self))); } |
#transform ⇒ Array<Float>
Returns the object's 3x3 row-major transform matrix.
335 336 337 |
# File 'ext/graphics/sprite.c', line 335 static VALUE Sprite_get_transform(VALUE self) { return Transform_MatrixToArray(sfSprite_getTransform(Get_Sprite_Struct(self)).matrix); } |
#move(offset) ⇒ self
Moves the object by offset.
300 301 302 303 |
# File 'ext/graphics/sprite.c', line 300
static VALUE Sprite_move(VALUE self, VALUE rb_offset) {
sfSprite_move(Get_Sprite_Struct(self), vec2f_from_rb(rb_offset));
return self;
}
|
#rotate(angle) ⇒ self
Rotates the object by angle degrees.
312 313 314 315 |
# File 'ext/graphics/sprite.c', line 312
static VALUE Sprite_rotate(VALUE self, VALUE rb_angle) {
sfSprite_rotate(Get_Sprite_Struct(self), NUM2DBL(rb_angle));
return self;
}
|
#scale!(factors) ⇒ self
Scales the object by factors relative to its current scale.
324 325 326 327 |
# File 'ext/graphics/sprite.c', line 324
static VALUE Sprite_scale(VALUE self, VALUE rb_factors) {
sfSprite_scale(Get_Sprite_Struct(self), vec2f_from_rb(rb_factors));
return self;
}
|
#transform ⇒ Array<Float>
Returns the object's 3x3 row-major transform matrix.
335 336 337 |
# File 'ext/graphics/sprite.c', line 335 static VALUE Sprite_get_transform(VALUE self) { return Transform_MatrixToArray(sfSprite_getTransform(Get_Sprite_Struct(self)).matrix); } |