[SOLVED]Show images above a screen?

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
User avatar
Alera
Miko-Class Veteran
Posts: 651
Joined: Sun Mar 21, 2010 3:20 am
Completed: Tortichki // Zayay // Hero's Spirit
Deviantart: psyalera
itch: psyalera
Location: UK
Contact:

[SOLVED]Show images above a screen?

#1 Post by Alera »

I have a few screens and I get how to control the overlay of those with zorder but what about when I want to have an image to appear over them? More particular an image which is on a layer? The image is using a complex(for me) Python code so I don't know how to 'add' it under a screen so I could use zorder again and I'm pretty lost. I'll just post my code I guess, I hope you'll get what I'm trying to do?

Code: Select all

# Controls the movement of the image according to the mouse position using layers
init 800 python:
    class MouseParallax(renpy.Displayable):
        def __init__(self,layer_info):
            super(renpy.Displayable,self).__init__()
            self.xoffset,self.yoffset=0.0,0.0
            self.sort_layer=sorted(layer_info,reverse=True)
            cflayer=[]
            masteryet=False
            for m,n in self.sort_layer:
                if(not masteryet)and(m<0):
                    cflayer.append("master")
                    masteryet=True
                cflayer.append(n)
            if not masteryet:
                cflayer.append("master")
            cflayer.extend(["transient","screens","overlay"])
            config.layers=cflayer
            config.overlay_functions.append(self.overlay)
            return
        def render(self,width,height,st,at):
            return renpy.Render(width,height)
        def parallax(self,m):
            def trans(d,st,at):
                d.xoffset,d.yoffset=(int)(m*self.xoffset),0
                return 0
            return Transform(function=trans)
        def overlay(self):
            ui.add(self)
            for m,n in self.sort_layer:
                renpy.layer_at_list([self.parallax(m)],n)
            return
        def event(self,ev,x,y,st):
            import pygame
            if ev.type==pygame.MOUSEMOTION:
                self.xoffset,self.yoffset=((float)(x)/(config.screen_width))-0.5,((float)(y)/(config.screen_height))-0.5
            return
    MouseParallax([(100,"farback"),(50,"back"),(-80,"front"),(-280,"ontop")])

#screens
screen buttons:
    zorder 1
    vbox xalign 0.5 yalign 0.5:
        imagebutton auto "monster_%s.png" action ShowMenu('save') focus_mask True
       
# The game starts here.
label start:
    show bg
    show screen buttons 
    show zei onlayer ontop
It's probably a simple solution, but I just can't figure it out on my own. Help?
Last edited by Alera on Wed Feb 05, 2014 7:41 pm, edited 1 time in total.
Image
Games:
❤️ Zayay [Otome?][BxPlayer][NaNo 2013]
❤️ Tortichki [Drag&Drop mini game]

Other games I've worked on:
My Heart's Flame Emissary of Starlight Freedom From Silence Sickness
And many more unannounced/secret projects. (. .)

KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Show images above a screen?

#2 Post by KimiYoriBaka »

the first solution that comes to mind is to add a screen adds images based on a list, but I'm not sure if renpy's prediction would still work.

if you want to try that, it would be something like this:

Code: Select all

screen top_images:
    for i in imagelist:
        add i[0]:
            pos i[1]

label start:
    $ imagelist = [["zei.png", (0.5, 0.0)]]
    show bg
    show screen buttons
    show screen top_images

User avatar
Alera
Miko-Class Veteran
Posts: 651
Joined: Sun Mar 21, 2010 3:20 am
Completed: Tortichki // Zayay // Hero's Spirit
Deviantart: psyalera
itch: psyalera
Location: UK
Contact:

Re: Show images above a screen?

#3 Post by Alera »

@KimiYoriBaka
Hmmm, strangely, with this my image doesn't show up at all. Or maybe I'm missing something? I don't get any errors. :'<
Image
Games:
❤️ Zayay [Otome?][BxPlayer][NaNo 2013]
❤️ Tortichki [Drag&Drop mini game]

Other games I've worked on:
My Heart's Flame Emissary of Starlight Freedom From Silence Sickness
And many more unannounced/secret projects. (. .)

KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Show images above a screen?

#4 Post by KimiYoriBaka »

that's strange. did you try using zorder on the new screen as well?

User avatar
Alera
Miko-Class Veteran
Posts: 651
Joined: Sun Mar 21, 2010 3:20 am
Completed: Tortichki // Zayay // Hero's Spirit
Deviantart: psyalera
itch: psyalera
Location: UK
Contact:

