Class: Chippunk::World
- Inherits:
-
Object
- Object
- Chippunk::World
- Defined in:
- lib/chippunk/world.rb
Instance Attribute Summary collapse
-
#dt ⇒ Object
Returns the value of attribute dt.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#space ⇒ Object
readonly
Returns the value of attribute space.
-
#substeps ⇒ Object
Returns the value of attribute substeps.
Instance Method Summary collapse
- #add_object(obj) ⇒ Object
- #add_objects(*objects) ⇒ Object
- #draw(canvas) ⇒ Object
-
#initialize {|_self| ... } ⇒ World
constructor
A new instance of World.
- #method_missing(method, *args, &block) ⇒ Object
- #update(&block) ⇒ Object
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
12 13 14 |
# File 'lib/chippunk/world.rb', line 12 def method_missing(method, *args, &block) @space.send(method, *args, &block) end |
Instance Attribute Details
#dt ⇒ Object
Returns the value of attribute dt.
4 5 6 |
# File 'lib/chippunk/world.rb', line 4 def dt @dt end |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
3 4 5 |
# File 'lib/chippunk/world.rb', line 3 def objects @objects end |
#space ⇒ Object (readonly)
Returns the value of attribute space.
3 4 5 |
# File 'lib/chippunk/world.rb', line 3 def space @space end |
#substeps ⇒ Object
Returns the value of attribute substeps.
4 5 6 |
# File 'lib/chippunk/world.rb', line 4 def substeps @substeps end |
Instance Method Details
#add_object(obj) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/chippunk/world.rb', line 16 def add_object(obj) obj.world = self obj.shape.obj = obj @space.add_shape(obj.shape) @space.add_body(obj.shape.body) unless obj.static? @objects << obj end |
#add_objects(*objects) ⇒ Object
24 25 26 |
# File 'lib/chippunk/world.rb', line 24 def add_objects(*objects) objects.each{ |obj| self.add_object(obj) } end |
#draw(canvas) ⇒ Object
36 37 38 |
# File 'lib/chippunk/world.rb', line 36 def draw(canvas) @objects.each{ |obj| obj.draw(canvas) } end |
#update(&block) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/chippunk/world.rb', line 28 def update(&block) @substeps.times do @objects.each{ |o| o.body.reset_forces } yield(self) if block_given? @space.step(@dt) end end |