Class: RubySketch::SpriteWorld
- Inherits:
-
Object
- Object
- RubySketch::SpriteWorld
- Defined in:
- lib/rubysketch/sprite.rb
Overview
A class Manages sprites.
Instance Method Summary collapse
-
#addSprite(*sprites) ⇒ Sprite
Adds sprites to the physics engine.
-
#createSprite(*args, context: nil, **kwargs) ⇒ Sprite
Creates a new sprite and add it to physics engine.
- #debug=(state) ⇒ Object
- #debug? ⇒ Boolean
-
#gravity(*args) ⇒ nil
Sets gravity for the physics engine.
-
#initialize(pixels_per_meter: 0) ⇒ SpriteWorld
constructor
Create a new physics world.
-
#removeSprite(*sprites) ⇒ Sprite
Removes sprites from the physics engine.
Constructor Details
#initialize(pixels_per_meter: 0) ⇒ SpriteWorld
Create a new physics world
942 943 944 |
# File 'lib/rubysketch/sprite.rb', line 942 def initialize(pixels_per_meter: 0) @view, @debug = View.new(pixels_per_meter: pixels_per_meter), false end |
Instance Method Details
#addSprite(*sprites) ⇒ Sprite
Adds sprites to the physics engine.
1005 1006 1007 1008 |
# File 'lib/rubysketch/sprite.rb', line 1005 def addSprite(*sprites) sprites.each {@view.add _1.getInternal__} sprites.first end |
#createSprite(x, y, w, h) ⇒ Sprite #createSprite(image: img) ⇒ Sprite #createSprite(x, y, image: img) ⇒ Sprite #createSprite(x, y, image: img, offset: off) ⇒ Sprite #createSprite(x, y, image: img, shape: shp) ⇒ Sprite #createSprite(x, y, image: img, offset: off, shape: shp) ⇒ Sprite #createSprite(x, y, shape: shp) ⇒ Sprite
Creates a new sprite and add it to physics engine.
994 995 996 997 |
# File 'lib/rubysketch/sprite.rb', line 994 def createSprite(*args, context: nil, **kwargs) context ||= Context.context__ addSprite Sprite.new(*args, context: context, **kwargs) end |
#debug=(state) ⇒ Object
1046 1047 1048 |
# File 'lib/rubysketch/sprite.rb', line 1046 def debug=(state) @view.debug = state end |
#debug? ⇒ Boolean
1050 |
# File 'lib/rubysketch/sprite.rb', line 1050 def debug? = @view.debug? |
#gravity(vec) ⇒ nil #gravity(ary) ⇒ nil #gravity(x, y) ⇒ nil
Sets gravity for the physics engine.
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 |
# File 'lib/rubysketch/sprite.rb', line 1035 def gravity(*args) x, y = case arg = args.first when Vector then arg.array when Array then arg else args end @view.gravity x, y nil end |
#removeSprite(*sprites) ⇒ Sprite
Removes sprites from the physics engine.
1016 1017 1018 1019 |
# File 'lib/rubysketch/sprite.rb', line 1016 def removeSprite(*sprites) sprites.each {@view.remove _1.getInternal__} sprites.first end |