Customizable Sprite with Blinking? [SOLVED]

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.
Message
Author
User avatar
ArizaLuca
Veteran
Posts: 240
Joined: Tue Feb 20, 2018 12:59 pm
Completed: Through the Screen, Riddle Me This, Trust Fall, Phobias, Another Adventure
Projects: The Souls in the Seams, Fata Morgana, Minecraft: Story Mode - Behind the Scenes
Organization: Astral Autumn Games
Tumblr: astralautumngames
Deviantart: ArizaLuca
itch: astralautumngames
Contact:

Customizable Sprite with Blinking? [SOLVED]

#1 Post by ArizaLuca » Wed Jul 24, 2019 8:52 am

My current code is I have coded every sort of 'animation' the eyes have in Ren'Py, and then I use ConditionSwitch to switch between the variations of eyes-- for example, blue has a set of eyes, green has a set of 'animations', and so on so forth:

Code: Select all

image gold eyes squint:
    LiveComposite((740, 1110), 
        (0, 0), "player/player_eyes_gold_squint.png",
    )
    choice:
        4.5
    choice:
        3.5
    choice:
        1.5
    # This randomizes the time between blinking.
    "player/player_eyes_closed.png"
    .25
    repeat
    
image gray eyes = ConditionSwitch(
    "pmood == 'averted'", "gray eyes averted shine",
    "pmood == 'halfshut'", "gray eyes halfshut shine",
    "pmood == 'squint'", "gray eyes squint shine",
    "pmood == 'wide'", "gray eyes wide shine",
    "pmood == 'screwedup'", "player/player_eyes_screwedup.png",
    "pmood == 'closed'", "player/player_eyes_closed.png",
    "pmood == 'Truedull'", "gray eyes normal",
    "pmood == 'averteddull'", "gray eyes averted",
    "pmood == 'halfshutdull'", "gray eyes halfshut",
    "pmood == 'squintdull'", "gray eyes squint",
    "pmood == 'widedull'", "gray eyes wide",
    "True", "gray eyes normal shine")
    
 ##### An example of some of the code. ######
Then I put it in the character as a LayeredImage.

Code: Select all

layeredimage player:
    always:
        "player_base"
    if skin == 1:
        "player_skin_light"
    elif skin == 2:
        "player_skin_asian"
    elif skin == 3:
        "player_skin_tan"
    elif skin == 4:
        "player_skin_dark"
    if hair == 1:
        "player_hair_blonde"
    elif hair == 2:
        "player_hair_red"
    elif hair == 3:
        "player_hair_lightbrown"
    elif hair == 4:
        "player_hair_brown"
    elif hair == 5:
        "player_hair_darkbrown"
    elif hair == 6:
        "player_hair_black"
    if eye == 1:
        "blue eyes"
    elif eye == 2:
        "black eyes"
    elif eye == 3:
        "brown eyes"
    elif eye == 4:
        "gray eyes"
    elif eye == 5:
        "green eyes"
    elif eye == 6:
        "gold eyes"
    group eyebrows auto:
        attribute normal default
    group mouth auto:
        attribute frown default
    if pshadow:
        "player_shadow"
    if pshadow2:
        "player_shadow2"
    if ptears:
        "player_tears"
    if psweatdrop:
        "psweatdrop"
        
image side player = LayeredImageProxy("player", Transform(crop=(50, 0, 800, 750), zoom=0.6, xoffset=0))
Is there a more efficient way of going about this? I have tried doing if statements within the group, and if I put multiple groups within the if statement, but it just provides me with this error...

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/player definitions.rpy", line 1010: end of line expected.
    if eye == 1:
    ^

Ren'Py Version: Ren'Py 7.2.2.491
Wed Jul 24 10:39:24 2019
Last edited by ArizaLuca on Sun Aug 04, 2019 7:35 pm, edited 3 times in total.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1338
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Customizable Sprite with Blinking?

#2 Post by namastaii » Wed Jul 24, 2019 7:10 pm

So for blinking, I would do something like this

Code: Select all

image samantha_blink:
        
        "characters/samantha/eyes_open.png"
        choice:
            4.5
        
        "characters/samantha/eyes_closed.png"
        .20
        repeat
(this is just the eyes layer)

and then the live composite for the actual sprite

Code: Select all

def draw_samantha(st, at):
            return LiveComposite(
            (100, 830),
            (0, 0), "characters/samantha/samantha_without_eyes.png",
            (0, 0), "samantha_blink",

            ),.1
Hopefully this makes sense and is what you're looking for. In the live composite on top of the base sprite, I have "samantha_blink" which refers to the image I defined before.

You can also include a condition switch inline with the live composite

Code: Select all

