summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortradam <git.tradam.fyi>2021-09-27 08:39:23 -0400
committertradam <git.tradam.fyi>2021-09-27 08:39:23 -0400
commit5f46f1f975bd621fbca9c7e173de78e83ad70e3a (patch)
treeeed828b369247c3d081ae1b3573bdb5119ff96a4
parentc326eb2b27921f584ac46c484dab9be2cddb90f7 (diff)
downloadruby2d-camera-5f46f1f975bd621fbca9c7e173de78e83ad70e3a.tar.gz
ruby2d-camera-5f46f1f975bd621fbca9c7e173de78e83ad70e3a.zip
partially complete fixing code, found a strange bug with ruby2d
-rw-r--r--example/old_example/README.mdown (renamed from example/README.mdown)0
-rw-r--r--example/old_example/assets/background.png (renamed from example/assets/background.png)bin60142 -> 60142 bytes
-rw-r--r--example/old_example/assets/blobcoolthink.png (renamed from example/assets/blobcoolthink.png)bin13066 -> 13066 bytes
-rw-r--r--example/old_example/assets/blobshadow.png (renamed from example/assets/blobshadow.png)bin5679 -> 5679 bytes
-rw-r--r--example/old_example/assets/bricktexture.png (renamed from example/assets/bricktexture.png)bin741798 -> 741798 bytes
-rw-r--r--example/old_example/assets/legacy_player.png (renamed from example/assets/legacy_player.png)bin1044 -> 1044 bytes
-rw-r--r--example/old_example/assets/sprites/alienpls-56.png (renamed from example/assets/sprites/alienpls-56.png)bin255710 -> 255710 bytes
-rw-r--r--example/old_example/assets/sprites/blobdance-128.png (renamed from example/assets/sprites/blobdance-128.png)bin35825 -> 35825 bytes
-rw-r--r--example/old_example/assets/sprites/dance2-112.png (renamed from example/assets/sprites/dance2-112.png)bin214857 -> 214857 bytes
-rw-r--r--example/old_example/assets/sprites/dancer-128.png (renamed from example/assets/sprites/dancer-128.png)bin39270 -> 39270 bytes
-rw-r--r--example/old_example/assets/sprites/mainblob-128.png (renamed from example/assets/sprites/mainblob-128.png)bin94731 -> 94731 bytes
-rw-r--r--example/old_example/house.rb (renamed from example/house.rb)0
-rw-r--r--example/old_example/room.rb (renamed from example/room.rb)0
-rw-r--r--example/old_example/run.rb (renamed from example/run.rb)2
-rw-r--r--example/test/assets/alienpls-56.pngbin0 -> 255710 bytes
-rw-r--r--example/test/assets/bricktexture-600.pngbin0 -> 741798 bytes
-rw-r--r--example/test/run.rb378
-rw-r--r--lib/ruby2d/camera.rb1
-rw-r--r--lib/ruby2d/camera/circle.rb8
-rw-r--r--lib/ruby2d/camera/image.rb4
-rw-r--r--lib/ruby2d/camera/line.rb4
-rw-r--r--lib/ruby2d/camera/quad.rb4
-rw-r--r--lib/ruby2d/camera/rectangle.rb4
-rw-r--r--lib/ruby2d/camera/sprite.rb5
-rw-r--r--lib/ruby2d/camera/square.rb4
-rw-r--r--lib/ruby2d/camera/text.rb32
-rw-r--r--lib/ruby2d/camera/triangle.rb19
-rw-r--r--lib/ruby2d/camera/version.rb2
28 files changed, 424 insertions, 43 deletions
diff --git a/example/README.mdown b/example/old_example/README.mdown
index 186f6e3..186f6e3 100644
--- a/example/README.mdown
+++ b/example/old_example/README.mdown
diff --git a/example/assets/background.png b/example/old_example/assets/background.png
index f411e96..f411e96 100644
--- a/example/assets/background.png
+++ b/example/old_example/assets/background.png
Binary files differ
diff --git a/example/assets/blobcoolthink.png b/example/old_example/assets/blobcoolthink.png
index 7cdfcc8..7cdfcc8 100644
--- a/example/assets/blobcoolthink.png
+++ b/example/old_example/assets/blobcoolthink.png
Binary files differ
diff --git a/example/assets/blobshadow.png b/example/old_example/assets/blobshadow.png
index ff981cb..ff981cb 100644
--- a/example/assets/blobshadow.png
+++ b/example/old_example/assets/blobshadow.png
Binary files differ
diff --git a/example/assets/bricktexture.png b/example/old_example/assets/bricktexture.png
index 4ef86e0..4ef86e0 100644
--- a/example/assets/bricktexture.png
+++ b/example/old_example/assets/bricktexture.png
Binary files differ
diff --git a/example/assets/legacy_player.png b/example/old_example/assets/legacy_player.png
index 485e972..485e972 100644
--- a/example/assets/legacy_player.png
+++ b/example/old_example/assets/legacy_player.png
Binary files differ
diff --git a/example/assets/sprites/alienpls-56.png b/example/old_example/assets/sprites/alienpls-56.png
index af9452a..af9452a 100644
--- a/example/assets/sprites/alienpls-56.png
+++ b/example/old_example/assets/sprites/alienpls-56.png
Binary files differ
diff --git a/example/assets/sprites/blobdance-128.png b/example/old_example/assets/sprites/blobdance-128.png
index 6326ec0..6326ec0 100644
--- a/example/assets/sprites/blobdance-128.png
+++ b/example/old_example/assets/sprites/blobdance-128.png
Binary files differ
diff --git a/example/assets/sprites/dance2-112.png b/example/old_example/assets/sprites/dance2-112.png
index 2d69026..2d69026 100644
--- a/example/assets/sprites/dance2-112.png
+++ b/example/old_example/assets/sprites/dance2-112.png
Binary files differ
diff --git a/example/assets/sprites/dancer-128.png b/example/old_example/assets/sprites/dancer-128.png
index c3fdbc0..c3fdbc0 100644
--- a/example/assets/sprites/dancer-128.png
+++ b/example/old_example/assets/sprites/dancer-128.png
Binary files differ
diff --git a/example/assets/sprites/mainblob-128.png b/example/old_example/assets/sprites/mainblob-128.png
index ca78578..ca78578 100644
--- a/example/assets/sprites/mainblob-128.png
+++ b/example/old_example/assets/sprites/mainblob-128.png
Binary files differ
diff --git a/example/house.rb b/example/old_example/house.rb
index c6257ee..c6257ee 100644
--- a/example/house.rb
+++ b/example/old_example/house.rb
diff --git a/example/room.rb b/example/old_example/room.rb
index 27c002d..27c002d 100644
--- a/example/room.rb
+++ b/example/old_example/room.rb
diff --git a/example/run.rb b/example/old_example/run.rb
index 96ab9ab..2790f40 100644
--- a/example/run.rb
+++ b/example/old_example/run.rb
@@ -110,7 +110,7 @@ on :key do |event|
1
end
elsif Camera.angle += if Camera.angle < 350
- 10
+ 10
else
1
end
diff --git a/example/test/assets/alienpls-56.png b/example/test/assets/alienpls-56.png
new file mode 100644
index 0000000..af9452a
--- /dev/null
+++ b/example/test/assets/alienpls-56.png
Binary files differ
diff --git a/example/test/assets/bricktexture-600.png b/example/test/assets/bricktexture-600.png
new file mode 100644
index 0000000..4ef86e0
--- /dev/null
+++ b/example/test/assets/bricktexture-600.png
Binary files differ
diff --git a/example/test/run.rb b/example/test/run.rb
new file mode 100644
index 0000000..14e9d5c
--- /dev/null
+++ b/example/test/run.rb
@@ -0,0 +1,378 @@
+require 'ruby2d'
+require 'ruby2d/camera'
+
+Window.set(width: 640,
+ height: 480)
+
+# ----- UI -----
+#Rectangle.new(
+# width: 350,
+# height: 135,
+# color: 'navy',
+# z: 100
+#)
+@ui_pos_cam = Text.new(
+ 'pos: 0,0',
+ x: 10,
+ y: 10,
+ color: 'teal',
+ z: 101
+)
+#@ui_pos_ply = Text.new(
+# 'pos: 0,0',
+# x: 10,
+# y: 40,
+# color: 'teal',
+# z: 101
+#)
+@ui_zoom = Text.new(
+ 'zoom: 0',
+ x: 10,
+ y: 35,
+ color: 'lime',
+ z: 101
+)
+@ui_rotation = Text.new(
+ 'rotation: 0',
+ x: 10,
+ y: 60,
+ color: 'lime',
+ z: 101
+)
+#Rectangle.new(
+# x: (Window.width - 120),
+# width: 80,
+# height: 45,
+# color: 'navy',
+# opacity: 0.3,
+# z: 100
+#)
+@ui_fps = Text.new(
+ 'fps: 60.00',
+ x: (Window.width - 110),
+ y: 10,
+ color: 'teal',
+ z: 101
+)
+@dancing_alien1 = Camera::Sprite.new('./assets/alienpls-56.png',
+ x: 520 + -28,
+ y: -28,
+ width: 56,
+ height: 56,
+ clip_width: 56,
+ loop: true,
+ time: 35,
+ z: 1)
+@dancing_alien1.play
+@dancing_alien2 = Camera::Sprite.new('./assets/alienpls-56.png',
+ x: -28,
+ y: 370 + -28,
+ width: 56,
+ height: 56,
+ clip_width: 56,
+ loop: true,
+ time: 35,
+ z: 1)
+@dancing_alien2.play
+@dancing_alien3 = Camera::Sprite.new('./assets/alienpls-56.png',
+ x: -520 + -28,
+ y: -28,
+ width: 56,
+ height: 56,
+ clip_width: 56,
+ loop: true,
+ time: 35,
+ z: 1)
+@dancing_alien3.play
+@dancing_alien4 = Camera::Sprite.new('./assets/alienpls-56.png',
+ x: -28,
+ y: -370 + -28,
+ width: 56,
+ height: 56,
+ clip_width: 56,
+ loop: true,
+ time: 35,
+ z: 1)
+@dancing_alien4.play
+
+@caution_topleft = []
+@caution_topright = []
+@caution_botleft = []
+@caution_botright = []
+
+@caution_topleft.push Camera::Triangle.new(color: 'yellow',
+ x1: -280, y1: -200,
+ x2: -260, y2: -220,
+ x3: -300, y3: -220
+ )
+@caution_topleft.push Camera::Triangle.new(color: 'gray',
+ x1: -280, y1: -200,
+ x2: -300, y2: -180,
+ x3: -300, y3: -220
+ )
+@caution_topleft.push Camera::Quad.new(color: 'yellow',
+ x1: -280, y1: -200,
+ x2: -300, y2: -180,
+ x3: -300, y3: -160,
+ x4: -280, y4: -180
+ )
+@caution_topleft.push Camera::Quad.new(color: 'gray',
+ x1: -280, y1: -160,
+ x2: -300, y2: -140,
+ x3: -300, y3: -160,
+ x4: -280, y4: -180
+ )
+@caution_topleft.push Camera::Quad.new(color: 'gray',
+ x1: -280, y1: -200,
+ x2: -260, y2: -220,
+ x3: -240, y3: -220,
+ x4: -260, y4: -200
+ )
+@caution_topleft.push Camera::Quad.new(color: 'yellow',
+ x1: -240, y1: -200,
+ x2: -220, y2: -220,
+ x3: -240, y3: -220,
+ x4: -260, y4: -200
+ )
+
+@caution_topright.push Camera::Triangle.new(color: 'yellow',
+ x1: 280, y1: -200,
+ x2: 260, y2: -220,
+ x3: 300, y3: -220
+ )
+@caution_topright.push Camera::Triangle.new(color: 'gray',
+ x1: 280, y1: -200,
+ x2: 300, y2: -180,
+ x3: 300, y3: -220
+ )
+@caution_topright.push Camera::Quad.new(color: 'yellow',
+ x1: 280, y1: -200,
+ x2: 300, y2: -180,
+ x3: 300, y3: -160,
+ x4: 280, y4: -180
+ )
+@caution_topright.push Camera::Quad.new(color: 'gray',
+ x1: 280, y1: -160,
+ x2: 300, y2: -140,
+ x3: 300, y3: -160,
+ x4: 280, y4: -180
+ )
+@caution_topright.push Camera::Quad.new(color: 'gray',
+ x1: 280, y1: -200,
+ x2: 260, y2: -220,
+ x3: 240, y3: -220,
+ x4: 260, y4: -200
+ )
+@caution_topright.push Camera::Quad.new(color: 'yellow',
+ x1: 240, y1: -200,
+ x2: 220, y2: -220,
+ x3: 240, y3: -220,
+ x4: 260, y4: -200
+ )
+
+@caution_botleft.push Camera::Triangle.new(color: 'yellow',
+ x1: -280, y1: 200,
+ x2: -260, y2: 220,
+ x3: -300, y3: 220
+ )
+@caution_botleft.push Camera::Triangle.new(color: 'gray',
+ x1: -280, y1: 200,
+ x2: -300, y2: 180,
+ x3: -300, y3: 220
+ )
+@caution_botleft.push Camera::Quad.new(color: 'yellow',
+ x1: -280, y1: 200,
+ x2: -300, y2: 180,
+ x3: -300, y3: 160,
+ x4: -280, y4: 180
+ )
+@caution_botleft.push Camera::Quad.new(color: 'gray',
+ x1: -280, y1: 160,
+ x2: -300, y2: 140,
+ x3: -300, y3: 160,
+ x4: -280, y4: 180
+ )
+@caution_botleft.push Camera::Quad.new(color: 'gray',
+ x1: -280, y1: 200,
+ x2: -260, y2: 220,
+ x3: -240, y3: 220,
+ x4: -260, y4: 200
+ )
+@caution_botleft.push Camera::Quad.new(color: 'yellow',
+ x1: -240, y1: 200,
+ x2: -220, y2: 220,
+ x3: -240, y3: 220,
+ x4: -260, y4: 200
+ )
+
+@caution_botright.push Camera::Triangle.new(color: 'yellow',
+ x1: 280, y1: 200,
+ x2: 260, y2: 220,
+ x3: 300, y3: 220
+ )
+@caution_botright.push Camera::Triangle.new(color: 'gray',
+ x1: 280, y1: 200,
+ x2: 300, y2: 180,
+ x3: 300, y3: 220
+ )
+@caution_botright.push Camera::Quad.new(color: 'yellow',
+ x1: 280, y1: 200,
+ x2: 300, y2: 180,
+ x3: 300, y3: 160,
+ x4: 280, y4: 180
+ )
+@caution_botright.push Camera::Quad.new(color: 'gray',
+ x1: 280, y1: 160,
+ x2: 300, y2: 140,
+ x3: 300, y3: 160,
+ x4: 280, y4: 180
+ )
+@caution_botright.push Camera::Quad.new(color: 'gray',
+ x1: 280, y1: 200,
+ x2: 260, y2: 220,
+ x3: 240, y3: 220,
+ x4: 260, y4: 200
+ )
+@caution_botright.push Camera::Quad.new(color: 'yellow',
+ x1: 240, y1: 200,
+ x2: 220, y2: 220,
+ x3: 240, y3: 220,
+ x4: 260, y4: 200
+ )
+
+@text = Camera::Text.new("Bigger circles should always be in front of smaller ones",
+ size: 30,
+ x: 0, y: 65)
+
+@zindex_test = []
+
+@zindex_test.push Camera::Circle.new(color: 'random',
+ x: 50 + -25, y: -25,
+ radius: 25)
+@zindex_test.push Camera::Circle.new(color: 'random',
+ x: 25 + -25, y: -25,
+ radius: 25)
+@zindex_test.push Camera::Circle.new(color: 'random',
+ x: 0 + -25, y: -25,
+ radius: 25)
+@zindex_test.push Camera::Circle.new(color: 'random',
+ x: -25 + -25, y: -25,
+ radius: 25)
+@zindex_test.push Camera::Circle.new(color: 'random',
+ x: -50 + -25, y: -25,
+ radius: 25)
+
+@speed = 5
+@one_degree_in_radians = 0.01745329
+
+on :key do |event|
+ Camera.y -= (Math.cos(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 'w'
+ Camera.y += (Math.cos(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 's'
+ Camera.x -= (Math.sin(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 'w'
+ Camera.x += (Math.sin(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 's'
+
+ Camera.x += (Math.cos(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 'd'
+ Camera.x -= (Math.cos(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 'a'
+ Camera.y -= (Math.sin(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 'd'
+ Camera.y += (Math.sin(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 'a'
+
+ #@pressed_space = true if event.key == 'space' && !(@scene_transition_into || @scene_transition_out)
+ Camera.angle += 1.5 if event.key == 'q'
+ Camera.angle -= 1.5 if event.key == 'e'
+ Camera.zoom *= 1.01 if event.key == 'z'
+ Camera.zoom *= 0.99 if event.key == 'x'
+ if event.key == 'r'# && !(@scene_transition_into || @scene_transition_out || Camera.angle.zero?)
+ if Camera.zoom < 1.0
+ Camera.zoom *= 1.03
+ if Camera.zoom > 1.0
+ Camera.zoom = 1.0
+ end
+ elsif Camera.zoom > 1.0
+ Camera.zoom /= 1.03
+ if Camera.zoom < 1.0
+ Camera.zoom = 1.0
+ end
+ end
+ if Camera.angle <= 180
+ Camera.angle -= if Camera.angle > 10
+ 10
+ elsif Camera.angle != 0
+ 1
+ else
+ 0
+ end
+ elsif Camera.angle += if Camera.angle < 350
+ 10
+ elsif Camera.angle != 0
+ 1
+ else
+ 0
+ end
+ if (Camera.angle > 359) || (Camera.angle < 1)
+ Camera.angle = 0
+ end
+ end
+ end
+end
+
+@frame = 0
+update do
+ @frame += 1
+
+ @a = (Math.sin(((@frame - 30) % 120) * (Math::PI / 60.0)) * 15 + 25)
+ @b = (Math.sin(((@frame - 15) % 120) * (Math::PI / 60.0)) * 15 + 25)
+ @c = (Math.sin((@frame % 120) * (Math::PI / 60.0)) * 15 + 25)
+ @d = (Math.sin(((@frame + 15) % 120) * (Math::PI / 60.0)) * 15 + 25)
+ @e = (Math.sin(((@frame + 30) % 120) * (Math::PI / 60.0)) * 15 + 25)
+ @zindex_test[0].z = @a
+ @zindex_test[0].radius = @a
+ @zindex_test[0].x = 50 + -@a
+ @zindex_test[0].y = -@a
+ @zindex_test[1].z = @b
+ @zindex_test[1].radius = @b
+ @zindex_test[1].x = 25 + -@b
+ @zindex_test[1].y = -@b
+ @zindex_test[2].z = @c
+ @zindex_test[2].radius = @c
+ @zindex_test[2].x = -@c
+ @zindex_test[2].y = -@c
+ @zindex_test[3].z = @d
+ @zindex_test[3].radius = @d
+ @zindex_test[3].x = -25 + -@d
+ @zindex_test[3].y = -@d
+ @zindex_test[4].z = @e
+ @zindex_test[4].radius = @e
+ @zindex_test[4].x = -50 + -@e
+ @zindex_test[4].y = -@e
+
+ if (@frame % 120) < 30
+ @dancing_alien1.add
+ @dancing_alien2.remove
+ @dancing_alien3.remove
+ @dancing_alien4.remove
+ elsif ((@frame + 30) % 120) < 30
+ @dancing_alien1.remove
+ @dancing_alien2.add
+ @dancing_alien3.remove
+ @dancing_alien4.remove
+ elsif ((@frame + 60) % 120) < 30
+ @dancing_alien1.remove
+ @dancing_alien2.remove
+ @dancing_alien3.add
+ @dancing_alien4.remove
+ elsif ((@frame + 90) % 120) < 30
+ @dancing_alien1.remove
+ @dancing_alien2.remove
+ @dancing_alien3.remove
+ @dancing_alien4.add
+ end
+
+ @ui_pos_cam.text = "Camera Position: #{Camera.x.round(1)}, #{Camera.y.round(1)}"
+ #@ui_pos_ply.text = "Player Position: #{@player.x.round(1)}, #{@player.y.round(1)}"
+ @ui_zoom.text = "Zoom: #{Camera.zoom.round(3)}"
+ @ui_fps.text = "FPS: #{Window.fps.round(2)}"
+ @ui_rotation.text = "Angle: #{Camera.angle}"
+end
+
+show
diff --git a/lib/ruby2d/camera.rb b/lib/ruby2d/camera.rb
index 3213e16..7c587f1 100644
--- a/lib/ruby2d/camera.rb
+++ b/lib/ruby2d/camera.rb
@@ -16,7 +16,6 @@ module Ruby2D
def objects
@objects ||= []
end
-
end
def self._sort_by_z
diff --git a/lib/ruby2d/camera/circle.rb b/lib/ruby2d/camera/circle.rb
index 2896055..b2b8fd1 100644
--- a/lib/ruby2d/camera/circle.rb
+++ b/lib/ruby2d/camera/circle.rb
@@ -14,8 +14,8 @@ module Ruby2D
half_width = Window.width * 0.5
half_height = Window.height * 0.5
temp_radius = @radius * Camera.zoom
- temp_x = (((@x - Ruby2D::Camera.x + radius) * Math.cos(angle)) - ((@y - Ruby2D::Camera.y + radius) * Math.sin(angle))) * Ruby2D::Camera.zoom + half_width
- temp_y = (((@x - Ruby2D::Camera.x + radius) * Math.sin(angle)) + ((@y - Ruby2D::Camera.y + radius) * Math.cos(angle))) * Ruby2D::Camera.zoom + half_height
+ temp_x = (((@x - Camera.x + radius) * Math.cos(angle)) - ((@y - Camera.y + radius) * Math.sin(angle))) * Camera.zoom + half_width
+ temp_y = (((@x - Camera.x + radius) * Math.sin(angle)) + ((@y - Camera.y + radius) * Math.cos(angle))) * Camera.zoom + half_height
Ruby2D::Circle.draw(x: temp_x, y: temp_y,
radius: temp_radius,
sectors: sectors,
@@ -24,13 +24,13 @@ module Ruby2D
def initialize(opts = {})
super(opts)
- Ruby2D::Camera << self
+ Camera << self
Window.remove(self)
end
def z=(z)
super(z)
- Ruby2D::Camera._sort_by_z
+ Camera._sort_by_z
end
def remove
diff --git a/lib/ruby2d/camera/image.rb b/lib/ruby2d/camera/image.rb
index aa72685..3d4cf33 100644
--- a/lib/ruby2d/camera/image.rb
+++ b/lib/ruby2d/camera/image.rb
@@ -30,13 +30,13 @@ module Camera
def initialize(path, opts = {})
super(path, opts)
- Ruby2D::Camera << self
+ Camera << self
Window.remove(self)
end
def z=(z)
super(z)
- Ruby2D::Camera._sort_by_z
+ Camera._sort_by_z
end
def remove
diff --git a/lib/ruby2d/camera/line.rb b/lib/ruby2d/camera/line.rb
index 6019f3c..c9a8caf 100644
--- a/lib/ruby2d/camera/line.rb
+++ b/lib/ruby2d/camera/line.rb
@@ -32,7 +32,7 @@ module Ruby2D
def initialize(opts = {})
super(opts)
- Ruby2D::Camera << self
+ Camera << self
Window.remove(self)
end
@@ -57,7 +57,7 @@ module Ruby2D
def z=(z)
super(z)
- Ruby2D::Camera._sort_by_z
+ Camera._sort_by_z
end
end
end
diff --git a/lib/ruby2d/camera/quad.rb b/lib/ruby2d/camera/quad.rb
index 24ba516..994c137 100644
--- a/lib/ruby2d/camera/quad.rb
+++ b/lib/ruby2d/camera/quad.rb
@@ -36,7 +36,7 @@ module Ruby2D
def initialize(opts = {})
super(opts)
- Ruby2D::Camera << self
+ Camera << self
Window.remove(self)
end
@@ -61,7 +61,7 @@ module Ruby2D
def z=(z)
super(z)
- Ruby2D::Camera._sort_by_z
+ Camera._sort_by_z
end
end
end
diff --git a/lib/ruby2d/camera/rectangle.rb b/lib/ruby2d/camera/rectangle.rb
index b3758b6..f8a139e 100644
--- a/lib/ruby2d/camera/rectangle.rb
+++ b/lib/ruby2d/camera/rectangle.rb
@@ -36,7 +36,7 @@ module Ruby2D
def initialize(opts = {})
super(opts)
- Ruby2D::Camera << self
+ Camera << self
Window.remove(self)
@x1 -= @x
@x2 -= @x
@@ -69,7 +69,7 @@ module Ruby2D
def z=(z)
super(z)
- Ruby2D::Camera._sort_by_z
+ Camera._sort_by_z
end
end
end
diff --git a/lib/ruby2d/camera/sprite.rb b/lib/ruby2d/camera/sprite.rb
index d01a86f..da67d54 100644
--- a/lib/ruby2d/camera/sprite.rb
+++ b/lib/ruby2d/camera/sprite.rb
@@ -28,7 +28,6 @@ module Ruby2D
temp_y += temp_width
temp_width = -temp_width
temp_height = -temp_height
- puts 'both'
when :horizontal
temp_y += temp_width
temp_height = -temp_height
@@ -45,13 +44,13 @@ module Ruby2D
def initialize(path, opts = {})
super(path, opts)
- Ruby2D::Camera << self
+ Camera << self
Window.remove(self)
end
def z=(z)
super(z)
- Ruby2D::Camera._sort_by_z
+ Camera._sort_by_z
end
def remove
diff --git a/lib/ruby2d/camera/square.rb b/lib/ruby2d/camera/square.rb
index b6f0321..7f74ee5 100644
--- a/lib/ruby2d/camera/square.rb
+++ b/lib/ruby2d/camera/square.rb
@@ -36,7 +36,7 @@ module Ruby2D
def initialize(opts = {})
super(opts)
- Ruby2D::Camera << self
+ Camera << self
Window.remove(self)
@x1 -= @x
@x2 -= @x
@@ -69,7 +69,7 @@ module Ruby2D
def z=(z)
super(z)
- Ruby2D::Camera._sort_by_z
+ Camera._sort_by_z
end
end
end
diff --git a/lib/ruby2d/camera/text.rb b/lib/ruby2d/camera/text.rb
index da23edb..04f2dcc 100644
--- a/lib/ruby2d/camera/text.rb
+++ b/lib/ruby2d/camera/text.rb
@@ -16,11 +16,13 @@ module Ruby2D
return if @hide
angle = Camera.angle * (Math::PI / 180)
+ render_text.size = size * Camera.zoom
+ #puts render_text.width
half_width = Window.width * 0.5
half_height = Window.height * 0.5
if center
- offset_y = y + (Camera.zoom / 2)
- offset_x = x + (Camera.zoom / 2)
+ offset_x = x + (width / Camera.zoom / 2) - (render_text.width / 2 / Camera.zoom)
+ offset_y = y + (height / Camera.zoom / 2) - (render_text.height / 2 / Camera.zoom)
else
offset_x = x + (width / Camera.zoom / 2)
offset_y = y + (height / Camera.zoom / 2)
@@ -30,25 +32,29 @@ module Ruby2D
temp_y = (((offset_x - Camera.x) * Math.sin(angle)) + ((offset_y - Camera.y) * Math.cos(angle))) \
* Camera.zoom + half_height - (height / 2)
temp_rotate = rotate + Camera.angle
- # Workaround for resizing text
- # TODO: resizing doesnt work at all even with workaround
- temp_size = size # * Camera.zoom
- self.size *= Camera.zoom
- draw(x: temp_x, y: temp_y,
- rotate: temp_rotate,
- color: [color.r, color.g, color.b, color.a])
- self.size = temp_size
+ render_text.draw(x: temp_x, y: temp_y,
+ rotate: temp_rotate,
+ color: [color.r, color.g, color.b, color.a])
end
def initialize(text, opts = {})
super(text, opts)
- Ruby2D::Camera << self
+ self.render_text = Ruby2D::Text.new(text, opts)
+ render_text.remove
+ self.center = opts[:center]
+ Camera << self
Window.remove(self)
end
def z=(z)
super(z)
- Ruby2D::Camera._sort_by_z
+ render_text.z = z
+ Camera._sort_by_z
+ end
+
+ def text=(text)
+ super(text)
+ render_text.text = text
end
def remove
@@ -59,7 +65,7 @@ module Ruby2D
@hide = false
end
- attr_accessor :center
+ attr_accessor :center, :render_text
end
end
end
diff --git a/lib/ruby2d/camera/triangle.rb b/lib/ruby2d/camera/triangle.rb
index 56e2aef..e97dd98 100644
--- a/lib/ruby2d/camera/triangle.rb
+++ b/lib/ruby2d/camera/triangle.rb
@@ -8,15 +8,15 @@ module Ruby2D
def _draw
return if @hide
- angle = Ruby2D::Camera.angle * (Math::PI / 180)
+ angle = Camera.angle * (Math::PI / 180)
half_width = Window.width * 0.5
half_height = Window.height * 0.5
- temp_x1 = (((x + @x1 - Ruby2D::Camera.x) * Math.cos(angle)) - ((y + @y1 - Ruby2D::Camera.y) * Math.sin(angle))) * Ruby2D::Camera.zoom + half_width
- temp_y1 = (((x + @x1 - Ruby2D::Camera.x) * Math.sin(angle)) + ((y + @y1 - Ruby2D::Camera.y) * Math.cos(angle))) * Ruby2D::Camera.zoom + half_height
- temp_x2 = (((x + @x2 - Ruby2D::Camera.x) * Math.cos(angle)) - ((y + @y2 - Ruby2D::Camera.y) * Math.sin(angle))) * Ruby2D::Camera.zoom + half_width
- temp_y2 = (((x + @x2 - Ruby2D::Camera.x) * Math.sin(angle)) + ((y + @y2 - Ruby2D::Camera.y) * Math.cos(angle))) * Ruby2D::Camera.zoom + half_height
- temp_x3 = (((x + @x3 - Ruby2D::Camera.x) * Math.cos(angle)) - ((y + @y3 - Ruby2D::Camera.y) * Math.sin(angle))) * Ruby2D::Camera.zoom + half_width
- temp_y3 = (((x + @x3 - Ruby2D::Camera.x) * Math.sin(angle)) + ((y + @y3 - Ruby2D::Camera.y) * Math.cos(angle))) * Ruby2D::Camera.zoom + half_height
+ temp_x1 = (((x + @x1 - Camera.x) * Math.cos(angle)) - ((y + @y1 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width
+ temp_y1 = (((x + @x1 - Camera.x) * Math.sin(angle)) + ((y + @y1 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height
+ temp_x2 = (((x + @x2 - Camera.x) * Math.cos(angle)) - ((y + @y2 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width
+ temp_y2 = (((x + @x2 - Camera.x) * Math.sin(angle)) + ((y + @y2 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height
+ temp_x3 = (((x + @x3 - Camera.x) * Math.cos(angle)) - ((y + @y3 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width
+ temp_y3 = (((x + @x3 - Camera.x) * Math.sin(angle)) + ((y + @y3 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height
Ruby2D::Triangle.draw(x1: temp_x1, y1: temp_y1,
x2: temp_x2, y2: temp_y2,
x3: temp_x3, y3: temp_y3,
@@ -30,9 +30,8 @@ module Ruby2D
def initialize(opts = {})
super(opts)
- Ruby2D::Camera << self
+ Camera << self
Window.remove(self)
- add
end
def remove
@@ -56,7 +55,7 @@ module Ruby2D
def z=(z)
super(z)
- Ruby2D::Camera._sort_by_z
+ Camera._sort_by_z
end
end
end
diff --git a/lib/ruby2d/camera/version.rb b/lib/ruby2d/camera/version.rb
index 1b12ce9..b95b99a 100644
--- a/lib/ruby2d/camera/version.rb
+++ b/lib/ruby2d/camera/version.rb
@@ -2,6 +2,6 @@
module Ruby2d
module Camera
- VERSION = '1.1.1.beta'
+ VERSION = '1.1.2.beta'
end
end