electronstudio / raylib-python-cffi

Python CFFI bindings for Raylib
http://electronstudio.github.io/raylib-python-cffi
Eclipse Public License 2.0
142 stars 29 forks source link

Escape triggers exit even after pr.set_exit_key(KEY_NULL) #62

Closed cratuki closed 2 years ago

cratuki commented 2 years ago

By default, when a user presses escape in raylib, the return status of pr.window_should_close() changes from False to True.

When we use pr.set_exit_key(KEY_NULL), escape should no longer do this. My experience on 4.0.0.6 is that escape still causes window_should_close to return True after my call to set_exit_key.

electronstudio commented 2 years ago

This program works as expected for me on Linux/Python 3.10.4:

from pyray import *
init_window(800, 450, "Hello")
set_exit_key(KEY_NULL)
while not window_should_close():
    begin_drawing()
    clear_background(WHITE)
    draw_text("Hello world", 190, 200, 20, VIOLET)
    end_drawing()
close_window()

What OS/Python are you on? Seems unlikely to be a Python specific issue, so I would also test Raylib itself in C to see if the problem is there.

cratuki commented 2 years ago

Your sample code worked on my machine. I have found the issue. The set_exit_key call must be after init_window to be effective. If it is made before init_window, init_window seems to stomp on it and re-set escape to be the exit key. Is this expected behaviour?

cratuki commented 2 years ago

I should have answered your question. I am on Linux, running Python 3.9.7.

electronstudio commented 2 years ago

Probably. I don't know, you would have to ask Raylib. Raylib Python CFFI is only a binding to Raylib.

cratuki commented 2 years ago

Thanks. Closing.