Sha256: f097724fdfd69f0b2befcc1d0a2c3c532f148c808e17588136194409b640a598

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.0.0 motion/joybox-ios/core/layer.rb
joybox-0.0.6 motion/joybox-ios/core/layer.rb