Playing Snow animation on Title 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
feisty_wizard
Newbie
Posts: 12
Joined: Sun Jul 16, 2017 10:41 am
Tumblr: feisty-wizard
itch: feisty-wizard
Contact:

Playing Snow animation on Title Screen?

#1 Post by feisty_wizard » Wed Feb 07, 2018 3:42 am

I've figured out how to use and make the snow particle effect for my VN during the game but I'd also like to add it to the title screen. I don't know if it's possible, i've already tried placing it in a few areas in the gui trying to get it to work.

sorry if it's a terrible question. I actually don't know anything about basic coding and somehow have been able to get by with guessing.


EDIT:
another thing that might be super easy but I can't figure out is how to center the text on my title screen.

Image

i just want the words to be centered with each other so it looks nicer

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Playing Snow animation on Title Screen?

#2 Post by Imperf3kt » Wed Feb 07, 2018 6:00 am

Without some code examples, I can only guess how you use whatever you are using.
I can, however, suggest that for the buttons you are using a vbox? Try adding (or changing to) xalign 0.5 before the textbuttons, but inside the vbox.

Code: Select all

screen navigation():
    tag menu
    #### whatever else is here
    
    vbox:
        xalign 0.5
        
        textbutton _("Start") action Start()
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

User avatar
Donmai
Eileen-Class Veteran
Posts: 1919
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
Projects: Slumberland
Location: Brazil
Contact:

Re: Playing Snow animation on Title Screen?

#3 Post by Donmai » Wed Feb 07, 2018 8:50 am

Maybe are you trying to use the show statement? The example script for the snow effect is something like this:

Code: Select all

init:
    image snow = Snow("snowflake.png")

label start:
    show snow
    "Hey, look! It's snowing."
That's an old script, but it works. To show the snow on a screen like the main menu you can't use the show statement. You have to use the add statement to put an image on a screen. Try this on the main menu section of your screens.rpy:

Code: Select all

screen main_menu():

    ## This ensures that any other menu screen is replaced.
    tag menu

    style_prefix "main_menu"

    add gui.main_menu_background
    add "snow"
Image
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

User avatar
feisty_wizard
Newbie
Posts: 12
Joined: Sun Jul 16, 2017 10:41 am
Tumblr: feisty-wizard
itch: feisty-wizard
Contact:

Re: Playing Snow animation on Title Screen?

#4 Post by feisty_wizard » Wed Feb 07, 2018 2:40 pm

Sorry Here's the code I use for snow:

Code: Select all

##Snow##

init python:

    import random

    random.seed()

    def Snow(image, max_particles=25, speed=100, wind=100, xborder=(0,30), yborder=(0,30), **kwargs):

        return Particles(SnowFactory(image, max_particles, speed, wind, xborder, yborder, **kwargs))

    class SnowFactory(object):
        def __init__(self, image, max_particles, speed, wind, xborder, yborder, **kwargs):
            self.max_particles = max_particles
            self.speed = speed
            self.wind = wind

            self.xborder = xborder
            self.yborder = yborder

            self.depth = kwargs.get("depth", 10)

            self.image = self.image_init(image)

        def create(self, particles, st):

            if particles is None or len(particles) < self.max_particles:

                depth = random.randint(1, self.depth)
                depth_speed = 1.5-depth/(self.depth+0.0)

                return [ SnowParticle(self.image[depth-1],      # the image used by the particle
                                      random.uniform(-self.wind, self.wind)*depth_speed,  # wind's force
                                      self.speed*depth_speed,  # the vertical speed of the particle
                                      random.randint(self.xborder[0], self.xborder[1]), # horizontal border
                                      random.randint(self.yborder[0], self.yborder[1]), # vertical border
                                      ) ]

        def image_init(self, image):
            rv = [ ]

            for depth in range(self.depth):
                p = 1.1 - depth/(self.depth+0.0)
                if p > 1:
                    p = 1.0

                rv.append( im.FactorScale( im.Alpha(image, p), p ) )

            return rv

        def predict(self):
            return self.image

    class SnowParticle(object):
        def __init__(self, image, wind, speed, xborder, yborder):

            self.image = image

            if speed <= 0:
                speed = 1

            self.wind = wind
            self.speed = speed
            self.oldst = None

            self.xpos = random.uniform(0-xborder, renpy.config.screen_width+xborder)
            self.ypos = -yborder


        def update(self, st):

            if self.oldst is None:
                self.oldst = st

            lag = st - self.oldst
            self.oldst = st

            self.xpos += lag * self.wind
            self.ypos += lag * self.speed

            if self.ypos > renpy.config.screen_height or\
               (self.wind< 0 and self.xpos < 0) or (self.wind > 0 and self.xpos > renpy.config.screen_width):
                return None

            return int(self.xpos), int(self.ypos), st, self.image
