My brother is trying to get something he made in Pygame to work in Ren'Py and he wanted to ask some questions.
--- So I would like to take advantage of some of Ren'Py's features for a project however I'm running into a couple basic issues that I'll need to understand before I even know how viable it is to take this approach.
I have been able to figure out how to get pygame to take over the display (that's no trick really) but I'm having a much harder time figuring out how to hand the display back to the original settings afterward. I could redo much of the code I already have to use Ren'Py type scripting but that would nullify some of the purpose of this. I have tried to experiment with having the pygame script not take over the screen but just draw on it but I run into the second problem. (as a note: what I've tried was using a pygame.surface.fill( ) which didn't work because the Ren'Py display is OpenGl by default and pygame.surface.blit( ) which is where the second problem came in.
The second problem involves renderables. For some reason I'm having a hard time getting the pygame script to load images through Ren'Py. I can define the image in the Ren'Py script and it knows how to work with it but whether I try to pass it to the normal Python script or try to load the image in the Pygame script with pygame.image.load( ) it can't seem to handle it. I've seen some examples of things which use some of the guts of the rendering system and I could probably work my way through that but I'd rather not if there's a simpler way to do things.
I rather get the idea that Ren'Py was not meant to be used the way I'm trying to use it but I'm wondering if more knowledgeable people could either confirm that or point me in a direction that would make it seem more viable. ---
Pygame script in Ren'Py
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
- Darkmoonfire
- Regular
- Posts: 103
- Joined: Mon Apr 25, 2011 6:41 am
- Completed: Christmas Project
- Organization: Lunarescent Wings
- Tumblr: darkmoonfire
- Contact:
-
- Regular
- Posts: 42
- Joined: Sat Mar 31, 2012 2:56 pm
- Location: projectexist.net
- Contact:
Re: Pygame script in Ren'Py
Read up on Renpygame here.
Get Renpygame here.
Although your brother is going to want to add the following lines to the top of script.rpy:
After doing that, he's going to want to scan through both script.rpy and aliens.py. Even if he'd rather not use Renpygame, at least he will be able to see how "going back to Ren'Py from Pygame" works.
Get Renpygame here.
Although your brother is going to want to add the following lines to the top of script.rpy:
Code: Select all
init python hide:
import pygame
pygame.font.init()
- Darkmoonfire
- Regular
- Posts: 103
- Joined: Mon Apr 25, 2011 6:41 am
- Completed: Christmas Project
- Organization: Lunarescent Wings
- Tumblr: darkmoonfire
- Contact:
Re: Pygame script in Ren'Py
Thanks for your help. My brother was able to get things working, although he had to use GIFs instead of PNGs because it was having trouble loading those in. Apparently they required some extended images module that he couldn't find.
- Darkmoonfire
- Regular
- Posts: 103
- Joined: Mon Apr 25, 2011 6:41 am
- Completed: Christmas Project
- Organization: Lunarescent Wings
- Tumblr: darkmoonfire
- Contact:
Re: Pygame script in Ren'Py
So how do you get PNGs to work in renpygame? It seems odd that they wouldn't since they work both renpy and pygame.
Re: Pygame script in Ren'Py
I generally avoid giving advice on using pygame in Ren'Py because in 99.9% of all cases you'd be better off taking python logic from pygame code and using Ren'Py's screen language/udds to handle displaying stuff... + we'd have more basecode for Ren'Py if it's something interesting if you're willing to share
Otherwise you just load pngs with pygame.image.load(os.path to the image). No libraries should be missing.
Otherwise you just load pngs with pygame.image.load(os.path to the image). No libraries should be missing.
-
- Veteran
- Posts: 253
- Joined: Fri Nov 14, 2008 7:59 pm
- Completed: Lots.
- Projects: Black Closet
- Organization: Slipshod
- Location: Behind you.
- Contact:
Re: Pygame script in Ren'Py
There are two approaches to this - you can set your game to always run in software mode (by setting the renderer preference in an init block or by modifying Ren'Py, for instance) and then you'll be able to mess with the screen in software mode. Alternatively, you can have the pygame code draw to a Displayable - something likeDarkmoonfire's brother wrote:I have been able to figure out how to get pygame to take over the display (that's no trick really) but I'm having a much harder time figuring out how to hand the display back to the original settings afterward. I could redo much of the code I already have to use Ren'Py type scripting but that would nullify some of the purpose of this. I have tried to experiment with having the pygame script not take over the screen but just draw on it but I run into the second problem. (as a note: what I've tried was using a pygame.surface.fill( ) which didn't work because the Ren'Py display is OpenGl by default and pygame.surface.blit( ) which is where the second problem came in.
Code: Select all
init python:
class Forcefield617(renpy.display.core.Displayable):
def render(self, width, height, st, at):
ret = renpy.display.render.Render(width, height)
surf = renpy.display.pgrender.surface((800,600), True)
# do all your pygame manipulations to surf.
ret.blit(surf,(0,0))
renpy.redraw(self, 0.02) # Only redraw if your displayable's animated
return ret
image whatever = Forcefield617()
label start:
show whatever
You probably want something like renpy.display.im.cache.get(im.Image('fnords.png')) - which returns a Pygame surface and, AFAIK, takes advantage of the image cache.Darkmoonfire's brother wrote:The second problem involves renderables. For some reason I'm having a hard time getting the pygame script to load images through Ren'Py. I can define the image in the Ren'Py script and it knows how to work with it but whether I try to pass it to the normal Python script or try to load the image in the Pygame script with pygame.image.load( ) it can't seem to handle it. I've seen some examples of things which use some of the guts of the rendering system and I could probably work my way through that but I'd rather not if there's a simpler way to do things.
Nom nom nom nom nom LEAVES.
Who is online
Users browsing this forum: Bing [Bot], Donmai, Google [Bot], LittleRainySeasons