Anna-Lischen
Anna-Lischen

Reputation: 878

Is it possible to display a pygame Minigame in renpy displayable?

I have tried something like that:

screen backgroundGame():
    default backgroundGameDisp = backgroundGameDisplayable()
    add Solid("#394387") # dark blue
    add backgroundGameDisp

init python:

    import math
    import pygame
    #from pygame.locals import *

    class backgroundGameDisplayable(renpy.Displayable):
        def __init__(self):
            super(backgroundGameDisplayable, self).__init__()
        def render(self, width, height, st, at):
            render = renpy.Render(width, height)
            return render
            
        def event(self, ev, x, y, st):
            print("CLASS WORKS! Coords are, x", str(x), "y:", str(y))
            pygame.init()

            widthGame = 1000
            heightGame = 1000

            screem = pygame.display.set_mode((widthGame, heightGame))
            pygame.display.set_caption("TEST")

            run = True
            while run:

                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        run = False
            pygame.quit()

        def per_interact(self):
            pass
        def visit(self):
            return []                     

Here's the script.rpy file:

define e = Character('Eileen', color="#c8ffc8")


label start:

    scene bg room

    show eileen happy

    e "bla"

    call screen backgroundGame

    e "bla2"

    return

When I run the project like this firstly Renpy game appears, than it is replaced with a pygame window, while I want that pygame thing to appear within the displayable. What am I doing wrong?

Upvotes: 2

Views: 1006

Answers (1)

Rabbid76
Rabbid76

Reputation: 211230

It is not a good idea to mix frame materials. The frameworks may interact poorly with each other or conflict completely. If it works on your (operating) system, that doesn't mean it will work on another (operating) system or with a different version of one of the frameworks. Mixing frameworks always means some kind of undefined behavior.
Pygame is known to work poorly with other frameworks on different systems. e.g. Embedding a Pygame window into a Tkinter or WxPython frame

Upvotes: 0

Related Questions