def draw_samantha(st, at):
            return LiveComposite(
            (100, 830),
            (0, 0), "create_character/base_female1.png",
            (0, 0), ConditionSwitch(
                "my_condition", "characters/outfits/uniform_female_1.png",
                "my_condition == False","characters/samantha/outfit%s.png"%(samantha_outfit),
                ),
            (0, 0), "samantha_blink_flip",
            

            ),.1
with many options in a condition switch, you can probably create an image for it just like you did (I haven't done it that way before yet) and then put that image in the live composite. I also feel like I'm confusing myself haha let me know if any of this helps or for more clarification

**I also just realized you already know how to create the blinking. My bad. But I guess you could just create an image for every specific type of blink animation and maybe include that in a condition switch in the live composite for the character? I would make the entire character live composite and get rid of some of those lines of code and put it together in one functional piece.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1338
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Customizable Sprite with Blinking?

#3 Post by namastaii » Wed Jul 24, 2019 7:25 pm

Another thing I noticed was all the variables for the hair and all that. You don't need any if statements for those if you just put it all in a live composite :) If you want to send another sample my way I can help if it's confusing hahaha

User avatar
ArizaLuca
Veteran
Posts: 240
Joined: Tue Feb 20, 2018 12:59 pm
Completed: Through the Screen, Riddle Me This, Trust Fall, Phobias, Another Adventure
Projects: The Souls in the Seams, Fata Morgana, Minecraft: Story Mode - Behind the Scenes
Organization: Astral Autumn Games
Tumblr: astralautumngames
Deviantart: ArizaLuca
itch: astralautumngames
Contact:

Re: Customizable Sprite with Blinking?

#4 Post by ArizaLuca » Wed Jul 24, 2019 8:12 pm

The thing is, while that's fine (I've used sprites like that before, but I'm glad to get a refresher since I've been using LayeredImages lately, haha), the transitions between emotions are very abrupt, and every other character's are dissolves.

Unfortunately, at this point if I don't find a better solution I'll probably just revert to the LiveComposite/ConditionSwitch thing just because lordy this character's getting annoying to try to code in xD

But it's definitely good to confirm that's probably the most efficient method at this point.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1338
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Customizable Sprite with Blinking?

#5 Post by namastaii » Thu Jul 25, 2019 12:37 am

It works well for me because it all happens live and all I have to do during scripting the dialogue is change an expression variable with something like $samantha_emotion = "happy" etc
Plus the less lines of code you use the faster the game will run in the long run

User avatar
ArizaLuca
Veteran
Posts: 240
Joined: Tue Feb 20, 2018 12:59 pm
Completed: Through the Screen, Riddle Me This, Trust Fall, Phobias, Another Adventure
Projects: The Souls in the Seams, Fata Morgana, Minecraft: Story Mode - Behind the Scenes
Organization: Astral Autumn Games
Tumblr: astralautumngames
Deviantart: ArizaLuca
itch: astralautumngames
Contact:

Re: Customizable Sprite with Blinking?

#6 Post by ArizaLuca » Thu Jul 25, 2019 7:31 am

That's fair. Well; that sprite's gonna be a LiveComposite, then xD

Ah, hang on; how do you do side images for LiveComposite/ConditionSwitch sprites? Sorry xD

User avatar
namastaii
Eileen-Class Veteran
Posts: 1338
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Customizable Sprite with Blinking? [SOLVED]

#7 Post by namastaii » Thu Jul 25, 2019 9:25 am

I dont think there is much difference, you just use the image in the character definition like the example i showed on your other thread

User avatar
ArizaLuca
Veteran
Posts: 240
Joined: Tue Feb 20, 2018 12:59 pm
Completed: Through the Screen, Riddle Me This, Trust Fall, Phobias, Another Adventure
Projects: The Souls in the Seams, Fata Morgana, Minecraft: Story Mode - Behind the Scenes
Organization: Astral Autumn Games
Tumblr: astralautumngames
Deviantart: ArizaLuca
itch: astralautumngames
Contact:

Re: Customizable Sprite with Blinking?

#8 Post by ArizaLuca » Thu Jul 25, 2019 10:02 am

Ahhh, I just realized a tiny problem-- the way I'm customizing the sprite is a dressup game with a screen like:

Code: Select all

init python:
    hair, eye, skin  = 1, 1, 1 # default dressup items
    hair_styles_num, eye_styles_num, skin_styles_num = 6, 6, 4 # number of styles for each dressup item
    
