Lemma Soft Forums

Supporting creators of visual novels and story-based games since 2003.


Visit our new games list, blog aggregator, IRC, and wiki.
Activation problem? Email [email protected]
It is currently Wed May 22, 2013 6:36 am

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Fri Jul 27, 2012 4:41 pm 
Veteran
User avatar

Joined: Thu Jun 09, 2011 8:14 pm
Posts: 220
edit : note that since 6.10.0 you have an automatic simple version of this by enabling this config http://renpy.org/wiki/renpy/doc/referen ... tic_images
The code below allows you to have control on the thing and to adapt it to your needs.

Starting with Ren'py itself but old in general coding, I thought it was a bit bothering sometimes to have to write exactly the same thing in the pictures names and then in the code. Like "image Satria embarassed = 'img/Satria/embarassed.png" : two time nearly the same thing, in coding, is bad... it needs to be improved.

Data path and variable names looking that similar... a lot of time can surely be earned.

Code:
init python hide:

    for file in renpy.list_files():
        if file.startswith('img/'):
            if file.endswith('.png'):
                name = file.replace('img/','').replace('/', ' ').replace('.png','')
                renpy.image(name, Image(file, yanchor=400))
                continue
            continue


Replace img by your image directory (or the directory where you want Ren'py to use images to make variables). You have to use some conventions in naming files but it works for every picture (sprites, BG, CG, ...).

In short: it takes every files in the directory you want, and see if they are PNG files (you can change the extension too). Then it takes the path of the file and build the image variable from it. "img/Satria/upside_down.png" wille create a "Satria upside_down", "img/CG/black_night.png" will do a "CG black_night".


With that in your directory : http://puu.sh/MfYT http://puu.sh/MfV0
It will avoid you to write these lines :
Code:
image Satria embarassed = 'img/Satria/embarassed.png"
image Satria upside_down = 'img/Satria/upside_down.png"
etc...



An other advantage is that you just have to add a picture to your directory and you can already use it in your code.

_________________
Image
Seeking creativity, mostly on the music side of things.
http://soundcloud.com/ziassan


Last edited by Ziassan on Sat Sep 15, 2012 12:32 pm, edited 6 times in total.

Top
 Profile Send private message  
 
PostPosted: Sat Jul 28, 2012 12:45 pm 
Miko-Class Veteran
User avatar

Joined: Mon Dec 13, 2010 9:30 am
Posts: 842
Location: New Brunswick, Canada
Projects: Camp Renard
Sweet!

Thank you!

Susan

_________________
In order to understand recursion, one must first understand recursion. (Anonymous)


Top
 Profile Send private message  
 
PostPosted: Sat Jul 28, 2012 3:27 pm 
Eileen-Class Veteran
User avatar

Joined: Fri Mar 09, 2012 6:58 pm
Posts: 1157
Location: United States
Projects: Coming Out On Top
OMG, this is awesome Ziassan. Thanks for sharing!

_________________
Coming Out On Top - An Adult B/B Game
Wordpress Tumblr Twitter FB


Top
 Profile Send private message  
 
PostPosted: Mon Jul 30, 2012 11:17 am 
Miko-Class Veteran
User avatar

Joined: Fri Mar 16, 2012 11:38 am
Posts: 924
Location: Tokyo, Japan
Projects: Untitled Japanese study game
Organization: Pure Anarchy
Wow, I can't tell you how useful this will be. And easy to use too!

_________________
Working on a VN to teach lower-conversational Japanese, and a guide to living in Japan.
It's a very long dev process.

You could help me with my game A LOT by filling out this anonymous 10 question survey: http://www.surveymonkey.com/s/6GR57YB
Massive thanks to everyone who has already filled it out!
You can see a Q&A about the survey here: http://tinyurl.com/SurveyQandA


Top
 Profile Send private message  
 
PostPosted: Mon Jul 30, 2012 1:25 pm 
Eileen-Class Veteran
User avatar

Joined: Fri Jun 05, 2009 3:31 am
Posts: 1595
Location: Illinois, USA
Projects: Twelve
Organization: Kitsch-soft
Correct me if I'm wrong, but isn't Ren'Py set up this way so that it can load all the images at the start of the game so that the game works faster in the end? I thought I read that somewhere...

_________________
“When I stand before God at the end of my life,
Aspiring writer-artist.

I would hope that I would not have a single bit of talent left,
and could say, 'I used everything you gave me.'”
— Erma Bombeck

▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬▬
Works in Progress
Twelve - love story of an A.I. and her programmer
PAW ★ PRINTS - Laika in the Space with Tetris


Top
 Profile Send private message  
 
PostPosted: Mon Jul 30, 2012 1:53 pm 
Veteran
User avatar

Joined: Thu Jun 09, 2011 8:14 pm
Posts: 220
Hmm does that make a difference ? I mean, the code I wrote makes pretty much the same thing than declaring the images normally.
This line "renpy.image(name, Image(file, yanchor=400))" is the equivalent of the "image" thing. The difference is that here, I'm building the images declarations from the names of the data directly.

_________________
Image
Seeking creativity, mostly on the music side of things.
http://soundcloud.com/ziassan


Top
 Profile Send private message  
 
PostPosted: Mon Jul 30, 2012 1:59 pm 
Veteran
User avatar

Joined: Thu Jan 28, 2010 2:31 am
Posts: 289
Location: Singapore
Completed: Culina: The Spirit of Cooking
Projects: Love at the Laundromat, Culina: Hands in the Kitchen
Organization: Moustachio Studios
Just learned about this about a week ago. Python is so cool with having access to doing stuff like this. Great find!

_________________

Technical Designer/Programmer
Game Design Portfolio - Project updates on my Twitter - Check out my 2D Platformer: Lunaris
Experienced in: C/C++, Python, Unreal, Unity, and Flash
_________________
"Space can be very lonely. The greatest adventure is having someone share it with you."


Top
 Profile Send private message  
 
PostPosted: Mon Jul 30, 2012 5:34 pm 
Eileen-Class Veteran
User avatar

Joined: Fri Jun 05, 2009 3:31 am
Posts: 1595
Location: Illinois, USA
Projects: Twelve
Organization: Kitsch-soft
Ziassan wrote:
Hmm does that make a difference ? I mean, the code I wrote makes pretty much the same thing than declaring the images normally.
This line "renpy.image(name, Image(file, yanchor=400))" is the equivalent of the "image" thing. The difference is that here, I'm building the images declarations from the names of the data directly.

Oh, I'm sorry. That does make sense. (I feel so dumb...)
Now that I know this, I will probably use your code so thanks in advance :)

