better sorting of images coming into sprites, fixes one rbx error

This commit is contained in:
John Bintz 2011-09-17 12:02:51 -04:00
parent 88ee68de5d
commit c9593794bd
2 changed files with 8 additions and 2 deletions

View File

@ -10,7 +10,13 @@ module Compass
def_delegators :rows, :[] def_delegators :rows, :[]
def initialize(images) def initialize(images)
@images = images.sort {|a,b| a.height <=> b.height } @images = images.sort do |a,b|
if a.height == b.height
b.width <=> a.width
else
a.height <=> b.height
end
end
@rows = [] @rows = []
end end

View File

@ -111,7 +111,7 @@ class SpriteMapTest < Test::Unit::TestCase
base.generate base.generate
assert_equal 400, base.width assert_equal 400, base.width
assert_equal 60, base.height assert_equal 60, base.height
assert_equal [[0, 0], [20, 120], [20, 20], [20, 0], [20, 160]], base.images.map {|i| [i.top, i.left]} assert_equal [[0, 0], [20, 120], [20, 0], [20, 100], [20, 160]], base.images.map {|i| [i.top, i.left]}
assert File.exists?(base.filename) assert File.exists?(base.filename)
FileUtils.rm base.filename FileUtils.rm base.filename
end end