-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update cube3d.py #112
base: master
Are you sure you want to change the base?
Update cube3d.py #112
Conversation
In this modified version, I removed the elif event.type == hapi.pygame.MOUSEBUTTONUP block and the draging = False line from that block. Additionally, I removed the try, except, else, and finally blocks, as they weren't necessary for the suggested modification. Now, the pygame.QUIT event is directly handled in the event loop, and if that event is detected, it sets hapi.is_running to False and breaks out of the loop. This should provide a cleaner and more direct exit mechanism when the quit button is pressed.
@TheBigKahuna353 Is it fixed? |
Yes i have changed it you can check it in the commits |
|
||
pmouseX = hapi.mouseX() | ||
pmouseY = hapi.mouseY() | ||
|
||
for event in hapi.pygame.event.get(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hooman handles events itself and it is bad in pygame to call this function twice in the same loop. What you can do is create a function called def handle_event(event)
or similar and then update hooman of this by hapi.handle_events = handle_event
.
for event in hapi.pygame.event.get(): | ||
if event.type == hapi.pygame.QUIT: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using above comment, this becomes unnecessary as hooman does this
see hooman.event_loop() to see the actual hooman code so you know what i mean.
# for i in range(8): | ||
# hapi.ellipse( 50+ points[i].x, 50+ points[i].y, 5, 5) | ||
|
||
pmouseX = hapi.mouseX() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you forgot to keep these 2 lines, very crucial as this variable is the previous mouse position
for event in hapi.pygame.event.get(): | ||
if event.type == hapi.pygame.QUIT: | ||
hapi.is_running = False | ||
break | ||
|
||
if event.type == hapi.pygame.KEYDOWN: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can remove this, it doesnt do anything
break | ||
|
||
elif event.type == hapi.pygame.MOUSEBUTTONUP: | ||
draging = False | ||
|
||
elif event.type == hapi.pygame.MOUSEMOTION: | ||
if dragging: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of using MOUSEBUTTONUP and MOUSEBUTTONDOWN events to see if the mouse is dragging, you could change this line to if hapi.pygame.mouse.get_pressed()[0]:
In this modified version, I removed the elif event.type == hapi.pygame.MOUSEBUTTONUP block and the draging = False line from that block. Additionally, I removed the try, except, else, and finally blocks, as they weren't necessary for the suggested modification.
Now, the pygame.QUIT event is directly handled in the event loop, and if that event is detected, it sets hapi.is_running to False and breaks out of the loop. This should provide a cleaner and more direct exit mechanism when the quit button is pressed.