lib/ruby2d/camera.rb in ruby2d-camera-1.1.0 vs lib/ruby2d/camera.rb in ruby2d-camera-1.1.1
- old
+ new
@@ -14,12 +14,22 @@
# Contains all objects that are tracked
def objects
@objects ||= []
end
+
end
+ def self._sort_by_z
+ @sort_by_z = true
+ end
+
+ def self._resolve_z_sorting
+ objects.sort_by!(&:z) if @sort_by_z
+ @sort_by_z = false
+ end
+
def self.debug_x
@debug_x ||= 0
end
def self.debug_x=(debug_x)
@@ -35,22 +45,23 @@
end
# Adding objects so they are
# tracked by the Camera
def self.<<(item)
- objects.push(item) unless objects.include?(item)
- objects.sort_by! do |n|
- n.z
+ unless objects.include?(item)
+ objects.push(item)
+ self._sort_by_z
end
end
def self.remove(item)
objects.delete(item) if objects.include?(item)
end
# Redraw all objects that
# are tracked by the Camera
def self._redraw(auto_purge: false)
+ self._resolve_z_sorting
objects.each(&:_draw)
end
# Variables changing Camera properties
def self._x(x)