Class: PandaCanvas::AnimationCanvas

Inherits:
Gosu::Window
  • Object
show all
Includes:
DrawingMethods
Defined in:
lib/panda_canvas/animation_canvas.rb

Overview

AnimationCanvas is a subclassed Gosu::Window that is used for animation.

Constant Summary

Constants included from DrawingMethods

DrawingMethods::CANVAS_CALLS, DrawingMethods::CANVAS_UPDATE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DrawingMethods

#font, #sym_color, #text, #text_rel

Constructor Details

#initialize(width, height, &block) ⇒ AnimationCanvas

Creates a new canvas window with dimensions width and height. A block is passed to be executed.



13
14
15
16
17
18
19
20
# File 'lib/panda_canvas/animation_canvas.rb', line 13

def initialize(width, height, &block)
  super(width, height, false)
  self.caption = 'Panda Canvas'
  @block = block
  @image = TexPlay.create_image(self, width, height)
  @agent = DrawingAgent.new(self, @image)
  @agent.frame = 0
end

Instance Attribute Details

#imageObject (readonly)

TexPlay image, which is drawn in the window.



9
10
11
# File 'lib/panda_canvas/animation_canvas.rb', line 9

def image
  @image
end

Instance Method Details

#drawObject

Draws the image in memory.



23
24
25
26
# File 'lib/panda_canvas/animation_canvas.rb', line 23

def draw
  @image.draw(0, 0, 0)
  @agent.canvas_calls.each {|call| send call[0], *call[1..-1] }
end

#updateObject

Runs an animation block.



29
30
31
32
33
34
35
# File 'lib/panda_canvas/animation_canvas.rb', line 29

def update
  @image.rect 0, 0, width, height, :color => :black, :fill => true
  DrawingMethods::CANVAS_UPDATE.each {|call| send call[0], *call[1..-1] }
  @agent.canvas_calls = []
  @agent.frame += 1
  @agent.instance_eval &@block
end