class SF::ConvexShape
- SF::ConvexShape
- SF::Shape
- SF::Transformable
- Reference
- Object
Overview
Specialized shape representing a convex polygon
This class inherits all the functions of SF::Transformable
(position, rotation, scale, bounds, ...) as well as the
functions of SF::Shape (outline, color, texture, ...).
It is important to keep in mind that a convex shape must always be... convex, otherwise it may not be drawn correctly. Moreover, the points must be defined in order; using a random order would result in an incorrect shape.
Usage example:
polygon = SF::ConvexShape.new
polygon.point_count = 3
polygon[0] = SF.vector2f(0, 0)
polygon[1] = SF.vector2f(0, 10)
polygon[2] = SF.vector2f(25, 5)
polygon.outline_color = SF::Color::Red
polygon.outline_thickness = 5
polygon.position = {10, 20}
...
window.draw polygonSee also: SF::Shape, SF::RectangleShape, SF::CircleShape
Defined in:
graphics/graphics.crgraphics/obj.cr
Constructors
- 
        .new(point_count : Int = 0)
        
          Default constructor 
Instance Method Summary
- 
        #[](index)
        
          Shorthand for #get_point
- 
        #[]=(index, point)
        
          Shorthand for #set_point
- 
        #dup : ConvexShape
        
          Returns a shallow copy of this object. 
- 
        #finalize
        
          Virtual destructor 
- 
        #get_point(index : Int) : Vector2f
        
          Get the position of a point 
- 
        #point_count : Int32
        
          Get the number of points of the polygon 
- 
        #point_count=(count : Int)
        
          Set the number of points of the polygon 
- 
        #set_point(index : Int, point : Vector2 | Tuple)
        
          Set the position of a point 
Instance methods inherited from class SF::Shape
  
  
    
      fill_color : Color
    fill_color, 
    
  
    
      fill_color=(color : Color)
    fill_color=, 
    
  
    
      finalize
    finalize, 
    
  
    
      get_point(index : Int) : Vector2f
    get_point, 
    
  
    
      global_bounds : FloatRect
    global_bounds, 
    
  
    
      local_bounds : FloatRect
    local_bounds, 
    
  
    
      outline_color : Color
    outline_color, 
    
  
    
      outline_color=(color : Color)
    outline_color=, 
    
  
    
      outline_thickness : Float32
    outline_thickness, 
    
  
    
      outline_thickness=(thickness : Number)
    outline_thickness=, 
    
  
    
      point_count : Int32
    point_count, 
    
  
    
      set_texture(texture : Texture | Nil, reset_rect : Bool = false)
    set_texture, 
    
  
    
      texture=(texture : Texture)
    texture=, 
    
  
    
      texture_rect : IntRect
    texture_rect, 
    
  
    
      texture_rect=(rect : IntRect)
    texture_rect=, 
    
  
    
      update
    update
    
  
    
    
  
    
  Instance methods inherited from module SF::Drawable
  
  
    
      draw(target : RenderTarget, states : RenderStates)
    draw
    
  
    
    
  
    
  Instance methods inherited from class SF::Transformable
  
  
    
      dup : Transformable
    dup, 
    
  
    
      finalize
    finalize, 
    
  
    
      inverse_transform : Transform
    inverse_transform, 
    
  
    
      move(offset_x : Number, offset_y : Number)move(offset : Vector2 | Tuple) move, origin : Vector2f origin, origin=(origin : Vector2 | Tuple) origin=, position : Vector2f position, position=(position : Vector2 | Tuple) position=, rotate(angle : Number) rotate, rotation : Float32 rotation, rotation=(angle : Number) rotation=, scale(factor_x : Number, factor_y : Number)
scale(factor : Vector2 | Tuple)
scale : Vector2f scale, scale=(factors : Vector2 | Tuple) scale=, set_origin(x : Number, y : Number) set_origin, set_position(x : Number, y : Number) set_position, set_scale(factor_x : Number, factor_y : Number) set_scale, transform : Transform transform
Constructor methods inherited from class SF::Transformable
  
  
    
      new
    new
    
  
    
  
    
    
    
  
    
    
    
  
Constructor Detail
Default constructor
- point_count - Number of points of the polygon
Instance Method Detail
Returns a shallow copy of this object.
This allocates a new object and copies the contents of
self into it.
Get the position of a point
The returned point is in local coordinates, that is, the shape's transforms (position, rotation, scale) are not taken into account. The result is undefined if index is out of the valid range.
- index - Index of the point to get, in range 0 ... point_count
Returns: Position of the index-th point of the polygon
See also: point=
Get the number of points of the polygon
Returns: Number of points of the polygon
See also: #point_count=
Set the number of points of the polygon
count must be greater than 2 to define a valid shape.
- count - New number of points of the polygon
See also: #point_count
Set the position of a point
Don't forget that the polygon must remain convex, and the points need to stay ordered! point_count= must be called first in order to set the total number of points. The result is undefined if index is out of the valid range.
- index - Index of the point to change, in range 0 ... point_count
- point - New position of the point
See also: point