Instant CG and BG gallery

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
leon
Miko-Class Veteran
Posts: 554
Joined: Sun Oct 09, 2011 11:15 pm
Completed: Visual Novel Tycoon, Night at the Hospital, Time Labyrinth, The Buried Moon, Left of Center, Super Otome Quest
Projects: Lemon Project, Porcelain Heart, Dream's Dénouement
Organization: Team ANARKY
Contact:

Re: Instant CG and BG gallery

#61 Post by leon »

To but a background behind, just list 2 displayables:

Code: Select all

g_cg.image("#000", gal_item)
To center/position the CG you can use im.Composite:

Code: Select all

g_cg.image(im.Composite((1280, 720), (0,0), "black.jpg", (200,200), ImageReference(gal_item)))

Mitula
Newbie
Posts: 8
Joined: Sun Mar 10, 2013 1:19 pm
Contact:

Re: Instant CG and BG gallery

#62 Post by Mitula »

Thank you!

With the first solution, I have a background that appears.
Contrariwise, the second made ​​me the following error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While executing init code:
  File "game/gallery.rpy", line 7, in script
  File "game/gallery.rpy", line 41, in python
Exception: Expected an image, but got a general displayable.

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "C:\Users\Seven\Downloads\renpy-6.17.1-sdk\renpy\execution.py", line 294, in run
    node.execute()
  File "C:\Users\Seven\Downloads\renpy-6.17.1-sdk\renpy\ast.py", line 732, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\Seven\Downloads\renpy-6.17.1-sdk\renpy\python.py", line 1358, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/gallery.rpy", line 41, in <module>
    g_cg.image(im.Composite((1024, 768), (0,0), "black.jpg", (200,200), ImageReference(gal_item)))
  File "C:\Users\Seven\Downloads\renpy-6.17.1-sdk\renpy\display\im.py", line 596, in __init__
    self.images = [ image(i) for i in args[1::2] ]
  File "C:\Users\Seven\Downloads\renpy-6.17.1-sdk\renpy\display\im.py", line 1534, in image
    return image(arg.target, loose=loose, **properties)
  File "C:\Users\Seven\Downloads\renpy-6.17.1-sdk\renpy\display\im.py", line 1549, in image
    raise Exception("Expected an image, but got a general displayable.")
Exception: Expected an image, but got a general displayable.

Windows-7-6.1.7601-SP1
Ren'Py 6.17.1.309

User avatar
leon
Miko-Class Veteran
Posts: 554
Joined: Sun Oct 09, 2011 11:15 pm
Completed: Visual Novel Tycoon, Night at the Hospital, Time Labyrinth, The Buried Moon, Left of Center, Super Otome Quest
Projects: Lemon Project, Porcelain Heart, Dream's Dénouement
Organization: Team ANARKY
Contact:

Re: Instant CG and BG gallery

#63 Post by leon »

Have you added an image called black.jpg to your game folder? Check the documentation for im.Composite or try it with LiveComposite if that doesn't work.

Code: Select all

g_cg.image(LiveComposite((1280, 720), (0,0), "#000", (200,200), gal_item))

Mitula
Newbie
Posts: 8
Joined: Sun Mar 10, 2013 1:19 pm
Contact:

Re: Instant CG and BG gallery

#64 Post by Mitula »

Super ! It works perfectly !
Again thank you for your advice

FrostGem
Newbie
Posts: 1
Joined: Sat Mar 08, 2014 11:59 am
Contact:

Re: Instant CG and BG gallery

#65 Post by FrostGem »

Hi!

Thank you very much for the code it works really well :).

This may be an odd request but is it possible to reset the gallery, like re-lock the images. You see I'd need to demonstrate that it works when I have to show this at college so I need to re-lock the image to show it unlocks at the right time.

User avatar
leon
Miko-Class Veteran
Posts: 554
Joined: Sun Oct 09, 2011 11:15 pm
Completed: Visual Novel Tycoon, Night at the Hospital, Time Labyrinth, The Buried Moon, Left of Center, Super Otome Quest
Projects: Lemon Project, Porcelain Heart, Dream's Dénouement
Organization: Team ANARKY
Contact:

