Ren'Py memo

Ren'Pyの個人的なメモ

ボイスが鳴っている間だけ口を動かす

参照:Can Lip Flap Be Synched (Sync / Synced) With Voice [solved] - Lemma Soft Forums


python earlyの置き場所:initの下じゃないところ できれば一番上に置く
* and _preferences.get_mute("voice") == Falseはボイスミュートの際に口パクを行わないためのコード 動かしたい場合は該当のコードを消してください

python early:

    # https://lemmasoft.renai.us/forums/viewtopic.php?t=25399
    speaking = None

    def while_speaking(names, speak_d, done_d, st, at):
        if renpy.music.is_playing('voice') and speaking == names and _preferences.get_mute("voice") == False:
            return speak_d, .1
        else:
            return done_d, None

    curried_while_speaking = renpy.curry(while_speaking)

    def WhileSpeaking(names, speaking_d, done_d=Null()):
        curried_while_speaking = renpy.curry(while_speaking)
        return DynamicDisplayable(curried_while_speaking(names, speaking_d, done_d))

    def speaker_callback(names, event, **kwargs):
        global speaking
        speaking = names

    speaker = renpy.curry(speaker_callback)

Character

 define b = Character(_('スーくん'), voice_tag="b", callback=speaker("b"), image="1")


口パクアニメーションの指定

    image 1_talk:
        "1_c_c1" #閉じ口
        choice:
            pause 0.1
        choice:
            pause 0.05
        choice:
            pause 0.01
        "1_c_c6" #中間口
        pause 0.1
        "1_c_c7" #大きく開ける口
        pause 0.1
        repeat

layeredimage

 #キャラクター変数名、口パクアニメーション名、最後に表示される口の画像
    image 1_m1 = WhileSpeaking("b", "1_talk", "1_c_c1.png") 
    image 1_m2 = WhileSpeaking("b", "1_talk", "1_c_c2.png")
    image 1_m3 = WhileSpeaking("b", "1_talk", "1_c_c3.png")
    image 1_m4 = WhileSpeaking("b", "1_talk", "1_c_c4.png")
    image 1_m5 = WhileSpeaking("b", "1_talk", "1_c_c5.png")

    layeredimage 1:
        always "1_base"

        group a:
            attribute a1 default
            attribute a2
            attribute a3
            attribute a4
        group b:
            attribute b1 default
            attribute b2
        group c:
            attribute c0 default
            attribute c1
            attribute c2
            attribute c3
            attribute c4
            attribute c5
            attribute c6
            attribute c7
        group e:
            attribute e0 default
            attribute e1:
                "1_m1"
            attribute e2:
                "1_m2"
            attribute e3:
                "1_m3"
            attribute e4:
                "1_m4"
            attribute e5:
                "1_m5"
        group d:
            attribute d1 default
            attribute d2

使用例

    show 1 a1 b1 e3 with dissolve

Ren'Pyで作った矩形を角丸シェーダーで丸くする

