Sha256: b3841b4ab6f2eda80a2f3040810bb55b70bbb39920564e696c2c17be6780de08

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

Joybox::TMX::TileLayer = CCTMXLayer

class CCTMXLayer

  include Joybox::Common

  alias_method :name, :layerName
  alias_method :name=, :setLayerName
  alias_method :tiles_size, :layerSize
  alias_method :tiles_size=, :setLayerSize
  alias_method :map_of_tiles, :tiles
  alias_method :map_of_tiles=, :setTiles
  alias_method :tile_set, :tileset
  alias_method :tile_set=, :setTileset
  alias_method :orientation, :layerOrientation
  alias_method :orientation=, :setLayerOrientation
  alias_method :release_map, :releaseMap
  alias_method :setup_tiles, :setupTiles

  Orthogonal = 0
  Hexagonal = 1
  Isometric = 2

  def tile_size
    return mapTileSize unless Device.retina?
    return mapTileSize.half if Device.retina?
  end

  def size
    [layerSize.width * tile_size.width, layerSize.height * tile_size.height].to_size
  end

  def point_for_coordinate(coordinate)
    positionAt(coordinate)
  end

  def coordinate_for_point(point)
    point = point.to_point unless point.is_a? (CGPoint)
    x = point.x / tile_size.width
    y = (size.height - point.y) / tile_size.height
    [x.floor, y.floor].to_point
  end

  def sprite_at(point)
    coordinate = coordinate_for_point(point)
    tileAt(coordinate)
  end

  def tile_type_at(point)
    coordinate = coordinate_for_point(point)
    tileGIDAt(coordinate)
  end

  def remove_tile_at(point)
    coordinate = coordinate_for_point(point)
    removeTileAt(coordinate)
  end

  def set_tile_type_at(point, tile_type)
    coordinate = coordinate_for_point(point)
    setTileGID(tile_type, at: coordinate)
  end

  def [](point)
    coordinate = coordinate_for_point(point)
    tileGIDAt(coordinate)
  end

  def []=(point, tile_type)
    coordinate = coordinate_for_point(point)
    setTileGID(tile_type, at: coordinate)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
joybox-1.1.1 motion/joybox/tmx/tile_layer.rb
joybox-1.1.0 motion/joybox/tmx/tile_layer.rb