Skip to content
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

Problem to import .pyx files #145

Closed
BlackRam-oss opened this issue Feb 18, 2023 · 6 comments
Closed

Problem to import .pyx files #145

BlackRam-oss opened this issue Feb 18, 2023 · 6 comments

Comments

@BlackRam-oss
Copy link

BlackRam-oss commented Feb 18, 2023

Hi, I was trying to import pygame_sdl2 into renpy project.
to do this i downloaded the library from here https://github.com/renpy/pygame_sdl2/tree/master/src/pygame_sdl2 (I failed with pip)
(I tried to follow the read me instructions, but I don't think they are up to date)

this works for py files, but not for pyx files.
checking in the init.py file.
I noticed that the compiler can't find the .pyx libraries.
image

i know what pyx files are, but i have never developed with it. searching a bit on the internet i realized that i had to add the Cython library,
image

but nothing changed.

could you give me some suggestions?

@renpytom
Copy link
Member

You should just be able to import pygame_sdl2 into Ren'Py with.

init python:
    import pygame_sdl2

@BlackRam-oss
Copy link
Author

BlackRam-oss commented Feb 18, 2023

yes it is true it is already within renpy, however this does not work

import pygame_sdl2 as pygame
pygame.import_as_pygame()
pygame._optional_imports()

def main():
    # Initialize pygame_sdl2
    pygame.init()

    pygame.mixer.get_init()

@BlackRam-oss
Copy link
Author

another problem is display.mode_ok

pygame.init()

bestdepth = pygame.display.mode_ok(600, 32, 32)
screen = pygame.display.set_mode(600, 32, bestdepth)

https://github.com/renpy/pygame_sdl2/blob/master/src/pygame_sdl2/display.pyx#L657

the function is this I don't understand why it gives me this error

image

@BlackRam-oss
Copy link
Author

@renpytom Sorry to insist, but I would like to understand if I am making a mistake in using this library or it is a possible implementation.

And if so, can I help in any way? (I don't specialize in python, but I work as a programmer)

I need to create Renpy minigames that already exist in pygame. this Issue would help me a lot

@mal
Copy link
Member

mal commented Feb 28, 2023

That traceback looks like a straight-forward Python error on your end. 600 is in integer, rather than a tuple representing a size.

I'd suggest reviewing the pygame documentation and updating your code to call these functions with valid arguments.

https://www.pygame.org/docs/ref/display.html#pygame.display.list_modes
https://www.pygame.org/docs/ref/display.html#pygame.display.mode_ok
https://www.pygame.org/docs/ref/display.html#pygame.display.set_mode

This doesn't appear to be an issue with renpy or pygame_sdl2.

@BlackRam-oss
Copy link
Author

@mal

Yes sorry you are right, I don't know why I was passing those parameters. in fact now display works.

the only thing is that i think the optional imports are not working. as shown in a previous comment. (although on these imports I am not essential, however if I know there is another way to import this would help me a lot)

import pygame_sdl2 as pygame
pygame.import_as_pygame()
pygame._optional_imports()

def main():
    # Initialize pygame_sdl2
    pygame.init()

    pygame.mixer.get_init()
While running game code:
  File "game/script.rpy", line 31, in script
    $ score = aliens.main()
  File "game/script.rpy", line 31, in script
    $ score = aliens.main()
  File "game/script.rpy", line 31, in <module>
    $ score = aliens.main()
NotImplementedError: Could not import pygame_sdl2.mixer: No module named 'pygame_sdl2.mixer'

Sorry to ask another question but it's the latest problem I have getting my little pygame to work on renpy that has been bugging me for a while.

ie: once i finish the game i don't know how to switch from pygame screen to renpy screen

#import basic pygame_sdl2 modules
import pygame_sdl2 as pygame
pygame.import_as_pygame()
pygame._optional_imports()

def main():
    # Initialize pygame_sdl2
    pygame.init()
    screen = pygame.display.set_mode((100,100), 32, 32)

    pygame.time.wait(1000)

    # * https://github.com/renpy/renpy/issues/4347
    # * renpytom tell me to use:
    renpy.display_reset()  # but not work

    # ! BOOM:
    renpy.call("start")

    return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants