Class: DXRubyRP5::RenderTarget
- Inherits:
-
Object
- Object
- DXRubyRP5::RenderTarget
- Defined in:
- lib/dxruby_rp5/render_target.rb
Instance Attribute Summary collapse
-
#_surface ⇒ Object
readonly
Returns the value of attribute _surface.
-
#bgcolor ⇒ Object
Returns the value of attribute bgcolor.
Instance Method Summary collapse
- #draw(x, y, image, z = 0) ⇒ Object
- #draw_font(x, y, string, font, hash = {}) ⇒ Object (also: #drawFont)
- #draw_tile(basex, basey, map, image_arr, startx, starty, sizex, sizey, z = 0) ⇒ Object (also: #drawTile)
- #height ⇒ Object
-
#initialize(width, height, _bgcolor = [0, 255, 255, 255]) ⇒ RenderTarget
constructor
A new instance of RenderTarget.
- #update ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(width, height, _bgcolor = [0, 255, 255, 255]) ⇒ RenderTarget
Returns a new instance of RenderTarget.
7 8 9 10 11 12 |
# File 'lib/dxruby_rp5/render_target.rb', line 7 def initialize(width, height, _bgcolor = [0, 255, 255, 255]) _bgcolor = to_rp5_color(_bgcolor) @bgcolor = $app.color(*_bgcolor) @_surface = $app.create_graphics(width, height) @queue = [] end |
Instance Attribute Details
#_surface ⇒ Object (readonly)
Returns the value of attribute _surface.
5 6 7 |
# File 'lib/dxruby_rp5/render_target.rb', line 5 def _surface @_surface end |
#bgcolor ⇒ Object
Returns the value of attribute bgcolor.
4 5 6 |
# File 'lib/dxruby_rp5/render_target.rb', line 4 def bgcolor @bgcolor end |
Instance Method Details
#draw(x, y, image, z = 0) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/dxruby_rp5/render_target.rb', line 41 def draw(x, y, image, z = 0) return if image.nil? draw_task = { :proc => lambda { @_surface.image(image._surface, x, y) }, :z => z } @queue << draw_task end |
#draw_font(x, y, string, font, hash = {}) ⇒ Object Also known as: drawFont
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/dxruby_rp5/render_target.rb', line 50 def draw_font(x, y, string, font, hash = {}) if string.empty? return end if hash[:color] color = $app.color(*hash[:color]) else color = $app.color(255) end proc = lambda do @_surface.push_matrix @_surface.text_size(font.size) @_surface.text_font(font.native) # DXRubyでは文字の配置指定はできないため、都度text_alignを指定 # せず固定で良いかもしれない @_surface.text_align(Processing::App::LEFT, Processing::App::TOP) @_surface.fill(color) string.lines.each.with_index do |line, i| line.chomp! if line.empty? next end @_surface.text(string, x, y) end @_surface.pop_matrix end draw_task = { :proc => proc, :z => hash[:z] || 0, } @queue << draw_task end |
#draw_tile(basex, basey, map, image_arr, startx, starty, sizex, sizey, z = 0) ⇒ Object Also known as: drawTile
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/dxruby_rp5/render_target.rb', line 85 def draw_tile(basex, basey, map, image_arr, startx, starty, sizex, sizey, z = 0) image_arr = image_arr.flatten first_img = image_arr[0] w, h = first_img.width, first_img.height startx_mod_w = startx % w starty_mod_h = starty % h from_i = starty_mod_h < 0 ? -1 : 0 to_i = sizey + (starty_mod_h <= 0 ? 0 : 1) from_j = startx_mod_w < 0 ? -1 : 0 to_j = sizex + (startx_mod_w <= 0 ? 0 : 1) y = basey - (starty_mod_h < 0 ? h + starty_mod_h : starty_mod_h) init_x = basex - (startx_mod_w < 0 ? w + startx_mod_w : startx_mod_w) (from_i..to_i).each do |i| if (i + starty / h) < 0 my = (((i + starty / h) % map.size) + map.size) % map.size else my = (i + starty / h) % map.size end map_row = map[my] x = init_x (from_j..to_j).each do |j| if (j + startx / w) < 0 mx = (((j + startx / w) % map_row.size) + map_row.size) % map_row.size else mx = (j + startx / w) % map_row.size end idx = map_row[mx] map_img = image_arr[idx] self.draw(x, y, map_img, z) x += w end y += h end end |
#height ⇒ Object
18 19 20 |
# File 'lib/dxruby_rp5/render_target.rb', line 18 def height return @_surface.height end |
#update ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/dxruby_rp5/render_target.rb', line 31 def update @_surface.begin_draw() @_surface.background(@bgcolor) @queue.sort { |a, b| a[:z] <=> b[:z] }.each do |task| task[:proc].call end @queue.clear @_surface.end_draw() end |
#width ⇒ Object
14 15 16 |
# File 'lib/dxruby_rp5/render_target.rb', line 14 def width return @_surface.width end |