Re: Instant CG and BG gallery

#66 Post by leon »

Click on "delete persistent" in Ren'Py launcher.

kirbysuperstar
Newbie
Posts: 10
Joined: Fri Jan 18, 2013 9:11 pm
Contact:

Re: Instant CG and BG gallery

#67 Post by kirbysuperstar »

Is there a way to make this work with automatically defined images, at all? I can't seem to get it to, it just throws up the Expected image, got general displayable error.

User avatar
leon
Miko-Class Veteran
Posts: 554
Joined: Sun Oct 09, 2011 11:15 pm
Completed: Visual Novel Tycoon, Night at the Hospital, Time Labyrinth, The Buried Moon, Left of Center, Super Otome Quest
Projects: Lemon Project, Porcelain Heart, Dream's Dénouement
Organization: Team ANARKY
Contact:

Re: Instant CG and BG gallery

#68 Post by leon »

It should work fine with automatically defined images. Try putting the part where you define the images in init -1.

kirbysuperstar
Newbie
Posts: 10
Joined: Fri Jan 18, 2013 9:11 pm
Contact:

Re: Instant CG and BG gallery

#69 Post by kirbysuperstar »

You mean the #Gallery Settings section? I only ask because as I'm having Renpy define everything for me, there is no image definition section.

User avatar
leon
Miko-Class Veteran
Posts: 554
Joined: Sun Oct 09, 2011 11:15 pm
Completed: Visual Novel Tycoon, Night at the Hospital, Time Labyrinth, The Buried Moon, Left of Center, Super Otome Quest
Projects: Lemon Project, Porcelain Heart, Dream's Dénouement
Organization: Team ANARKY
Contact:

Re: Instant CG and BG gallery

#70 Post by leon »

You could try using this code and add -1 to the init clause.

kirbysuperstar
Newbie
Posts: 10
Joined: Fri Jan 18, 2013 9:11 pm
Contact:

Re: Instant CG and BG gallery

#71 Post by kirbysuperstar »

Heeeey that worked beautifully, thanks a bunch!

tsubame-chi
Newbie
Posts: 12
Joined: Mon Feb 03, 2014 2:18 am
Projects: Chosen Ghost
Organization: JACT Productions
Location: United States
Contact:

Re: Instant CG and BG gallery

#72 Post by tsubame-chi »

Omg. At first, I tried to use this a couple of times and I couldn't figure out how to use it. But, I read the comments from others and found out! Yey! I was stuck with the image error thingy the whole time and couldn't figure it out until I found out that there was this tiny typo in the part where I define the images. GAH.

Thank you so much, though! It definitely helped me out a lot! :)

User avatar
chickenhearted
Regular
Posts: 25
Joined: Fri Apr 04, 2014 1:18 am
Projects: Romancin Dudes(GxB)
Organization: chickandnugget
Tumblr: chickandnugget
Location: St. PigeoNation's
Contact:

Re: Instant CG and BG gallery

#73 Post by chickenhearted »

I've been struggling with my lack of coding knowledge to get a CG gallery working, but this actually worked easily!

Celebratory dancing is in order~ :DD

Much thanks!
Image

User avatar
TheOneAndOnly-K
Regular
Posts: 78
Joined: Mon Apr 07, 2014 10:33 am
Contact:

Re: Instant CG and BG gallery

#74 Post by TheOneAndOnly-K »

*sigh*

You've heard this problem many a time, yet it's just not fixing for me.

I'm unsure whether it's because I have to define images in the screens or in the 'script' but here we go.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While executing init code:
  File "game/screens.rpy", line 646, in script
  File "game/screens.rpy", line 649, in python
