Reputation: 2814
For the past couple of days, I have been playing around in the Ursina Engine in Python, used for creating both 3D and 2D games. But the recurring problem I have been facing with this engine when making 3D games, is that I can't close the window properly. This is happening because mouse is being used inside of the game, to control the player, so if I try to go to the close button, the mouse will always stay in the game. The workaround for this is to move to a different window, position the mouse so it's outside of the window, and then finally hit the close button. But this is a lot of work for the user to do, to simply close the window.
Here is some simple code to demonstrate:
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
import random
game = Ursina()
class Block(Button):
def __init__(self, position = (0,0,0)):
super().__init__(parent = scene, position = position, model = 'cube', color = color.white)
for z in range(20):
for x in range(20):
block = Block(position = (x, 0, z))
player = FirstPersonController()
game.run()
I believe this import statement is causing this:
from ursina.prefabs.first_person_controller import FirstPersonController
How can I close the window properly in Ursina?
Upvotes: 3
Views: 3419
Reputation: 1
You could try moving the existing Exit button elsewhere, and creating your own custom Exit button, that is located where you want it and allows a clean exit by the player.
from ursina import*
app = Ursina()
# move Exit button off the screen
window.exit_button.x = -10000
# declare a new exit button
exit = Button(
text = "X",
scale = 0.05,
model = "cube",
color = color.red)
exit.y = 0.45
exit.x = 0.8
def input(key):
if key == "left mouse down" and mouse.hovered_entity == exit:
quit()
app.run()
Upvotes: 0
Reputation: 227
Just disable the FPC (First Person Controller)
player.disable()
or just
make the mouse unlocked mouse.locked = False
, so it can move
Upvotes: 0
Reputation: 109
One solution to this problem would be to create a way for you to exit the game by pressing a key.
def input(key):
if key == 'escape':
quit()
With this code you can close the game by pressing 'escape'.
Upvotes: 6
Reputation: 1489
Quick solution, Shift+Q (if the exit_button is enabled).
Usually in first person shooters you make a pause menu and put an exit button there. The FirstPersonController hides the mouse cursor and locks the position to the center of the screen. To reverse this, do:
mouse.locked = False
mouse.visible = True
Upvotes: 4
Reputation: 117
I usually press the "Windows" key. Pressing this button open the windows menu, but it also makes the mouse visible.
Another tip, you can put:
window.exit_button.visible = False
In your code to make it easier to close the window.
Upvotes: 2