Blinking Effect Question

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
ReAnimator
Regular
Posts: 64
Joined: Mon Dec 16, 2013 1:00 pm
Contact:

Blinking Effect Question

#1 Post by ReAnimator » Tue Aug 16, 2022 4:29 am

Hello.
I want this blinking animation to have fadein and out effect.
Currently trans.alpha is set to 1.0 and 0.0 respectively so it shows and hides instantly.
Is there any way to achieve this?

Code: Select all

init python:
    def show_op(trans, st, at):
        if st < 1 / x:
            trans.alpha = 1.0
            return 0
        else:
            return None

    def hide_op(trans, st, at):
        if st < 1 / x:
            trans.alpha = 0.0
            return 0
        else:
            return None

screen blinking():
    add Solid("#ffff"):
        at transform:
            function show_op
            function hide_op
            repeat
            
    timer 1.0 action SetVariable("x", x + 1) repeat True

label start:
    $ x = 1 
    show screen blinking
    "I want to add fadein and out effect to trans.alpha."
    return
    

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

Re: Blinking Effect Question

#2 Post by Imperf3kt » Tue Aug 16, 2022 6:17 am

you could use "on show" within the screen to add the transition.
https://www.renpy.org/doc/html/screens.html#on
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

ReAnimator
Regular
Posts: 64
Joined: Mon Dec 16, 2013 1:00 pm
Contact:

Re: Blinking Effect Question

#3 Post by ReAnimator » Tue Aug 16, 2022 11:48 am

Yeah,
To be exact I want it to look like attached video.
Can it be done with on show statement?
I really can't figure it out.
Attachments
Comp.zip
(9.88 KiB) Downloaded 2 times

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1843
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Blinking Effect Question

#4 Post by Ocelot » Tue Aug 16, 2022 1:26 pm

You can make a custom warper ( https://www.renpy.org/doc/html/atl.html ... -statement ) and use it in transform:

Code: Select all

init python:
    def Blink(repetitions):
        def blink(t):
            from math import pi, cos
            t = t * t * (pi * 2 * repetitions - pi)
            w = cos(t)
            return (w + 1) / 2 # [-1, 1] → [0, 1]
        return blink

define blink = Blink(20)

transform induce_seizure:
    alpha 1.0
    warp blink 10 alpha 0.0

screen blinking():
    add Solid("#ffff") at induce_seizure

label start:
    show screen blinking
    "I want to add fadein and out effect to trans.alpha."
    return
< < insert Rick Cook quote here > >

ReAnimator
Regular
Posts: 64
Joined: Mon Dec 16, 2013 1:00 pm
Contact:

Re: Blinking Effect Question

#5 Post by ReAnimator » Tue Aug 16, 2022 1:46 pm

Brilliant!
You know what, there's no way I can figure this out on my own. How can you do that, man... this makes me really sad... still no idea about that math code... lol
Thanks for your help. This is exactly I want.

User avatar
m_from_space
Veteran
Posts: 302
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Blinking Effect Question

#6 Post by m_from_space » Wed Aug 17, 2022 7:57 am

Ocelot wrote:
Tue Aug 16, 2022 1:26 pm
transform induce_seizure:
:lol: Thanks for the laugh.

Post Reply

Who is online

Users browsing this forum: No registered users