diff --git a/gym/envs/box2d/car_racing.py b/gym/envs/box2d/car_racing.py index 55864138e68..b146fac50d2 100644 --- a/gym/envs/box2d/car_racing.py +++ b/gym/envs/box2d/car_racing.py @@ -383,7 +383,7 @@ def render(self, mode='human'): self.human_render = True win.clear() t = self.transform - gl.glViewport(0, 0, WINDOW_W, WINDOW_H) + gl.glViewport(0, 0, 2 * WINDOW_W, 2 * WINDOW_H) t.enable() self.render_road() for geom in self.viewer.onetime_geoms: @@ -391,6 +391,7 @@ def render(self, mode='human'): t.disable() self.render_indicators(WINDOW_W, WINDOW_H) win.flip() + return self.viewer.isopen self.viewer.onetime_geoms = [] return arr @@ -472,12 +473,14 @@ def key_release(k, mod): if k==key.DOWN: a[2] = 0 env = CarRacing() env.render() - record_video = False - if record_video: - env.monitor.start('/tmp/video-test', force=True) env.viewer.window.on_key_press = key_press env.viewer.window.on_key_release = key_release - while True: + record_video = False + if record_video: + from gym.wrappers.monitor import Monitor + env = Monitor(env, '/tmp/video-test', force=True) + isopen = True + while isopen: env.reset() total_reward = 0.0 steps = 0 @@ -492,7 +495,6 @@ def key_release(k, mod): #plt.imshow(s) #plt.savefig("test.jpeg") steps += 1 - if not record_video: # Faster, but you can as well call env.render() every time to play full window. - env.render() - if done or restart: break + isopen = env.render() + if done or restart or isopen == False: break env.close()