Re: Show images above a screen?

#5 Post by Alera »

Oh, I'm sorry I mislead you, I got it to display and zorder works, my mistake, but how do I make it so it so uses my layer? I want to use my mouse movement thing on it.

That code alone is still quite useful though, thank you~
Image
Games:
❤️ Zayay [Otome?][BxPlayer][NaNo 2013]
❤️ Tortichki [Drag&Drop mini game]

Other games I've worked on:
My Heart's Flame Emissary of Starlight Freedom From Silence Sickness
And many more unannounced/secret projects. (. .)

KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Show images above a screen?

#6 Post by KimiYoriBaka »

Assuming I'm reading your code correctly, having images with parallax on top of the screens would require having another set of layers that are added to config.layers after the default ones.

if that is correct, then an adjustment like this would work:

Code: Select all

# Controls the movement of the image according to the mouse position using layers
init 800 python:
    class MouseParallax(renpy.Displayable):
        def __init__(self,layer_info, slayer_info):
            super(renpy.Displayable,self).__init__()
            self.xoffset,self.yoffset=0.0,0.0
            self.sort_layer=sorted(layer_info,reverse=True)
            self.sort_slayer=sorted(slayer_info,reverse=True) #repeating the same formatting
            cflayer=[]
            masteryet=False
            for m,n in self.sort_layer:
                if(not masteryet)and(m<0):
                    cflayer.append("master")
                    masteryet=True
                cflayer.append(n)
            if not masteryet:
                cflayer.append("master")
            cflayer.extend(["transient","screens","overlay"])
            for m,n in self.sort_slayer:
                cflayer.append(n)     #adding them after screens so they'll be rendered on top
            config.layers=cflayer
            config.overlay_functions.append(self.overlay)
            return
        def render(self,width,height,st,at):
            return renpy.Render(width,height)
        def parallax(self,m):
            def trans(d,st,at):
                d.xoffset,d.yoffset=(int)(m*self.xoffset),0
                return 0
            return Transform(function=trans)
        def overlay(self):
            ui.add(self)
            for m,n in self.sort_layer:
                renpy.layer_at_list([self.parallax(m)],n)
            for m,n in self.sort_slayer:
                renpy.layer_at_list([self.parallax(m)],n) #not sure, but it looks like this would be needed
            return
        def event(self,ev,x,y,st):
            import pygame
            if ev.type==pygame.MOUSEMOTION:
                self.xoffset,self.yoffset=((float)(x)/(config.screen_width))-0.5,((float)(y)/(config.screen_height))-0.5
            return
    MouseParallax([(100,"farback"),(50,"back"),(-80,"front"),(-280,"ontop")], [(100,"sfarback"), (0, "smaster"), (50,"sback"),(-80,"sfront"),(-280,"sontop")]) 
    #adding layers with identical values and a slight difference in name

#screens
screen buttons:
    zorder 1
    vbox xalign 0.5 yalign 0.5:
        imagebutton auto "monster_%s.png" action ShowMenu('save') focus_mask True
       
# The game starts here.
label start:
    show bg
    show screen buttons 
    show zei onlayer sontop  #adding to the layer on top of the screens
(disclaimer: I haven't tested this, and I'm just going off of how your code appears to work)

User avatar
Alera
Miko-Class Veteran
Posts: 651
Joined: Sun Mar 21, 2010 3:20 am
Completed: Tortichki // Zayay // Hero's Spirit
Deviantart: psyalera
itch: psyalera
Location: UK
Contact:

Re: Show images above a screen?

#7 Post by Alera »

Wow, thank you!!! It finally worked!!! You're great >v<
Image
Games:
❤️ Zayay [Otome?][BxPlayer][NaNo 2013]
❤️ Tortichki [Drag&Drop mini game]

Other games I've worked on:
My Heart's Flame Emissary of Starlight Freedom From Silence Sickness
And many more unannounced/secret projects. (. .)

User avatar
Friar Tuck
Newbie
Posts: 11
Joined: Sat Apr 26, 2014 1:10 am
Projects: The Clockwork Diary with Copper Clasps
Contact:

Re: [SOLVED]Show images above a screen?

#8 Post by Friar Tuck »

Alera wrote:Wow, thank you!!! It finally worked!!! You're great >v<
How does it work? Without a complete example, I do not understand. Please help me.

Oh, sorry. I see this: http://lemmasoft.renai.us/forums/viewto ... 38#p293811
Its geat!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]