module Joybox module Core class Layer < CCLayer touch_states = [:began, :moved, :ended, :cancelled] touch_states.each do |touch_state| define_method("on_touches_#{touch_state}") do |&block| self.touchEnabled = true if block_given? instance_variable_set("@on_touches_#{touch_state}_block", block) end end # These methods can't be autogenerated using metaprogramming # because Objective-C will call them def ccTouchesBegan(touches, withEvent: event) @on_touches_began_block.call(touches, event) if @on_touches_began_block end def ccTouchesMoved(touches, withEvent: event) @on_touches_moved_block.call(touches, event) if @on_touches_moved_block end def ccTouchesEnded(touches, withEvent: event) @on_touches_ended_block.call(touches, event) if @on_touches_ended_block end def ccTouchesCancelled(touches, withEvent: event) @on_touches_cancelled_block.call(touches, event) if @on_touches_cancelled_block end end end end