From 5b5a7ffcaede8e0a9fb44e5bb57218c45d85ce29 Mon Sep 17 00:00:00 2001 From: neochuky Date: Sat, 17 Mar 2012 14:16:13 +0000 Subject: [PATCH 01/10] new file: game_object_press_button.rb --- lib/chingu/game_object_press_button.rb | 112 +++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 lib/chingu/game_object_press_button.rb diff --git a/lib/chingu/game_object_press_button.rb b/lib/chingu/game_object_press_button.rb new file mode 100644 index 00000000..2122d7f4 --- /dev/null +++ b/lib/chingu/game_object_press_button.rb @@ -0,0 +1,112 @@ +module Chingu + # + # GameObject inherits from BasicGameObject to get traits and some class-methods like .all and .destroy + # On top of that, it encapsulates GOSUs Image#draw_rot and all its parameters. + # In Chingu GameObject is a visual object, something to put on screen, centers around the .image-parameter. + # If you wan't a invisible object but with traits, use BasicGameObject. + # +class PressButton < GameObject + def setup + + # @animations = Chingu::Animation.new(:file => "../media/heli.png") + puts "press ejecuto" + puts @animations + #Set event methods to nill + @on_click_method = @on_release_method = @on_hold_method = Proc.new {} + #Normaly a button has two images, pressed and unpressed + @animations.frame_names = {:scan => 0..1} + #puts self.width + #puts self.height + @animation = @animations[:scan] + #The button starts unpressed + @image = @animation.first + @clicked = false + half_width = self.width / 2 + half_height = self.height / 2 + #Total area of the button + @button_range = {:x => ((self.x - half_width)..(self.x + self.width - half_width)), + :y => ((self.y - half_height)..(self.y + self.height - half_height))} + #If the user clicks, we check if he clicked a button + self.input = {:left_mouse_button => :check_click, + :released_left_mouse_button => :check_release, + :holding_left_mouse_button => :check_hold } + end + + def check_click +=begin + puts $window.mouse_x + puts $window.mouse_y + puts self.center_x + puts self.center_y + puts self.center + puts @button_range +=end + #If mouse position is inside the range, then go to click + if @button_range[:x].include? $window.mouse_x and + @button_range[:y].include? $window.mouse_y then + #The user clicked on this button + @clicked = true + self.on_click + end + end + + def check_hold +=begin + puts "holding" + puts $window.mouse_x + puts $window.mouse_y + puts @button_range +=end + if @button_range[:x].include? $window.mouse_x and + @button_range[:y].include? $window.mouse_y then + self.on_hold + end + end + + def check_release +=begin + puts $window.mouse_x + puts $window.mouse_y + puts @button_range +=end + #If the button was pressed, it does not matter + #where the user has the mouse + if @clicked then + @clicked = false + self.on_release + end + end + + #Methods that allow QT like use. + def on_click(&block) + #Set pressed image + @image = @animation.last + if block_given? + #If is first call, save the block that will be executed + @on_click_method = block + else + #On a normal call, execute user's code + @on_click_method.call + end + end + + + def on_release(&block) + @image = @animation.first + if block_given? + @on_release_method = block + else + @on_release_method.call + end + end + + def on_hold(&block) + if block_given? + @on_hold_method = block + else + @on_hold_method.call + end + end + +end +end From dc25423408ca92fa12d68285da0e7384c3108990 Mon Sep 17 00:00:00 2001 From: neochuky Date: Sat, 17 Mar 2012 14:23:57 +0000 Subject: [PATCH 02/10] License added --- lib/chingu/game_object_press_button.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/chingu/game_object_press_button.rb b/lib/chingu/game_object_press_button.rb index 2122d7f4..9ffde5ff 100644 --- a/lib/chingu/game_object_press_button.rb +++ b/lib/chingu/game_object_press_button.rb @@ -1,3 +1,22 @@ +#Added button functinality +#Copyright 2012, neochuky neochuki@gmail.com +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +#++ + module Chingu # # GameObject inherits from BasicGameObject to get traits and some class-methods like .all and .destroy From 0e8a199af5ebb696f990c167f803cbed647bfece Mon Sep 17 00:00:00 2001 From: neochuky Date: Sat, 17 Mar 2012 23:29:57 +0000 Subject: [PATCH 03/10] First complete press button object --- lib/chingu/game_object_press_button.rb | 193 ++++++++++++------------- 1 file changed, 89 insertions(+), 104 deletions(-) diff --git a/lib/chingu/game_object_press_button.rb b/lib/chingu/game_object_press_button.rb index 9ffde5ff..f802df56 100644 --- a/lib/chingu/game_object_press_button.rb +++ b/lib/chingu/game_object_press_button.rb @@ -19,113 +19,98 @@ module Chingu # - # GameObject inherits from BasicGameObject to get traits and some class-methods like .all and .destroy - # On top of that, it encapsulates GOSUs Image#draw_rot and all its parameters. - # In Chingu GameObject is a visual object, something to put on screen, centers around the .image-parameter. - # If you wan't a invisible object but with traits, use BasicGameObject. + # PressButton provides a Qt like interface, a normal use would be + # + # myButton = PressButton(:x => x, :y => y,:released_image => image when the button + # is not clicked,:pressed_image => image when the button is clicked ) + # + # myButton.on_click do + # do some awesome + # end + # # -class PressButton < GameObject - def setup - - # @animations = Chingu::Animation.new(:file => "../media/heli.png") - puts "press ejecuto" - puts @animations - #Set event methods to nill - @on_click_method = @on_release_method = @on_hold_method = Proc.new {} - #Normaly a button has two images, pressed and unpressed - @animations.frame_names = {:scan => 0..1} - #puts self.width - #puts self.height - @animation = @animations[:scan] - #The button starts unpressed - @image = @animation.first - @clicked = false - half_width = self.width / 2 - half_height = self.height / 2 - #Total area of the button - @button_range = {:x => ((self.x - half_width)..(self.x + self.width - half_width)), - :y => ((self.y - half_height)..(self.y + self.height - half_height))} - #If the user clicks, we check if he clicked a button - self.input = {:left_mouse_button => :check_click, - :released_left_mouse_button => :check_release, - :holding_left_mouse_button => :check_hold } - end - def check_click -=begin - puts $window.mouse_x - puts $window.mouse_y - puts self.center_x - puts self.center_y - puts self.center - puts @button_range -=end - #If mouse position is inside the range, then go to click - if @button_range[:x].include? $window.mouse_x and - @button_range[:y].include? $window.mouse_y then - #The user clicked on this button - @clicked = true - self.on_click - end + class PressButton < Chingu::GameObject + + def initialize(options = {}) + #Normaly a button has two images, pressed and released + @released_image = Image[options[:released_image]] + @pressed_image = Image[options[:pressed_image]] + super end - - def check_hold -=begin - puts "holding" - puts $window.mouse_x - puts $window.mouse_y - puts @button_range -=end - if @button_range[:x].include? $window.mouse_x and - @button_range[:y].include? $window.mouse_y then - self.on_hold - end - end - - def check_release -=begin - puts $window.mouse_x - puts $window.mouse_y - puts @button_range -=end - #If the button was pressed, it does not matter - #where the user has the mouse - if @clicked then + + def setup + #Set event methods to nill + @on_click_method = @on_release_method = @on_hold_method = Proc.new {} + #The button starts unpressed @clicked = false - self.on_release + @image = @released_image + half_width = self.width / 2 + half_height = self.height / 2 + #Total area of the button + @button_range = {:x => ((self.x - half_width)..(self.x + self.width - half_width)), + :y => ((self.y - half_height)..(self.y + self.height - half_height))} + #If the user clicks, we check if he clicked a button + self.input = {:left_mouse_button => :check_click, + :released_left_mouse_button => :check_release, + :holding_left_mouse_button => :check_hold } end - end - - #Methods that allow QT like use. - def on_click(&block) - #Set pressed image - @image = @animation.last - if block_given? - #If is first call, save the block that will be executed - @on_click_method = block - else - #On a normal call, execute user's code - @on_click_method.call - end - end - - - def on_release(&block) - @image = @animation.first - if block_given? - @on_release_method = block - else - @on_release_method.call - end - end - - def on_hold(&block) - if block_given? - @on_hold_method = block - else - @on_hold_method.call + + def check_click + #If mouse position is inside the range, then go to click + if @button_range[:x].include? $window.mouse_x and + @button_range[:y].include? $window.mouse_y then + #The user clicked on this button + @clicked = true + self.on_click + end + end + + def check_hold + if @button_range[:x].include? $window.mouse_x and + @button_range[:y].include? $window.mouse_y then + self.on_hold + end + end + + def check_release + #If the button was pressed, it does not matter + #where the user has the mouse + if @clicked then + @clicked = false + self.on_release + end + end + + #Methods that allow QT like use. + def on_click(&block) + #Set pressed image + if block_given? + #If is first call, save the block that will be executed + @on_click_method = block + else + #On a normal call, execute user's code + @image = @pressed_image + @on_click_method.call + end + end + + + def on_release(&block) + if block_given? + @on_release_method = block + else + @image = @released_image + @on_release_method.call + end + end + + def on_hold(&block) + if block_given? + @on_hold_method = block + else + @on_hold_method.call + end + end end - end - -end -end +end \ No newline at end of file From 572442aae0775d9c2285a8043a54838436d48c12 Mon Sep 17 00:00:00 2001 From: neochuky Date: Fri, 13 Apr 2012 19:55:37 +0100 Subject: [PATCH 04/10] Added set_x and set_y for press button --- lib/chingu/game_object_press_button.rb | 32 ++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/chingu/game_object_press_button.rb b/lib/chingu/game_object_press_button.rb index f802df56..ab361e10 100644 --- a/lib/chingu/game_object_press_button.rb +++ b/lib/chingu/game_object_press_button.rb @@ -31,11 +31,16 @@ module Chingu # class PressButton < Chingu::GameObject - + # alias :oldx= :x= + # alias :old_y= :y= + # old_x = self.instance_method(:x=) + def initialize(options = {}) #Normaly a button has two images, pressed and released @released_image = Image[options[:released_image]] @pressed_image = Image[options[:pressed_image]] + @x = options[:x] + @y = options[:y] super end @@ -45,11 +50,11 @@ def setup #The button starts unpressed @clicked = false @image = @released_image - half_width = self.width / 2 - half_height = self.height / 2 + @half_width = self.width / 2 + @half_height = self.height / 2 #Total area of the button - @button_range = {:x => ((self.x - half_width)..(self.x + self.width - half_width)), - :y => ((self.y - half_height)..(self.y + self.height - half_height))} + @button_range = {:x => ((self.x - @half_width)..(self.x + self.width - @half_width)), + :y => ((self.y - @half_height)..(self.y + self.height - @half_height))} #If the user clicks, we check if he clicked a button self.input = {:left_mouse_button => :check_click, :released_left_mouse_button => :check_release, @@ -113,4 +118,21 @@ def on_hold(&block) end end end + + #TODO Overwritte x= method of module sprite + # define_method(:x=) do + # old_x.bind(self).call + # puts "lo pille \n" + # @button_range[:x] = ((self.x - @half_width)..(self.x + self.width - @half_width)) + # end + + def set_x= value + @button_range[:x] = ((value - @half_width)..(value + self.width - @half_width)) + self.x = value + end + + def set_y= value + @button_range[:y] = ((value - @half_height)..(value + self.height - @half_height)) + self.y = value + end end \ No newline at end of file From 0fc3169b7c6a364c8f841387fcef0e394efa414e Mon Sep 17 00:00:00 2001 From: neochuky Date: Fri, 8 Jun 2012 09:38:54 +0100 Subject: [PATCH 05/10] Set_x and Set_y added --- lib/chingu/game_object_press_button.rb | 37 +++++++++++++++++++------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/chingu/game_object_press_button.rb b/lib/chingu/game_object_press_button.rb index ab361e10..b978b95e 100644 --- a/lib/chingu/game_object_press_button.rb +++ b/lib/chingu/game_object_press_button.rb @@ -21,7 +21,7 @@ module Chingu # # PressButton provides a Qt like interface, a normal use would be # - # myButton = PressButton(:x => x, :y => y,:released_image => image when the button + # myButton = PressButton(:x => x, :y => y,:button_image => image when the button # is not clicked,:pressed_image => image when the button is clicked ) # # myButton.on_click do @@ -33,12 +33,11 @@ module Chingu class PressButton < Chingu::GameObject # alias :oldx= :x= # alias :old_y= :y= - # old_x = self.instance_method(:x=) + old_x = self.instance_method(:x=) def initialize(options = {}) #Normaly a button has two images, pressed and released - @released_image = Image[options[:released_image]] - @pressed_image = Image[options[:pressed_image]] + @button_image = Image[options[:button_image]] @x = options[:x] @y = options[:y] super @@ -49,7 +48,9 @@ def setup @on_click_method = @on_release_method = @on_hold_method = Proc.new {} #The button starts unpressed @clicked = false - @image = @released_image + #The button can be used/clicked + @active = true + @image = @button_image @half_width = self.width / 2 @half_height = self.height / 2 #Total area of the button @@ -60,10 +61,23 @@ def setup :released_left_mouse_button => :check_release, :holding_left_mouse_button => :check_hold } end + + def active= value + #If the button was pressed, it does not matter + #where the user has the mouse + @active = value + end + + def active? value + #If the button was pressed, it does not matter + #where the user has the mouse + return @active + end def check_click #If mouse position is inside the range, then go to click - if @button_range[:x].include? $window.mouse_x and + if @active and + @button_range[:x].include? $window.mouse_x and @button_range[:y].include? $window.mouse_y then #The user clicked on this button @clicked = true @@ -72,7 +86,8 @@ def check_click end def check_hold - if @button_range[:x].include? $window.mouse_x and + if @active and + @button_range[:x].include? $window.mouse_x and @button_range[:y].include? $window.mouse_y then self.on_hold end @@ -81,7 +96,7 @@ def check_hold def check_release #If the button was pressed, it does not matter #where the user has the mouse - if @clicked then + if @active and @clicked then @clicked = false self.on_release end @@ -95,7 +110,8 @@ def on_click(&block) @on_click_method = block else #On a normal call, execute user's code - @image = @pressed_image + @factor_x -= 0.02 + @factor_y -= 0.02 @on_click_method.call end end @@ -105,7 +121,8 @@ def on_release(&block) if block_given? @on_release_method = block else - @image = @released_image + @factor_x += 0.02 + @factor_y += 0.02 @on_release_method.call end end From 6da9291f9e87b8881e564ee74ca3201a241656a9 Mon Sep 17 00:00:00 2001 From: neochuky Date: Fri, 8 Jun 2012 19:20:39 +0100 Subject: [PATCH 06/10] Text button in progess --- lib/chingu/game_object_press_button.rb | 38 ++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/chingu/game_object_press_button.rb b/lib/chingu/game_object_press_button.rb index b978b95e..f2082647 100644 --- a/lib/chingu/game_object_press_button.rb +++ b/lib/chingu/game_object_press_button.rb @@ -36,7 +36,7 @@ class PressButton < Chingu::GameObject old_x = self.instance_method(:x=) def initialize(options = {}) - #Normaly a button has two images, pressed and released + #Get the button image @button_image = Image[options[:button_image]] @x = options[:x] @y = options[:y] @@ -152,4 +152,38 @@ def set_y= value @button_range[:y] = ((value - @half_height)..(value + self.height - @half_height)) self.y = value end -end \ No newline at end of file +#end + +################################################################################################################ + + #TODO Make text buttons work, thay saiy no width + class PressButtonText < Chingu::Text + # alias :oldx= :x= + # alias :old_y= :y= + old_x = self.instance_method(:x=) + + def initialize(text, options = {}) + #Get the button size + super + @x = options[:x] + @y = options[:y] + end + + def setup + #Set event methods to nill + @on_click_method = @on_release_method = @on_hold_method = Proc.new {} + #The button starts unpressed + @clicked = false + #The button can be used/clicked + @active = true + self.methods + # @half_width = self.width / 2 + # @half_height = self.height / 2 + #Total area of the button + # @button_range = {:x => ((self.x - @half_width)..(self.x + self.width - @half_width)), + # :y => ((self.y - @half_height)..(self.y + self.height - @half_height))} + end + + end + +end \ No newline at end of file From 83b9b80781090cb5d098a9cad5a67ed4bc42bed3 Mon Sep 17 00:00:00 2001 From: neochuky Date: Fri, 8 Jun 2012 22:43:09 +0100 Subject: [PATCH 07/10] No more textbutton --- lib/chingu/game_object_press_button.rb | 34 -------------------------- 1 file changed, 34 deletions(-) diff --git a/lib/chingu/game_object_press_button.rb b/lib/chingu/game_object_press_button.rb index f2082647..e8930db9 100644 --- a/lib/chingu/game_object_press_button.rb +++ b/lib/chingu/game_object_press_button.rb @@ -152,38 +152,4 @@ def set_y= value @button_range[:y] = ((value - @half_height)..(value + self.height - @half_height)) self.y = value end -#end - -################################################################################################################ - - #TODO Make text buttons work, thay saiy no width - class PressButtonText < Chingu::Text - # alias :oldx= :x= - # alias :old_y= :y= - old_x = self.instance_method(:x=) - - def initialize(text, options = {}) - #Get the button size - super - @x = options[:x] - @y = options[:y] - end - - def setup - #Set event methods to nill - @on_click_method = @on_release_method = @on_hold_method = Proc.new {} - #The button starts unpressed - @clicked = false - #The button can be used/clicked - @active = true - self.methods - # @half_width = self.width / 2 - # @half_height = self.height / 2 - #Total area of the button - # @button_range = {:x => ((self.x - @half_width)..(self.x + self.width - @half_width)), - # :y => ((self.y - @half_height)..(self.y + self.height - @half_height))} - end - - end - end \ No newline at end of file From df131b7acc8e66f9acccab1bff2d319f0d76dfab Mon Sep 17 00:00:00 2001 From: neochuky Date: Mon, 18 Jun 2012 22:28:22 +0100 Subject: [PATCH 08/10] Fixed position alias and moved code from setup to initialize --- lib/chingu/game_object_press_button.rb | 62 ++++++++++++++------------ 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/lib/chingu/game_object_press_button.rb b/lib/chingu/game_object_press_button.rb index e8930db9..80fab8ff 100644 --- a/lib/chingu/game_object_press_button.rb +++ b/lib/chingu/game_object_press_button.rb @@ -31,19 +31,21 @@ module Chingu # class PressButton < Chingu::GameObject - # alias :oldx= :x= - # alias :old_y= :y= - old_x = self.instance_method(:x=) + alias :old_x= :x= + alias :old_y= :y= def initialize(options = {}) + super #Get the button image - @button_image = Image[options[:button_image]] + if options[:button_image] + @button_image = Image[options[:button_image]] + else + @animation = Animation.new(:file => options[:button_animation], + :size => options[:size]||[50,50], :delay => options[:delay]||100) + @button_image = @animation.first + end @x = options[:x] @y = options[:y] - super - end - - def setup #Set event methods to nill @on_click_method = @on_release_method = @on_hold_method = Proc.new {} #The button starts unpressed @@ -51,16 +53,17 @@ def setup #The button can be used/clicked @active = true @image = @button_image - @half_width = self.width / 2 - @half_height = self.height / 2 + @half_width = @button_image.width / 2 + @half_height = @button_image.height / 2 #Total area of the button - @button_range = {:x => ((self.x - @half_width)..(self.x + self.width - @half_width)), - :y => ((self.y - @half_height)..(self.y + self.height - @half_height))} + @button_range = {:x => ((self.x - @half_width)..(self.x + @button_image.width - @half_width)), + :y => ((self.y - @half_height)..(self.y + @button_image.height - @half_height))} #If the user clicks, we check if he clicked a button self.input = {:left_mouse_button => :check_click, :released_left_mouse_button => :check_release, :holding_left_mouse_button => :check_hold } - end + @initialized = true + end def active= value #If the button was pressed, it does not matter @@ -134,22 +137,25 @@ def on_hold(&block) @on_hold_method.call end end - end - #TODO Overwritte x= method of module sprite - # define_method(:x=) do - # old_x.bind(self).call - # puts "lo pille \n" - # @button_range[:x] = ((self.x - @half_width)..(self.x + self.width - @half_width)) - # end - - def set_x= value - @button_range[:x] = ((value - @half_width)..(value + self.width - @half_width)) - self.x = value + def x= value + @x = value + old_x = value + if @initialized + @button_range[:x] = ((value - @half_width)..(value + @button_image.width - @half_width)) + end end - def set_y= value - @button_range[:y] = ((value - @half_height)..(value + self.height - @half_height)) - self.y = value - end + def y= value + @y = value + old_y = value + if @initialized + @button_range[:y] = ((value - @half_height)..(value + @button_image.height - @half_height)) + end + end + + def update + @image = @animation.next if @animation + end + end end \ No newline at end of file From 6ec9224fe4d8bf3c812dc143c52f1b3ff59050a4 Mon Sep 17 00:00:00 2001 From: neochuky Date: Sat, 14 Jul 2012 11:48:50 +0100 Subject: [PATCH 09/10] Minor fixes --- lib/chingu/game_object_press_button.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/chingu/game_object_press_button.rb b/lib/chingu/game_object_press_button.rb index 80fab8ff..42661283 100644 --- a/lib/chingu/game_object_press_button.rb +++ b/lib/chingu/game_object_press_button.rb @@ -40,9 +40,14 @@ def initialize(options = {}) if options[:button_image] @button_image = Image[options[:button_image]] else - @animation = Animation.new(:file => options[:button_animation], - :size => options[:size]||[50,50], :delay => options[:delay]||100) - @button_image = @animation.first + #Get the button animation + if options[:button_animation] + @animation = Animation.new(:file => options[:button_animation], + :size => options[:size]||[50,50], :delay => options[:delay]||100) + @button_image = @animation.first + else + raise "A button needs an image or an animation\n" + end end @x = options[:x] @y = options[:y] @@ -66,14 +71,10 @@ def initialize(options = {}) end def active= value - #If the button was pressed, it does not matter - #where the user has the mouse @active = value end def active? value - #If the button was pressed, it does not matter - #where the user has the mouse return @active end @@ -107,7 +108,6 @@ def check_release #Methods that allow QT like use. def on_click(&block) - #Set pressed image if block_given? #If is first call, save the block that will be executed @on_click_method = block From fa38b1ce0ae58d61518d01c20735440a2b554b26 Mon Sep 17 00:00:00 2001 From: neochuky Date: Tue, 31 Jul 2012 12:59:48 +0100 Subject: [PATCH 10/10] Fixed error when factor was not 1 --- lib/chingu/game_object_press_button.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/chingu/game_object_press_button.rb b/lib/chingu/game_object_press_button.rb index 42661283..ee891f69 100644 --- a/lib/chingu/game_object_press_button.rb +++ b/lib/chingu/game_object_press_button.rb @@ -49,8 +49,6 @@ def initialize(options = {}) raise "A button needs an image or an animation\n" end end - @x = options[:x] - @y = options[:y] #Set event methods to nill @on_click_method = @on_release_method = @on_hold_method = Proc.new {} #The button starts unpressed @@ -58,11 +56,11 @@ def initialize(options = {}) #The button can be used/clicked @active = true @image = @button_image - @half_width = @button_image.width / 2 - @half_height = @button_image.height / 2 + @half_width = self.width / 2 + @half_height = self.height / 2 #Total area of the button - @button_range = {:x => ((self.x - @half_width)..(self.x + @button_image.width - @half_width)), - :y => ((self.y - @half_height)..(self.y + @button_image.height - @half_height))} + @button_range = {:x => ((self.x - @half_width)..(self.x + self.width - @half_width)), + :y => ((self.y - @half_height)..(self.y + self.height - @half_height))} #If the user clicks, we check if he clicked a button self.input = {:left_mouse_button => :check_click, :released_left_mouse_button => :check_release, @@ -142,7 +140,7 @@ def x= value @x = value old_x = value if @initialized - @button_range[:x] = ((value - @half_width)..(value + @button_image.width - @half_width)) + @button_range[:x] = ((value - @half_width)..(value + self.width - @half_width)) end end @@ -150,7 +148,7 @@ def y= value @y = value old_y = value if @initialized - @button_range[:y] = ((value - @half_height)..(value + @button_image.height - @half_height)) + @button_range[:y] = ((value - @half_height)..(value + self.height - @half_height)) end end @@ -158,4 +156,4 @@ def update @image = @animation.next if @animation end end -end \ No newline at end of file +end