Exception: Expected an image, but got a general displayable.

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "C:\Users\Mam\Downloads\Fish\Renpy\renpy\execution.py", line 294, in run
    node.execute()
  File "C:\Users\Mam\Downloads\Fish\Renpy\renpy\ast.py", line 732, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\Mam\Downloads\Fish\Renpy\renpy\python.py", line 1382, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/screens.rpy", line 649, in <module>
    renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))
  File "C:\Users\Mam\Downloads\Fish\Renpy\renpy\display\im.py", line 643, in __init__
    im = image(im)
  File "C:\Users\Mam\Downloads\Fish\Renpy\renpy\display\im.py", line 1536, in image
    return image(arg.target, loose=loose, **properties)
  File "C:\Users\Mam\Downloads\Fish\Renpy\renpy\display\im.py", line 1551, in image
    raise Exception("Expected an image, but got a general displayable.")
Exception: Expected an image, but got a general displayable.

Windows-7-6.1.7601-SP1
Ren'Py 6.17.4.409
 
This is the scripting...

Code: Select all

################################################################

init python:
    #Galleries settings - start
    #list the CG gallery images here:
    gallery_cg_items = ["apartment", "arcade"]
    #how many rows and columns in the gallery screens?
    gal_rows = 3
    gal_cols = 3
    #thumbnail size in pixels:
    thumbnail_x = 267
    thumbnail_y = 150
    #the setting above (267x150) will work well with 16:9 screen ratio. Make sure to adjust it, if your are using 4:3 or something else.
    #Galleries settings - end
    
    gal_cells = gal_rows * gal_cols    
    g_cg = Gallery()
    for gal_item in gallery_cg_items:
        g_cg.button(gal_item + " butt")
        g_cg.image(gal_item)
        g_cg.unlock(gal_item)
    g_cg.transition = fade
    cg_page=0
    
init +1 python:
    #Here we create the thumbnails. We create a grayscale thumbnail image for BGs, but we use a special "locked" image for CGs to prevent spoilers.
    for gal_item in gallery_cg_items:
        renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))
        
screen cg_gallery:
    tag menu
    use navigation
    frame background None xpos 10:
        grid gal_rows gal_cols:
            ypos 10
            $ i = 0
            $ next_cg_page = cg_page + 1            
            if next_cg_page > int(len(gallery_cg_items)/gal_cells):
                $ next_cg_page = 0
            for gal_item in gallery_cg_items:
                $ i += 1
                if i <= (cg_page+1)*gal_cells and i>cg_page*gal_cells:
                    add g_cg.make_button(gal_item + " butt", gal_item + " png", im.Scale("gallocked.png", thumbnail_x, thumbnail_y), xalign=0.5, yalign=0.5, idle_border=None, background=None, bottom_margin=24)
            for j in range(i, (cg_page+1)*gal_cells): #we need this to fully fill the grid
                null
        frame:
            yalign 0.97
            vbox:
                if len(gallery_cg_items)>gal_cells:
                    textbutton _("Next Page") action [SetVariable('cg_page', next_cg_page), ShowMenu("cg_gallery")]
Help please...

User avatar
leon
Miko-Class Veteran
Posts: 554
Joined: Sun Oct 09, 2011 11:15 pm
Completed: Visual Novel Tycoon, Night at the Hospital, Time Labyrinth, The Buried Moon, Left of Center, Super Otome Quest
Projects: Lemon Project, Porcelain Heart, Dream's Dénouement
Organization: Team ANARKY
Contact:

Re: Instant CG and BG gallery

#75 Post by leon »

As a quick fix you can just replace this:

Code: Select all

init +1 python:
    #Here we create the thumbnails. We create a grayscale thumbnail image for BGs, but we use a special "locked" image for CGs to prevent spoilers.
    for gal_item in gallery_cg_items:
        renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))
with this:

Code: Select all

init +1 python:
    renpy.image ("apartment butt", im.Scale("apartment.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("arcade butt", im.Scale("arcade.jpg", thumbnail_x, thumbnail_y))

Post Reply

Who is online

Users browsing this forum: No registered users