screen customize():

    ## Ensure this appears on top of other screens.
    zorder 100

    frame:

        xalign 0.5
        xsize 700
        yfill True

        hbox:

            xalign 0.5
            yalign 0.3
            spacing 400

            textbutton _("<") action SetVariable('hair', max(hair-1,1))
            textbutton _(">") action SetVariable('hair', min(hair+1,hair_styles_num))

        add "doll" xalign 0.5

        hbox:

            xalign 0.5
            yalign 0.4
            spacing 400

            textbutton _("<") action SetVariable('eye', max(eye-1,1))
            textbutton _(">") action SetVariable('eye', min(eye+1,eye_styles_num))
            
        hbox:

            xalign 0.5
            yalign 0.5
            spacing 400

            textbutton _("<") action SetVariable('skin', max(skin-1,1))
            textbutton _(">") action SetVariable('skin', min(skin+1,skin_styles_num))

        textbutton _("Done") action Jump('dressup_game') xalign 0.99 yalign 0.95
I'm not entirely sure LiveComposite/ConditionSwitch would be good because it requires a 'True' statement that I'm not sure would work in this case... would it still work if I formatted it something like:

Code: Select all

image player = LiveComposite(
    (740, 1110), 
    (0,0), ConditionSwitch(
        "skin == 1", "player/player_skin_light.png",
        "skin == 2", "player/player_skin_asian.png",
        "skin == 3", "player/player_skin_tan.png",
        "skin == 4", "player/player_skin_dark.png",
        "'True'", "player/player_base.png",
        ),...

User avatar
namastaii
Eileen-Class Veteran
Posts: 1338
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Customizable Sprite with Blinking?

#9 Post by namastaii » Thu Jul 25, 2019 11:28 am

All you need to do with the live composite at that point is have lines like this for the variables:

Code: Select all

"create_character/sprite_skin%s.png"%(skinColor)
and have your files organized as sprite_skin1.png, sprite_skin2.png etc then the live composite will pull the right file according to what the variable has been set as. %s is where the variable number would go and if skinColor is set to 2, then it will be displaying sprite_skin2.png

This is what it'd look like in live composite:

Code: Select all

LiveComposite(


                (100, 630),
                (0, 0), "create_character/sprite_skin%s.png"%(skinColor),

User avatar
ArizaLuca
Veteran
Posts: 240
Joined: Tue Feb 20, 2018 12:59 pm
Completed: Through the Screen, Riddle Me This, Trust Fall, Phobias, Another Adventure
Projects: The Souls in the Seams, Fata Morgana, Minecraft: Story Mode - Behind the Scenes
Organization: Astral Autumn Games
Tumblr: astralautumngames
Deviantart: ArizaLuca
itch: astralautumngames
Contact:

Re: Customizable Sprite with Blinking?

#10 Post by ArizaLuca » Thu Jul 25, 2019 1:20 pm

I adjusted the code to have this:

Code: Select all

image player = LiveComposite(
        (740, 1110),
        (0,0), "player/player_base.png",
        (0,0), "player/player_skin_%s.png"%(skin),
        (0,0), "player/player_hair_%s.png"%(hair)
        (0,0), "player_eyes_%s"%(eye)
        (0,0), ConditionSwitch(
            "pbrow == 'quirk'", "player/player_eyebrows_quirked.png",
            "pbrow == 'raised'", "player/player_eyebrows_raised.png",
            "pbrow == 'sad'", "player/player_eyebrows_sad.png",
            "pbrow == 'angry'", "player/player_eyebrows_angry.png",
            "pbrow == 'thoughtful'", "player/player_eyebrows_thoughtful.png",
            "'True'", "player/player_eyebrows_normal.png"
            ),
        (0,0), ConditionSwitch(
            "pmouth == 'open'", "player/player_mouth_open.png",
            "pmouth == 'opensmile'", "player/player_mouth_opensmile.png",
            "pmouth == 'smile'", "player/player_mouth_smile.png",
            "pmouth == 'teeth'", "player/player_mouth_teeth.png",
            "pmouth == 'toothysmile'", "player/player_mouth_toothysmile.png",
            "'True'", "player/player_mouth_frown.png"
            ),
        (0,0), ConditionSwitch(
            "pshadow == 'full'", "player/player_shadow.png",
            "pshadow == 'half'", "player/player_shadow2.png",
            "'True'", "none.png",
            ),
        (0,0), ConditionSwitch(
            "ptears == 'tears'", "player/player_tears.png",
            "'True'", "none.png",
            ),
        (0,0), ConditionSwitch(
            "psweatdrop == 'sweatdrop'", "player/player_sweatdrop.png",
            "'True'", "none.png",
            )
        )
        
    
image side playerside:
    LiveCrop((50, 0, 800, 750), zoom=0.6, xoffset=0, "player")
    
It now pops up with this error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/definitions/player definitions.rpy", line 1070, in script
    image player = LiveComposite(
  File "game/definitions/player definitions.rpy", line 1075, in <module>
    (0,0), "player_eyes_%s"%(eye)
TypeError: 'int' object is not callable

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/definitions/player definitions.rpy", line 1070, in script
    image player = LiveComposite(
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/ast.py", line 999, in execute
    img = renpy.python.py_eval_bytecode(self.code.bytecode)
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/python.py", line 1954, in py_eval_bytecode
    return eval(bytecode, globals, locals)
  File "game/definitions/player definitions.rpy", line 1075, in <module>
    (0,0), "player_eyes_%s"%(eye)
TypeError: 'int' object is not callable

Darwin-18.0.0-x86_64-i386-64bit
Ren'Py 7.2.2.491
Desruc Dolls 1.0
Thu Jul 25 13:16:11 2019
Do I have to do the 'def draw' thing?

User avatar
namastaii
Eileen-Class Veteran
Posts: 1338
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Customizable Sprite with Blinking?

#11 Post by namastaii » Thu Jul 25, 2019 1:30 pm

You forgot some commas in your live composite. After fixing those, see if there is an error

also sorry the %s syntax is for python. If you're using renpy language I think it might translate to

Code: Select all

"character/skin[s_skincolor].png"

User avatar
ArizaLuca
Veteran
Posts: 240
Joined: Tue Feb 20, 2018 12:59 pm
Completed: Through the Screen, Riddle Me This, Trust Fall, Phobias, Another Adventure
Projects: The Souls in the Seams, Fata Morgana, Minecraft: Story Mode - Behind the Scenes
Organization: Astral Autumn Games
Tumblr: astralautumngames
Deviantart: ArizaLuca
itch: astralautumngames
Contact:

Re: Customizable Sprite with Blinking?

#12 Post by ArizaLuca » Thu Jul 25, 2019 3:27 pm

A similar result pops up both ways if I try to run the python and the renpy language:

Code: Select all

I'm sorry, but an uncaught exception occurred.

After initialization, but before game start.
SyntaxError: non-keyword arg after keyword arg (player definitions.rpy, line 1109)

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/bootstrap.py", line 313, in bootstrap
    renpy.main.main()
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/main.py", line 465, in main
    renpy.game.script.analyze()
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/script.py", line 905, in analyze
    i.analyze()
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/ast.py", line 1007, in analyze
    self.atl.mark_constant()
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/atl.py", line 692, in mark_constant
    i.mark_constant()
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/atl.py", line 976, in mark_constant
    constant = min(constant, is_constant_expr(expr))
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/pyanalysis.py", line 530, in is_constant_expr
    node, literal = ccache.ast_eval_literal(expr)
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/pyanalysis.py", line 684, in ast_eval_literal
    expr = py_compile(expr, 'eval', ast_node=True)
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/python.py", line 690, in py_compile
    raise e
SyntaxError: non-keyword arg after keyword arg (player definitions.rpy, line 1109)

Darwin-18.0.0-x86_64-i386-64bit
Ren'Py 7.2.2.491
Desruc Dolls 1.0
Thu Jul 25 15:27:11 2019

User avatar
namastaii
Eileen-Class Veteran
Posts: 1338
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Customizable Sprite with Blinking?

#13 Post by namastaii » Fri Jul 26, 2019 3:53 pm

can you show me line 1109 on player definitions.rpy?

User avatar
ArizaLuca
Veteran
Posts: 240
Joined: Tue Feb 20, 2018 12:59 pm
Completed: Through the Screen, Riddle Me This, Trust Fall, Phobias, Another Adventure
Projects: The Souls in the Seams, Fata Morgana, Minecraft: Story Mode - Behind the Scenes
Organization: Astral Autumn Games
Tumblr: astralautumngames
Deviantart: ArizaLuca
itch: astralautumngames
Contact:

Re: Customizable Sprite with Blinking?

#14 Post by ArizaLuca » Fri Jul 26, 2019 6:38 pm

Code: Select all

image side playerside:
    LiveCrop((50, 0, 800, 750), zoom=0.6, xoffset=0, "player")
I'm not sure that's the issue? the issue seems to appear with how I now defined the character:

Code: Select all

image player = LiveComposite(
        (740, 1110),
        (0,0), "player/player_base.png",
        (0,0), "player/player_skin_%s.png"%(skin),
        (0,0), "player/player_hair_%s.png"%(hair),
        (0,0), "player_eyes_%s"%(eye),
        (0,0), ConditionSwitch(...
which is what I had to do since python confuses me xD

User avatar
namastaii
Eileen-Class Veteran
Posts: 1338
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Customizable Sprite with Blinking?

#15 Post by namastaii » Fri Jul 26, 2019 6:42 pm

does your live composite have a closing? the ), at the end

Code: Select all

LiveComposite(


                ##stuff here
                    ),.1

Post Reply

Who is online

Users browsing this forum: Google [Bot], Triority, Valhalla Ent