Class: Xibe::Sprite

Inherits:
Layer
  • Object
show all
Defined in:
lib/xibe.rb

Instance Attribute Summary collapse

Attributes inherited from Layer

#height, #visible, #width, #x, #y, #z

Instance Method Summary collapse

Methods inherited from Layer

#bottom, #hide, #left, #pos, #right, #show, #top

Constructor Details

#initialize(filename, width, height, transparent = false) ⇒ Sprite

Returns a new instance of Sprite.



572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# File 'lib/xibe.rb', line 572

def initialize(filename,width,height,transparent=false)
  super()
  @tiles = Image.to_tiles(filename, width, height, transparent)
  @width = width
  @height = height
  @frames = []
  @frame = 0
  @delay = 200
  @last_update = 0
  @direction = :right
  @visible = true
  @animate = true
  @tile
  @cmap
end

Instance Attribute Details

#animate=(value) ⇒ Object

Sets the attribute animate

Parameters:

  • value

    the value to set the attribute animate to.



571
572
573
# File 'lib/xibe.rb', line 571

def animate=(value)
  @animate = value
end

#delayObject

Returns the value of attribute delay.



570
571
572
# File 'lib/xibe.rb', line 570

def delay
  @delay
end

#directionObject

Returns the value of attribute direction.



570
571
572
# File 'lib/xibe.rb', line 570

def direction
  @direction
end

#framesObject

Returns the value of attribute frames.



570
571
572
# File 'lib/xibe.rb', line 570

def frames
  @frames
end

Instance Method Details

#drawObject

Draw sprite



616
617
618
619
620
# File 'lib/xibe.rb', line 616

def draw
  animate if @animate == true
  first_frame if @frames[@frame].nil?
  draw_tile(@tiles[@frames[@frame]], @x, @y) if @visible == true
end

#first_frameObject

Go to first frame



589
590
591
# File 'lib/xibe.rb', line 589

def first_frame
  @frame = 0
end

#go_frame(frame) ⇒ Object

Go to parameter frame



611
612
613
# File 'lib/xibe.rb', line 611

def go_frame(frame)
  @frame = frame
end

#last_frameObject

Go to last frame



594
595
596
# File 'lib/xibe.rb', line 594

def last_frame
  @frame = @frames.length - 1
end

#next_frameObject

Go to next frame



599
600
601
602
# File 'lib/xibe.rb', line 599

def next_frame
  @frame += 1
  first_frame if @frame > @frames.length - 1
end

#prev_frameObject

Go to previous frame



605
606
607
608
# File 'lib/xibe.rb', line 605

def prev_frame
  @frame -= 1
  last_frame if @frame < 0
end