Skip to content

Commit b9fe167

Browse files
committed
物理课的突发奇想直接导致我做出了双缓冲
1 parent 3796df2 commit b9fe167

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/engine.rb

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,7 @@ def initialize
4848
print tk_initialize_information
4949
eval tk_initialize_information
5050
end
51-
# noinspection RubyResolve
52-
canvas_initialize_information = <<END
53-
place(
54-
'x' => 0,
55-
'y' => 0,
56-
'width' => #{@game_bounds[2]},
57-
'height' => #{@game_bounds[3]}
58-
)
59-
END
60-
# noinspection RubyResolve
61-
@canvas = TkCanvas.new(@root) do
62-
print canvas_initialize_information
63-
eval canvas_initialize_information
64-
end
51+
@canvas = new_canvas
6552
# super do
6653
# on_init
6754
# end
@@ -89,6 +76,23 @@ def initialize
8976
Tk.mainloop
9077
end
9178

79+
def new_canvas
80+
# noinspection RubyResolve
81+
canvas_initialize_information = <<END
82+
place(
83+
'x' => 0,
84+
'y' => 0,
85+
'width' => #{@game_bounds[2]},
86+
'height' => #{@game_bounds[3]}
87+
)
88+
END
89+
# noinspection RubyResolve
90+
return TkCanvas.new(@root) do
91+
print canvas_initialize_information
92+
eval canvas_initialize_information
93+
end
94+
end
95+
9296
def bounds(x, y, width, height)
9397
@game_bounds[0] = x
9498
@game_bounds[1] = y
@@ -116,6 +120,7 @@ def message_box(msg = 'information',
116120
end
117121

118122
def draw_everything
123+
@canvas = new_canvas
119124
clear_screen
120125
@objs.each do |o|
121126
if o.is_a? FObject
@@ -241,6 +246,7 @@ def clear_time_listeners
241246
:clear_time_listeners,
242247
:clear_screen
243248

244-
private :draw_everything
249+
private :draw_everything,
250+
:new_canvas
245251

246252
end

0 commit comments

Comments
 (0)