summaryrefslogtreecommitdiffhomepage
path: root/lib/camera/wrappers/sprite_wrapper.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-04-24 16:22:08 -0400
committerrealtradam <[email protected]>2021-04-24 16:22:08 -0400
commit93290fb327f4dac63ac201c4c21e13c60cae0eff (patch)
tree6e44d1a48359c86a70b89a9f8cc8af3e3da8706a /lib/camera/wrappers/sprite_wrapper.rb
parent8968999c513b4ce3cac9f5907199235006bb6a11 (diff)
downloadruby2d-camera-old-93290fb327f4dac63ac201c4c21e13c60cae0eff.tar.gz
ruby2d-camera-old-93290fb327f4dac63ac201c4c21e13c60cae0eff.zip
Diffstat (limited to 'lib/camera/wrappers/sprite_wrapper.rb')
-rw-r--r--lib/camera/wrappers/sprite_wrapper.rb23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/camera/wrappers/sprite_wrapper.rb b/lib/camera/wrappers/sprite_wrapper.rb
index 58ed1f7..d38c0bc 100644
--- a/lib/camera/wrappers/sprite_wrapper.rb
+++ b/lib/camera/wrappers/sprite_wrapper.rb
@@ -6,19 +6,32 @@ module Camera
module SpriteWrapped
# Recalculates real coordiantes
# Use after changing variables
- def update
+ def redraw
angle = Camera.angle * (Math::PI / 180)
half_width = Window.width * 0.5
half_height = Window.height * 0.5
offset_x = x + (width / 2)
offset_y = y + (height / 2)
- @x = (((offset_x - Camera.x) * Math.cos(angle)) - ((offset_y - Camera.y) * Math.sin(angle))) \
+ @x = @flip_x = (((offset_x - Camera.x) * Math.cos(angle)) - ((offset_y - Camera.y) * Math.sin(angle))) \
* Camera.zoom + half_width - (width * Camera.zoom / 2)
- @y = (((offset_x - Camera.x) * Math.sin(angle)) + ((offset_y - Camera.y) * Math.cos(angle))) \
+ @y = @flip_y = (((offset_x - Camera.x) * Math.sin(angle)) + ((offset_y - Camera.y) * Math.cos(angle))) \
* Camera.zoom + half_height - (height * Camera.zoom / 2)
@rotate = rotate + Camera.angle
- @width = width * Camera.zoom
- @height = height * Camera.zoom
+ @width = @flip_width = width * Camera.zoom
+ @height = @flip_height = height * Camera.zoom
+ case @flip
+ when :both
+ @flip_x = @x + @height
+ @flip_width = -@width
+ @flip_y = @y + @width
+ @flip_height = -@height
+ when :horizontal
+ @flip_y = @y + @width
+ @flip_height = -@height
+ when :vertical
+ @flip_x = @x + @height
+ @flip_width = -@width
+ end
end
#Methods for moving the shape