Sha256: 36859b21479992f3c6d0026ed16f58f6ea3e79d3147c699ba00eebe8911da30a

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
joybox-1.1.1 motion/joybox-ios/core/layer.rb
joybox-1.1.0 motion/joybox-ios/core/layer.rb