Sha256: 777c9b493fd2fa200fd5bc8c8f91a3245410c3dddd759834d083a48c0c50cfa4

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

module Joybox
  module Core

    class Sprite < CCSprite

      alias_method :run_action, :runAction
      alias_method :stop_action, :stopAction
      alias_method :stop_all_actions, :stopAllActions

      def self.new(options = {})

        sprite ||= new_with_file_name(options) if options.has_key? (:file_name)
        sprite ||= new_with_texture(options) if options.has_key? (:texture)
        sprite ||= new_with_frame_name(options) if options.has_key? (:frame_name)

        sprite.position = options[:position] if options.has_key? (:position)

        sprite
      end

      def file_name=(file_name)

        texture = CCTextureCache.sharedTextureCache.addImage(file_name)
        self.setTexture(texture)
      end

      
      # Review this in another version, because I dont still quite convinced
      # that this is the correct approach. The alternative is two methods
      # flip_x and flip_y, but I dont like them either.
      def flip(options = {})

        self.flipX = options[:x] if options.include?(:x)
        self.flipY = options[:y] if options.include?(:y)
      end


      private 

      def self.new_with_file_name(options = {})

        spriteWithFile(options[:file_name])
      end


      def self.new_with_texture(options = {})

        if options.has_key? (:rect)

          spriteWithTexture(options[:texture], rect: options[:rect])
        else

          spriteWithTexture(options:[:texture])
        end

      end


      def self.new_with_frame_name(options = {})

        spriteWithSpriteFrameName(options[:frame_name])
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
joybox-0.0.6 motion/joybox/core/sprite.rb