Skip to content

Commit

Permalink
fix :visible => false / show()! bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ippa committed May 9, 2011
1 parent 8289f68 commit 95d278e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/chingu/basic_game_object.rb
Expand Up @@ -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!
Expand All @@ -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!
Expand Down
8 changes: 5 additions & 3 deletions lib/chingu/traits/sprite.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -205,15 +207,15 @@ 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

#
# 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

Expand Down
7 changes: 7 additions & 0 deletions spec/chingu/game_object_list_spec.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 95d278e

Please sign in to comment.