Class: Airsprite::SpriteFrame

Inherits:
Object
  • Object
show all
Defined in:
lib/airsprite/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path) ⇒ SpriteFrame

Returns a new instance of SpriteFrame.



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/airsprite/base.rb', line 241

def initialize(name, path)
  split_name = name.split('-')

  if split_name.size == 1
    @name = split_name[0]
    @speed = 0
  else
    @name = split_name.shift
    @speed = split_name.join.to_i
  end

  @data = Magick::Image::read(path).first
  @width = @data.columns.to_i
  @height = @data.rows.to_i
  @area = @width * @height
end

Instance Attribute Details

#areaObject

Returns the value of attribute area.



239
240
241
# File 'lib/airsprite/base.rb', line 239

def area
  @area
end

#dataObject

Returns the value of attribute data.



238
239
240
# File 'lib/airsprite/base.rb', line 238

def data
  @data
end

#heightObject

Returns the value of attribute height.



239
240
241
# File 'lib/airsprite/base.rb', line 239

def height
  @height
end

#nameObject

Returns the value of attribute name.



238
239
240
# File 'lib/airsprite/base.rb', line 238

def name
  @name
end

#positionObject

Returns the value of attribute position.



238
239
240
# File 'lib/airsprite/base.rb', line 238

def position
  @position
end

#speedObject

Returns the value of attribute speed.



238
239
240
# File 'lib/airsprite/base.rb', line 238

def speed
  @speed
end

#widthObject

Returns the value of attribute width.



239
240
241
# File 'lib/airsprite/base.rb', line 239

def width
  @width
end

#xObject

Returns the value of attribute x.



239
240
241
# File 'lib/airsprite/base.rb', line 239

def x
  @x
end

#yObject

Returns the value of attribute y.



239
240
241
# File 'lib/airsprite/base.rb', line 239

def y
  @y
end

Instance Method Details

#to_sObject



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/airsprite/base.rb', line 258

def to_s
  <<-EOS
  SpriteFrame
  {
    name "#{name}"
    speed #{speed}
    position #{position}
    width #{width}
    height #{height}
    area #{area}
    x #{x}
    y #{y}
  }
  EOS
end

#to_short_sObject



274
275
276
# File 'lib/airsprite/base.rb', line 274

def to_short_s
  "frame: #{width} x #{height} = #{area} (#{x}, #{y})"
end