角丸ボタン
内容説明
  • MITライセンス
  • 画像の角丸化はできません
  • Solidにのみ使用できます(Solidの説明:Displayable — Ren'Py Documentation
  • 角丸をどれだけ丸くするかの設定、アウトラインの太さ、色の変更ができます
導入手順
  1. A Frame displayable which has rounds off corners using shaders. · GitHubからrpyファイルをダウンロード(コピペまたはRaw->名前を付けて保存、txtではなくrpyの拡張子で)
  2. rpyファイルをgameフォルダに入れる
使い方
image color1 = RoundedFrame(Solid("#fff"), radius=20.0, outline_width=1.5, outline_color="#000")

Solid("#fff"):中身の色
radius:丸める半径の数値を指定(0.0~50.0ぐらい)
outline_witdh:アウトラインの太さ
outline_color:アウトラインの色

使用例

style window:
    yalign 0.9
    xpos 228
    xsize 890
    ysize 240
    background "color1"

style music_button:
    activate_sound "audio/se/switchblade2.mp3"
    idle_background "color1"
    hover_background "color2"
    selected_background "color2"
    xsize 360
    ysize 80
    padding (5,5,5,5)

itchページをつくる自分用メモ

自分用メモ

  • 見出しと本文のGooglefontは分けられる
  • 画像を使ってもいい
プロジェクトのメタデータを入れておく
  • Classification(操作方式・プレイ時間・言語・エンジン)
  • Promo images(SNSで表示される画像指定、真四角指定favicon画像)
プロジェクトの編集で忘れやすいこと
  • カバー画像(検索一覧で表示されるサムネイル)の推奨は630x500
  • ブラウザ版を埋め込んでいる場合、指定したViewport幅にページが横に伸びる
  • タグ付け忘れない(どんなタグをつけていいかわからない時は類似ゲームを参考にする)
  • ファイル一覧のfor~の後のアイコンを選択する(デフォルトは未選択)

とりあえずページに必要な要素

続きを読む

ゲーム内に外部リンクのボタンを作る

この例ではitch.ioの評価画面とコメント欄を開くボタンを作ります。

誤タッチがあるかもしれないのでConfirmでYes/Noのワンクッションを置きます。

        textbutton _(" Rate this game "):
            action Confirm(_("ブラウザでitch.ioの評価画面を開きます。\nよろしいですか?"), OpenURL("https://p6ik.itch.io/yamedomo/rate?source=game"))
        null width 50
        textbutton _(" Leave a comment "):
            action Confirm(_("ブラウザでitch.ioのコメント欄を開きます。\nよろしいですか?"), OpenURL("https://p6ik.itch.io/yamedomo/comments"))

itch.ioの評価URL:プロジェクトURLの末尾に/rate?source=game
itch.ioのコメントURL:プロジェクトURLの末尾に/comments

・置き場所がない場合はタイトルに置くといいかもしれません
・各SNSのリンクを張ってもいいかも
・itch.ioで公開していない場合はメールフォームでもいいかも

変更したpersistent変数を元に戻すボタン

元に戻すボタンの例

presistent変数:永続変数。

数値を変更する例のコード

        hbox:
            style_prefix "slider"
            label _("ウインドウ透明度\n{size=-3}(← 淡  濃 →){/size}")
            bar value FieldValue(persistent, 'window_alpha', 1.0, max_is_zero=False, offset=0, step=1) released Play("sound", gsound1) xsize 560 ysize 60 ypos 10
            null width 20

変更したpersistent変数を元に戻すボタン

            textbutton _("元に戻す"):
                action SetVariable("persistent.window_alpha", 0.95)
                xsize 150
                text_xalign 0.5

プレイヤーがバーなどで変更できる数値を、
デフォルトの数値(任意)に戻すボタンを作りたい時に。
xsize、text_xalignは関係ありません。

ブラウザ版では変数が保存されるタイミングがセーブなので(現在、おそらく)
オプションで変更してからブラウザを更新しても反映されていない場合があるかもしれません。

showにデフォルトのトランジションを設定する

引用:Set 'dissolve' transition as default transition - Lemma Soft Forums

showの時のみwith ~ を省略するコード。

ほぼ同じトランジションを使う場合の設定です。
その時だけ別のトランジションを使いたい時は
with fadeみたいにいつも通り書けば上書きされます。多分

init python:
    def replacement_show(*args, **kwargs):
        renpy.transition(dissolve)
        return renpy.show(*args, **kwargs)
    config.show = replacement_show

独自に設定したトランジションを設定したいとき

define dis = { "master" : Dissolve(0.2), "mcs" : Dissolve(0.2) }

init python:
    def replacement_show(*args, **kwargs):
        renpy.transition(dis)
        return renpy.show(*args, **kwargs)
    config.show = replacement_show

ボタンの選択状態が被るのを防ぐ(SelectedIf)

参照:Screen Actions, Values, and Functions — Ren'Py Documentation


ボタンのactionを複数付けると、
ラジオボタンのような一つのみがセレクトされる状態を
Ren'Pyがうまく理解できないことがある。

そのためSelectedIfで選択中の判定に使用したいアクションをかっこで括る。

おそらくラジオボタンの性質上、
変更の内容は違っても変更するものは同じである必要がある。
(Aの横幅を1にするボタン、Aの横幅を2に変更するボタンはその内容をselectedifには選べるがAの横幅を1にするボタン、Aの高さを1に変更にするボタンの内容をselectedifに指定してラジオボタンとして扱うことは不可)

使用例

            label _("フォントの変更")
            style_prefix "radio"
            if preferences.language == "en_us":
                textbutton "[gfont_name_en]":
                    action [SelectedIf(StylePreference("width", "0")), gui.SetPreference("font", "JF-Dot-Kappa20-0213.ttf"),Preference("font transform", None)]
                    text_font "JF-Dot-Kappa20-0213.ttf"
                null width 10
                textbutton "BIZ UD Gothic":
                    action [SelectedIf(StylePreference("width", "1")), gui.SetPreference("font", "BIZUDGothic-Regular.ttf"),Preference("font transform", None)]
                    text_font "BIZUDGothic-Regular.ttf"

言語ごとにテキストのスタイル設定を変更する

参照:スタイル — Ren'Py Documentation

screen preferences

        hbox:
            style_prefix "radio"
            label _("言語")
            null height 10
            textbutton _("日本語") action [Language(None), StylePreference("lang", "0")]
            null width 10
            textbutton "English" action [Language("en_us"), StylePreference("lang", "1")]

options.rpy(pythonが書けたらどこでもいい)

    renpy.register_style_preference("lang", "0", style.say_dialogue, "xsize",710)
    renpy.register_style_preference("lang", "0", style.say_dialogue, "xpos",20)

    renpy.register_style_preference("lang", "1", style.say_dialogue, "xsize",690)
    renpy.register_style_preference("lang", "1", style.say_dialogue, "xpos",33)


"lang":このスタイル設定の名前
"0" or "1":区別のための文字列 単語でもよい

"style.say_dialogue":更新するスタイル設定
namebox_labelを変更したい時はstyle.namebox_labelになる

"xsize","xpos":変更したいスタイルの箇所

710,20:変更したいスタイルの数値

renpy.register_style_preference("lang", "0", style.say_dialogue, "xsize",710)

xsizeはテキストボックスの横の広さにあたる。

renpy.register_style_preference("lang", "0", style.say_dialogue, "size",24)

sizeはテキストサイズにあたる。

renpy.register_style_preference("lang", "0", style.say_dialogue, "line_leading",13)

line_leadingは行間にあたる。

ビルド設定

参照:配布物のビルド — Ren'Py Documentation

コード

    build.classify('**~', None)
    build.classify('**.bak', None)
    build.classify('**/.**', None)
    build.classify('**/#**', None)
    build.classify('**/thumbs.db', None)

    build.classify('game/**.png', 'archive')
    build.classify('game/**.webp', 'archive')
    build.classify("game/**.rpy", "archive")
    build.classify("game/**.rpyc", "archive")

    build.classify("game/**.ttf", "archive")
    build.classify("game/**.otf", "archive")

    build.classify("_README.txt", "renpy")

    build.classify("game/audio/**.ogg", "archive")
    build.classify("game/audio/**.mp3", "archive")

補足

build.classify('game/**.webp', 'archive')

画像にwebpを使っている場合は使用(pngよりサイズの削減が期待できる拡張子)

build.classify("_README.txt", "renpy")

_README.txtの部分は各自のreadmeファイルの名前に変更する。
”renpy"指定の場合、Linux, Macintosh, Windows版にのみこのファイルが同梱される。
https://ja.renpy.org/doc/html/build.html#classifying-and-ignoring-files

よく見返すドキュメントのページ

スタイルのプロパティー

スタイルのプロパティー — Ren'Py Documentation
screenで使う要素になにか指定したい時によく見る。

Screen Actions, Values, Functions

Screen Actions, Values, and Functions — Ren'Py Documentation
screenでボタンを押したときのactionなどを指定する時によく見る。
screenを表示した時などに使うactionもこれに当てはまる。( on "show" action SetVariable("persistent.last_menu", "help") など)

スクリーンとスクリーン言語

スクリーンとスクリーン言語 — Ren'Py Documentation
screenの要素でどのスタイルのプロパティが通じるのかを確認するときによく見る。
たとえばbarの場合、
共通のプロパティー、位置スタイルプロパティー、バースタイルプロパティー
は通じるがGrid スタイルプロパティーで使うスタイルのプロパティは通じないなど。

設定変数

設定変数 — Ren'Py Documentation
たまに読むとこれ設定できたんだ~というのがあって楽しい。

キーマップのカスタマイズ

キーマップのカスタマイズ — Ren'Py Documentation
たまに読むとこのキー押すとこうなるんだ~というのがあって楽しい。