Class: DXRuby::Tiled::TileObject

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

Instance Attribute Summary collapse

Attributes inherited from TMEObject

#id, #name, #properties, #type

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of TileObject.



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/dxruby_tiled/object.rb', line 190

def initialize(x, y, tile, options = {})
  super x, y, options
  @tile = tile
  self.image = tile.original_image
  if tile.is_a? FlippedTile
    self.scale_x = tile.scale_x
    self.scale_y = tile.scale_y
    @tile = tile.tile
    self.extend(FlippedTileObject)
  end
  self.angle    = options[:rotation]
  self.center_x = -tile.offset_x
  self.center_y = self.image.height - tile.offset_y
  self.collision = tile.collision
  self.collision_enable = tile.collision_enable
  self.offset_sync = true
  @start_time = nil
end

Instance Attribute Details

#start_timeObject

Returns the value of attribute start_time.



174
175
176
# File 'lib/dxruby_tiled/object.rb', line 174

def start_time
  @start_time
end

#tileObject

Returns the value of attribute tile.



173
174
175
# File 'lib/dxruby_tiled/object.rb', line 173

def tile
  @tile
end

Class Method Details

.create_from_hash(hash) ⇒ Object



186
187
188
# File 'lib/dxruby_tiled/object.rb', line 186

def self.create_from_hash(hash)
  self.new(hash[:x], hash[:y], hash[:tile], hash)
end

.evolve(object) ⇒ Object



176
177
178
179
180
181
182
183
184
# File 'lib/dxruby_tiled/object.rb', line 176

def self.evolve(object)
  new_object = self.new(object.x, object.y, object.tile, id: @id)
  %w[z angle scale_x scale_y center_x center_y 
     alpha blend shader image target
     collision collision_enable collision_sync visible offset_sync
     name type start_time].each do |arg|
    new_object.send(arg + "=", object.send(arg))
  end
end

Instance Method Details

#become(new_class) ⇒ Object



223
224
225
# File 'lib/dxruby_tiled/object.rb', line 223

def become(new_class)
  new_class.evolve(self)
end

#drawObject



209
210
211
212
213
214
215
216
# File 'lib/dxruby_tiled/object.rb', line 209

def draw
  @start_time ||= DXRuby::Window::running_time
  tile = @tile.animate((DXRuby::Window::running_time - @start_time))
  self.image    = tile.original_image
  self.center_x = -tile.offset_x
  self.center_y = self.image.height - tile.offset_y
  super
end