From 95d278e2cfca70e2b7e0826c07c7b1b7dfb25f50 Mon Sep 17 00:00:00 2001 From: ippa Date: Mon, 9 May 2011 13:22:18 +0200 Subject: [PATCH] fix :visible => false / show()! bug --- lib/chingu/basic_game_object.rb | 4 ++-- lib/chingu/traits/sprite.rb | 8 +++++--- spec/chingu/game_object_list_spec.rb | 7 +++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/chingu/basic_game_object.rb b/lib/chingu/basic_game_object.rb index 97ca5314..e62ca638 100644 --- a/lib/chingu/basic_game_object.rb +++ b/lib/chingu/basic_game_object.rb @@ -118,7 +118,7 @@ def self.create(*options, &block) # Disable automatic calling of update() and update_trait() each game loop # def pause! - @parent.game_objects.pause_game_object(self) if @parent && @paused == false + @parent.game_objects.pause_game_object(self) if @parent && !@paused @paused = true end alias :pause :pause! @@ -127,7 +127,7 @@ def pause! # Enable automatic calling of update() and update_trait() each game loop # def unpause! - @parent.game_objects.unpause_game_object(self) if @parent && @paused == true + @parent.game_objects.unpause_game_object(self) if @parent && @paused @paused = false end alias :unpause :unpause! diff --git a/lib/chingu/traits/sprite.rb b/lib/chingu/traits/sprite.rb index 9c8afad9..d30127ea 100644 --- a/lib/chingu/traits/sprite.rb +++ b/lib/chingu/traits/sprite.rb @@ -71,7 +71,9 @@ def setup_trait(object_options = {}) def to_s "#{self.class.to_s} @ #{x.to_i} / #{y.to_i} " << "(#{width.to_i} x #{height.to_i}) - " << - " ratio: #{sprintf("%.2f",width/height)} scale: #{sprintf("%.2f", factor_x)}/#{sprintf("%.2f", factor_y)} angle: #{angle.to_i} zorder: #{zorder} alpha: #{alpha}" + "ratio: #{sprintf("%.2f",width.to_f/height.to_f)} " << + "scale: #{sprintf("%.2f", factor_x)}/#{sprintf("%.2f", factor_y)} " << + "angle: #{angle.to_i} zorder: #{zorder} alpha: #{alpha}" end def color=(color) @@ -205,7 +207,7 @@ def angle=(value) # Disable automatic calling of draw and draw_trait each game loop # def hide! - @parent.game_objects.hide_game_object(self) if @parent && @visible == true + @parent.game_objects.hide_game_object(self) if @parent && @visible @visible = false end @@ -213,7 +215,7 @@ def hide! # Enable automatic calling of draw and draw_trait each game loop # def show! - @parent.game_objects.show_game_object(self) if @parent && @visible == false + @parent.game_objects.show_game_object(self) if @parent && !@visible @visible = true end diff --git a/spec/chingu/game_object_list_spec.rb b/spec/chingu/game_object_list_spec.rb index 96ef645d..1c679667 100644 --- a/spec/chingu/game_object_list_spec.rb +++ b/spec/chingu/game_object_list_spec.rb @@ -63,6 +63,13 @@ module Chingu @game.game_objects.draw end + it "should keep track of visible game objects with show!()" do + go = GameObject.create(:visible => false) + go.show! + go.should_receive(:draw) + @game.game_objects.draw + end + it "should call draw() on all visible game objects" do GameObject.create.should_receive(:draw) GameObject.create(:visible => false).should_not_receive(:draw)