Dynamic Images

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
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.
Post Reply
Message
Author
pkt
Veteran
Posts: 322
Joined: Tue Jul 28, 2009 10:09 pm
Completed: I dunno
Projects: Something special
Contact:

Dynamic Images

#1 Post by pkt »

I'm working on a character maker program based on renpy. I need code to dynamically load images of a certain prefix and put them in a list so they can be addressed by number. Like head01.png-head32.png can be loaded at once. Head pic 32 called as $ head = 32 or something simple like that.
No Active Public Renpy Projects...

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Dynamic Images

#2 Post by JQuartz »

pkt wrote:I need code to dynamically load images of a certain prefix and put them in a list so they can be addressed by number. Like head01.png-head32.png can be loaded at once.
You can use for like so:

Code: Select all

label start:
    python:
        ui.vbox()
        for num in range(1, 33):
            if num>9:
                ui.image("head"+str(num)+".png")
            elif num<=9:
                ui.image("head0"+str(num)+".png")
        ui.close()
        renpy.pause()
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

pkt
Veteran
Posts: 322
Joined: Tue Jul 28, 2009 10:09 pm
Completed: I dunno
Projects: Something special
Contact:

Re: Dynamic Images

#3 Post by pkt »

Will said images need to be in the init as well?
No Active Public Renpy Projects...

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Dynamic Images

#4 Post by JQuartz »

pkt wrote:Will said images need to be in the init as well?
No.
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

pkt
Veteran
Posts: 322
Joined: Tue Jul 28, 2009 10:09 pm
Completed: I dunno
Projects: Something special
Contact:

Re: Dynamic Images

#5 Post by pkt »

It was somewhat going to use layers of different image sets like one for eyes another for hair and clothes and rotate a value based on button presses. There was going to be a color thing too. I'm a little used to C++ so it might look a little like this in that. I'm really rusty though.
Here's proto code

hair[hair_number,hair_color,hair_darkness]
if hair_number>=4
hair_number=0
...
if hair_number == 1
hair_01.png
if hair_number == 2
hair_02.png

but then wrap that in something to call the hair as a variable
then process the color in and value in as well.

Yeah I know it looks horrible but hoping it helps.
No Active Public Renpy Projects...

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Dynamic Images

#6 Post by JQuartz »

pkt wrote:It was somewhat going to use layers of different image sets like one for eyes another for hair and clothes and rotate a value based on button presses
I don't really get what exactly you meant but maybe it is something like this:

Code: Select all

init:
    $ hair_number=1
    
label select_hair:
    python:
        if hair_number>=4:
            hair_number=0

        
        ui.vbox()
        ui.textbutton("Next", ui.jumps("next_hair"))
        ui.image("hair_0"+str(hair_number)+".png")
        ui.close()
        ui.interact()
        
        
        
label next_hair:
    $ hair_number+=1
    jump select_hair
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

pkt
Veteran
Posts: 322
Joined: Tue Jul 28, 2009 10:09 pm
Completed: I dunno
Projects: Something special
Contact:

Re: Dynamic Images

#7 Post by pkt »

This code was needed to get my recode of the character maker working. So far everything but changing colors works now. That's the last frontier.
No Active Public Renpy Projects...

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Dynamic Images

#8 Post by JQuartz »

You can try using im.MatrixColor to change the color like so:

Code: Select all

init:
    $ hair_number=1
    $ valueb=0
   

label select_hair:
    python:
        if hair_number>=4:
            hair_number=0

       
        ui.vbox()
        ui.textbutton("Add valueb", ui.jumps("add_valueb"))
        ui.textbutton("Reduce valueb", ui.jumps("reduce_valueb"))
        ui.textbutton("Next", ui.jumps("next_hair"))
        ui.image(im.MatrixColor("s_image"+str(hair_number)+".png",
       [ -1,  valueb,  0, 0, 1,
          0, -1,  0, 0, 1,
          0,  0, -1, 0, 1,
          0,  0,  0, 1, 0, ]))   #set the other value in the matrix as variable
        ui.close()
        ui.interact()
       
       
       
label next_hair:
    $ hair_number+=1
    jump select_hair
    
label add_valueb:
    $ valueb+=1
    jump select_hair
    
label reduce_valueb:
    $ valueb-=1
    jump select_hair
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

pkt
Veteran
Posts: 322
Joined: Tue Jul 28, 2009 10:09 pm
Completed: I dunno
Projects: Something special
Contact:

Re: Dynamic Images

#9 Post by pkt »

Here's the script.rpy. So far none of the Matrix things worked for me with ui image. It's for a character maker thing.
Attachments
script.rpy
(3.72 KiB) Downloaded 36 times
No Active Public Renpy Projects...

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Dynamic Images

#10 Post by JQuartz »

pkt wrote:So far none of the Matrix things worked for me with ui image
Try this then:

Code: Select all

init:
    $ hair_number=1
    $ valueb=0
   
label start:
    pass
label select_hair:
    python:
        if hair_number>=4:
            hair_number=0

       
        ui.vbox()
        ui.textbutton("Add valueb", ui.jumps("add_valueb"))
        ui.textbutton("Reduce valueb", ui.jumps("reduce_valueb"))
        ui.textbutton("Next", ui.jumps("next_hair"))
        ui.image(im.MatrixColor("hair_0"+str(hair_number)+".png", im.matrix.hue(valueb)))
        ui.close()
        ui.interact()
       
       
       
label next_hair:
    $ hair_number+=1
    jump select_hair
    
label add_valueb:
    $ valueb+=10
    jump select_hair
    
label reduce_valueb:
    $ valueb-=10
    jump select_hair
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

pkt
Veteran
Posts: 322
Joined: Tue Jul 28, 2009 10:09 pm
Completed: I dunno
Projects: Something special
Contact:

Re: Dynamic Images

#11 Post by pkt »

Thanks, I know it's late and all but this code was a life saver and I finally got it to work.
No Active Public Renpy Projects...

Post Reply

Who is online

Users browsing this forum: No registered users