Class: RubySketch::SpriteWorld
- Inherits:
-
Object
- Object
- RubySketch::SpriteWorld
- Defined in:
- lib/rubysketch/sprite.rb
Overview
A class Manages sprites.
Instance Method Summary collapse
-
#addSprite(array = nil, sprite) ⇒ Sprite
Adds sprite to the physics engine.
-
#createSprite(*args, klass: nil, 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(pixelsPerMeter: 0) ⇒ SpriteWorld
constructor
Create a new physics world.
-
#offset ⇒ Vector
Returns the offset of the sprite world.
-
#offset=(arg) ⇒ Vector
Sets the offset of the sprite world.
-
#ox ⇒ Numeric
Returns the x-axis offset of the sprite world.
-
#ox=(x) ⇒ Numeric
Sets the x-axis offset of the sprite world.
-
#oy ⇒ Numeric
Returns the y-axis offset of the sprite world.
-
#oy=(x) ⇒ Numeric
Sets the y-axis offset of the sprite world.
-
#removeSprite(array = nil, sprite) ⇒ Sprite
Removes sprite from the physics engine.
-
#zoom ⇒ Numeric
Returns the zoom value of the sprite world.
-
#zoom=(zoom) ⇒ Numeric
Sets the zoom value of the sprite world.
Constructor Details
#initialize(pixelsPerMeter: 0) ⇒ SpriteWorld
Create a new physics world.
1084 1085 1086 |
# File 'lib/rubysketch/sprite.rb', line 1084 def initialize(pixelsPerMeter: 0) @view, @debug = View.new(pixelsPerMeter: pixelsPerMeter), false end |
Instance Method Details
#addSprite(array = nil, sprite) ⇒ Sprite
Adds sprite to the physics engine.
1149 1150 1151 1152 1153 |
# File 'lib/rubysketch/sprite.rb', line 1149 def addSprite(array = nil, sprite) @view.add sprite.getInternal__ array&.push sprite sprite 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.
1136 1137 1138 1139 1140 |
# File 'lib/rubysketch/sprite.rb', line 1136 def createSprite(*args, klass: nil, context: nil, **kwargs) klass ||= RubySketch::Sprite context ||= Context.context__ addSprite klass.new(*args, context: context, **kwargs) end |
#debug=(state) ⇒ Object
1283 1284 1285 |
# File 'lib/rubysketch/sprite.rb', line 1283 def debug=(state) @view.debug = state end |
#debug? ⇒ Boolean
1287 |
# File 'lib/rubysketch/sprite.rb', line 1287 def debug? = @view.debug? |
#gravity(vec) ⇒ nil #gravity(ary) ⇒ nil #gravity(x, y) ⇒ nil
Sets gravity for the physics engine.
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 |
# File 'lib/rubysketch/sprite.rb', line 1182 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 |
#offset ⇒ Vector
Returns the offset of the sprite world.
1197 1198 1199 1200 |
# File 'lib/rubysketch/sprite.rb', line 1197 def offset() s, z = @view.scroll, zoom Vector.new(-s.x / z, -s.y / z, -s.z / z) end |
#offset=(vec) ⇒ Vector #offset=(ary) ⇒ Vector
Sets the offset of the sprite world.
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 |
# File 'lib/rubysketch/sprite.rb', line 1212 def offset=(arg) zoom_ = zoom x, y, z = case arg when Vector then [arg.x, arg.y, arg.z] when Array then [arg[0] || 0, arg[1] || 0, arg[2] || 0] when nil then [0, 0, 0] else raise ArgumentError end @view.scroll_to(-x * zoom_, -y * zoom_, -z * zoom_) offset end |
#ox ⇒ Numeric
Returns the x-axis offset of the sprite world.
1229 1230 1231 |
# File 'lib/rubysketch/sprite.rb', line 1229 def ox() offset.x end |
#ox=(x) ⇒ Numeric
Sets the x-axis offset of the sprite world.
1239 1240 1241 1242 1243 1244 |
# File 'lib/rubysketch/sprite.rb', line 1239 def ox=(x) o = offset o.x = x self.offset = o x end |
#oy ⇒ Numeric
Returns the y-axis offset of the sprite world.
1250 1251 1252 |
# File 'lib/rubysketch/sprite.rb', line 1250 def oy() offset.y end |
#oy=(x) ⇒ Numeric
Sets the y-axis offset of the sprite world.
1260 1261 1262 1263 1264 1265 |
# File 'lib/rubysketch/sprite.rb', line 1260 def oy=(x) o = offset o.y = y self.offset = o y end |
#removeSprite(array = nil, sprite) ⇒ Sprite
Removes sprite from the physics engine.
1162 1163 1164 1165 1166 |
# File 'lib/rubysketch/sprite.rb', line 1162 def removeSprite(array = nil, sprite) @view.remove sprite.getInternal__ array&.delete sprite sprite end |
#zoom ⇒ Numeric
Returns the zoom value of the sprite world.
1271 1272 1273 |
# File 'lib/rubysketch/sprite.rb', line 1271 def zoom() @view.zoom end |
#zoom=(zoom) ⇒ Numeric
Sets the zoom value of the sprite world.
1279 1280 1281 |
# File 'lib/rubysketch/sprite.rb', line 1279 def zoom=(zoom) @view.zoom = zoom end |