renpy/doc/cookbook/Creating a TV-static effect for background

From Ren'Py

Jump to: navigation, search

This is a nifty effect that I saw in Fate/stay night, so I wanted to replicate it in Ren'py. While I may have not replicated it exactly, it will surely add some flavor to your VNs if you use it when the situation demands it. Basically, here's what you do.

Open your favourite image editor of choice (mine is Photoshop), and make a new canvas with the size of the screen you're using for your game (let's say 800x600 is today's default). Use paint bucket to paint the canvas white, in case you created a transparent canvas. Now, we need a function called "Add Noise", so find it in your filter toolbar. Use monochromatic noise, and for these images I used uniform distribution with values around 50% (changed +/- .01 for each of the images). I got these five images.

Image 1
Image 2
Image 3
Image 4
Image 5

Now, as you see, each of them is a bit different than the other. Perfect! What we need to do next, is put all these in an anim.SMAnimation function to do us good. So let's define all five states and all the edges to make this animation fluid and non-stop. Like so...

image static = anim.SMAnimation("a",
        anim.State("a", "noise1.png"),
        anim.State("b", "noise2.png"),
        anim.State("c", "noise3.png"),
        anim.State("d", "noise4.png"),
        anim.State("e", "noise5.png"),

        anim.Edge("a", .2, "b", trans=Dissolve(.2, alpha=True)),
        anim.Edge("b", .2, "a", trans=Dissolve(.2, alpha=True)),
        anim.Edge("a", .2, "c", trans=Dissolve(.2, alpha=True)),
        anim.Edge("c", .2, "a", trans=Dissolve(.2, alpha=True)),
        anim.Edge("a", .2, "d", trans=Dissolve(.2, alpha=True)),
        anim.Edge("d", .2, "a", trans=Dissolve(.2, alpha=True)),
        anim.Edge("a", .2, "e", trans=Dissolve(.2, alpha=True)),
        anim.Edge("e", .2, "a", trans=Dissolve(.2, alpha=True)),

        anim.Edge("b", .2, "c", trans=Dissolve(.2, alpha=True)),
        anim.Edge("c", .2, "b", trans=Dissolve(.2, alpha=True)),
        anim.Edge("b", .2, "d", trans=Dissolve(.2, alpha=True)),
        anim.Edge("d", .2, "b", trans=Dissolve(.2, alpha=True)),
        anim.Edge("b", .2, "e", trans=Dissolve(.2, alpha=True)),
        anim.Edge("e", .2, "b", trans=Dissolve(.2, alpha=True)),

        anim.Edge("c", .2, "d", trans=Dissolve(.2, alpha=True)),
        anim.Edge("d", .2, "c", trans=Dissolve(.2, alpha=True)),
        anim.Edge("c", .2, "e", trans=Dissolve(.2, alpha=True)),
        anim.Edge("e", .2, "c", trans=Dissolve(.2, alpha=True)),

        anim.Edge("d", .2, "e", trans=Dissolve(.2, alpha=True)),
        anim.Edge("e", .2, "d", trans=Dissolve(.2, alpha=True)),
        )

Now that's some typing right there! :D I wanted to do dissolves rather than just showing images, that would look too coarse. This looks perfect, even though it might be a tad memory consumptive. If the static changes too slow for your taste, change the delay of the edge (the first number before "trans") to a lower value, like .15 or .1

To use this, you just call it like this whenever you wish to show static in-game.

show static


One last thing - remember that these images (if you followed my instructions blindly) are opaque, so nothing below the static will be visible! To change that, you can:

  • change layer transparency in your image editor (less flexible) - to something around 50% - before you save your noise images
  • use im.Alpha for every noise state before you load the images in SMAnimation (more flexible, as you can define static with various degrees of alpha for different situations in the game, but probably less memory-efficient)


So this was my first cookbook recipe, hope you like it! Thanks goes to FIA and PyTom for correcting the script, now everything will work if you use opacity changes with im.Alpha (or use transparent .pngs, but as I said, that's less flexible).


EvilDragon

Personal tools