Class: DXRuby::Tiled::TMEObject

Inherits:
Sprite
  • Object
show all
Defined in:
lib/dxruby_tiled/object.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, options = {}) ⇒ TMEObject

Returns a new instance of TMEObject.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dxruby_tiled/object.rb', line 39

def initialize(x, y, options = {})
  super x, y, nil
  @name        = options[:name]
  @type        = options[:type]
  @id          = options[:id]
  @width       = options[:width]
  @height      = options[:height]
  @properties  = options[:properties]
  self.angle   = options[:rotation]
  self.visible = options[:visible]
  self.collision_sync = true
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/dxruby_tiled/object.rb', line 4

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/dxruby_tiled/object.rb', line 5

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



4
5
6
# File 'lib/dxruby_tiled/object.rb', line 4

def properties
  @properties
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/dxruby_tiled/object.rb', line 5

def type
  @type
end

Class Method Details

.create_from_hash(hash, map = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dxruby_tiled/object.rb', line 7

def self.create_from_hash(hash, map = nil)
  hash[:id] ||= map.next_object_id
  if hash[:template]
    template = map.load_template(hash[:template])
    gid, source = template[:object][:gid], template[:tileset][:source]
    template[:object][:gid] = map.tilesets.gid_adjusted_by_source(gid, source)
    hash.merge!(template[:object])
  end
  object = case
  when hash[:point]
    PointObject.create_from_hash(hash)
  when hash[:ellipse]
    EllipseObject.create_from_hash(hash)
  when hash[:polygon]
    PolygonObject.create_from_hash(hash)
  when hash[:polyline]
    PolylineObject.create_from_hash(hash)
  when hash[:text]
    TextObject.create_from_hash(hash)
  when hash[:gid]
    hash[:tile] = map.tilesets[hash[:gid]]
    TileObject.create_from_hash(hash)
  else
    RectangleObject.create_from_hash(hash)
  end
  if map && map.orientation == IsometricLayer
    object.extend(ObjectInIsometricMap)
    object.width_height = 1.0 * map.tile_height / map.tile_width
  end
  object
end