_________________
“When I stand before God at the end of my life,
Aspiring writer-artist.

I would hope that I would not have a single bit of talent left,
and could say, 'I used everything you gave me.'”
— Erma Bombeck

▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬▬
Works in Progress
Twelve - love story of an A.I. and her programmer
PAW ★ PRINTS - Laika in the Space with Tetris


Top
 Profile Send private message  
 
PostPosted: Sat Sep 08, 2012 1:01 pm 
Newbie
User avatar

Joined: Mon Aug 13, 2012 10:54 am
Posts: 3
Projects: Fate/Protocol VI
Not working if file or folder names contains numbers.
Nevermind, just forgot that a number should not be first character.


Top
 Profile Send private message  
 
PostPosted: Sat Sep 15, 2012 10:17 am 
Newbie
User avatar

Joined: Tue Jun 05, 2012 8:35 pm
Posts: 14
Projects: Salty Tears
Organization: Salty Salty Studios
This has been in Ren'Py itself since version 6.10.0 already: http://renpy.org/wiki/renpy/doc/referen ... tic_images


Top
 Profile Send private message  
 
PostPosted: Sat Sep 15, 2012 10:31 am 
Veteran
User avatar

Joined: Thu Jun 09, 2011 8:14 pm
Posts: 220
Oh, indeed, I wonder how many people knew about it.

Well I'll still leave my code as it allows more flexibility and controle if someone wants to do something specific about that. But thanks, I'll edit the first post about that.

_________________
Image
Seeking creativity, mostly on the music side of things.
http://soundcloud.com/ziassan


Top
 Profile Send private message  
 
PostPosted: Sat Sep 15, 2012 12:04 pm 
Ren'Py Creator
User avatar

Joined: Mon Feb 02, 2004 10:58 am
Posts: 10774
Location: Kings Park, NY
Completed: Moonlight Walks
Projects: Ren'Py
Ziassan's method is probably better than the built in one, as it gives far more control. The built-in method predates me making renpy.list_files() public - if the archive format had been opened up earlier, there never would have been a config.automatic_images.

_________________
Another Old-Fashioned Bishoujo Gamer
Supporting creators since 2004; Code > Drama
(When was the last time you backed up your game?)
"It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face in marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming" - Theodore Roosevelt


Top
 Profile Send private message  
 
PostPosted: Fri Mar 29, 2013 1:04 am 
Veteran
User avatar

Joined: Sun Oct 09, 2011 11:15 pm
Posts: 390
Projects: Dream's Dénouement
Organization: Team ANARKY
If anyone needs flipped sprites (facing the other way) as well:
Code:
init python hide:
    for file in renpy.list_files():
        if (file.startswith('sprites/')) and (file.endswith('.png')):
            name = file.replace('sprites/','').replace('/', ' ').replace('.png','')
            name_flipped = name + ' flip'
            renpy.image(name, Image(file, yalign=1.0))
            renpy.image(name_flipped, im.Flip(Image(file), horizontal=True, yalign=1.0))

_________________
Image Free hosting or website for your VN


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Protected by Anti-Spam ACP
Powered by phpBB® Forum Software © phpBB Group