Skip to content

Commit 14eaea5

Browse files
Jason L Perrycpowell
authored andcommitted
Prevent application from exiting while running as a jar
1 parent 3f7da4c commit 14eaea5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

bin/main.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,13 @@
5151
cfg.useGL20 = true
5252
cfg.width = 640
5353
cfg.height = 480
54-
LwjglApplication.new(MyGame.new, cfg)
54+
55+
game = MyGame.new
56+
57+
LwjglApplication.new(game, cfg)
58+
59+
# Prevent application from exiting while running as a jar
60+
while game.is_running
61+
sleep(1)
62+
end
63+

lib/ruby/my_game.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
class MyGame < Game
1414
include ApplicationListener
1515

16-
attr_reader :game_clock
16+
attr_reader :game_clock, :is_running
1717

1818
GAME_CLOCK_MULTIPLIER=1
1919

20+
def initialize
21+
@is_running = true
22+
end
23+
2024
def create
2125
@game_clock = Time.utc(2000,"jan",1,20,15,1)
2226

@@ -28,4 +32,7 @@ def increment_game_clock(seconds)
2832
@game_clock += (seconds)
2933
end
3034

35+
def dispose
36+
@is_running = false
37+
end
3138
end

0 commit comments

Comments
 (0)