Module: Chingu::Traits::BoundingBox
- Defined in:
- lib/chingu/traits/bounding_box.rb
Overview
Providing a bounding_box-method which generates a AABB on the fly from: x, y, factor_x, factor_y and rotation_center
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#bounding_box ⇒ Object
(also: #bb)
Returns an instance of class Rect.
- #cache_bounding_box ⇒ Object
-
#draw_trait ⇒ Object
def update_trait cache_bounding_box if trait_options[:cache] && !@cached_bounding_box super end.
- #setup_trait(options) ⇒ Object
Instance Method Details
#bounding_box ⇒ Object Also known as: bb
Returns an instance of class Rect
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/chingu/traits/bounding_box.rb', line 44 def bounding_box if @cached_bounding_box @cached_bounding_box.x = self.x + @_x_diff @cached_bounding_box.y = self.y + @_y_diff return @cached_bounding_box end width = self.image.width * self.factor_x.abs height = self.image.height * self.factor_y.abs if [:bounding_box][:scale] width = width * [:bounding_box][:scale] height = height * [:bounding_box][:scale] end x = self.x - (width * self.center_x.abs) y = self.y - (height * self.center_y.abs) return Rect.new(x, y, width, height) end |
#cache_bounding_box ⇒ Object
67 68 69 70 71 72 |
# File 'lib/chingu/traits/bounding_box.rb', line 67 def cache_bounding_box @cached_bounding_box = nil @cached_bounding_box = self.bounding_box @_x_diff = @cached_bounding_box.x - self.x @_y_diff = @cached_bounding_box.y - self.y end |
#draw_trait ⇒ Object
def update_trait
cache_bounding_box if [:bounding_box][:cache] && !@cached_bounding_box
super
end
79 80 81 82 83 84 |
# File 'lib/chingu/traits/bounding_box.rb', line 79 def draw_trait if [:bounding_box][:debug] $window.draw_rect(self.bounding_box, Chingu::DEBUG_COLOR, Chingu::DEBUG_ZORDER) end super end |
#setup_trait(options) ⇒ Object
36 37 38 39 |
# File 'lib/chingu/traits/bounding_box.rb', line 36 def setup_trait() @cached_bounding_box = nil super end |