and I have to use this statement to make it work when I want it in a scene:

Code: Select all

  init:
    image snow = Snow("snow.png")
    
   show snow    
I tried changing it to add snow but it didnt work. I think my main problem is I don't know WHERE to properly put all the code. I tried adding the snow script at the top of my screens.rpy, right under the exsisting init script.

Image
(right under that one line)

and I tried adding the second part of the code under "tag Menu" and when that didnt work I moved it under "window:"

this is the code for that section (removed snow code so you could see what I already have more easily)

Code: Select all

screen main_menu():

    # This ensures that any other menu screen is replaced.
    tag menu

    # The background of the main menu.
    window:
    
        style "main_menu"
        
        add gui.main_menu_background


    # The main menu buttons.
    frame:
        style_group "mm"
        xalign .52
        yalign .60

        has vbox

        textbutton _("Start Game") action Start()
        textbutton _("Load Game") action ShowMenu("load")
        textbutton _("Preferences") action ShowMenu("preferences")
        textbutton _("Help") action Help()
        textbutton _("Quit") action Quit(confirm=False)

init -2:

    # Make all the main menu buttons be the same size.
    style mm_button:
        size_group "mm"
I also couldnt get the words to center? I tried adding "xalign .5" after "has vbox" and it didnt do anything.

thanks in advance like so so much!! I guess im not good at learning code stuff myself haha

User avatar
feisty_wizard
Newbie
Posts: 12
Joined: Sun Jul 16, 2017 10:41 am
Tumblr: feisty-wizard
itch: feisty-wizard
Contact:

Re: Playing Snow animation on Title Screen?

#5 Post by feisty_wizard » Thu Feb 08, 2018 4:42 pm

booping

User avatar
solarProtag
Regular
Posts: 37
Joined: Sun May 28, 2017 12:17 am
Completed: http://solarprotag.weebly.com/gamedev.html
Projects: Battle Live Series
Tumblr: solarasketchbook
itch: solarprotagonist
Contact:

Re: Playing Snow animation on Title Screen?

#6 Post by solarProtag » Thu Feb 08, 2018 6:36 pm

Try adding an xalign 0.5 to each textbutton like this

Code: Select all

textbutton "Start" action Start() xalign 0.5
textbutton "Load" action ShowMenu("load") xalign 0.5
textbutton "Preferences" action ShowMenu("preferences") xalign 0.5
textbutton "Help" action ShowMenu("help") xalign 0.5
textbutton "About" action ShowMenu("about") xalign 0.5
textbutton "Quit" action Quit(confirm=not main_menu) xalign 0.5
I also recommend defining the "snow" image next to the code for your main menu, like for example underneath the "style main_menu" stuff on the main menu section in "screens.rpy" you add the "image snow = Snow("snow.png")". That's how I added the main menu logos onto my games.

User avatar
Donmai
Eileen-Class Veteran
Posts: 1919
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
Projects: Slumberland
Location: Brazil
Contact:

Re: Playing Snow animation on Title Screen?

#7 Post by Donmai » Thu Feb 08, 2018 8:04 pm

Okay, now that solarProtag kindly answered your second question, let's revisit the first one. I've already answered that question but I can understand your confusion. That said, the snow routine is python code. There's no "right" place to put it, but the best option is to create a separate rpy file and put that code there. Give it the name snow.rpy and drop it in your project folder. Put this line at the start of script.rpy

Code: Select all

image snow = Snow("images/snow.png")
Make sure you have a png image named "snow.png" in your images folder (I've attached one to this post in case you need it). The only thing you need to do now is what I've already shown you:

Code: Select all

screen main_menu():

    ## This ensures that any other menu screen is replaced.
    tag menu

    style_prefix "main_menu"

    add gui.main_menu_background
    add "snow" # <------ add this line to your main menu screen code
Attachments
snow.png
snow.png (242 Bytes) Viewed 1156 times
Image
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

User avatar
feisty_wizard
Newbie
Posts: 12
Joined: Sun Jul 16, 2017 10:41 am
Tumblr: feisty-wizard
itch: feisty-wizard
Contact:

Re: Playing Snow animation on Title Screen?

#8 Post by feisty_wizard » Fri Feb 09, 2018 6:00 pm

okay so finally got the snow to work so thanks so much!! the words still don't align right but like...ya know I can live with that lol I probably did the code for the vbox kinda wierd or something

it still turned out super nice so I really appreciate all of yalls help! <3
Image

Post Reply

Who is online

Users browsing this forum: Google [Bot]