[solved] Using variables to alter character sprite
Posted: Mon Jan 07, 2013 12:35 am
Question One: Can I use a variable to switch between character images? In this instance, I want the string in the variable hero_color to be used to switch the color of the charabase sprite. So if hero_color = "pink", then I want "show charabase hero_color" to be the same as "show charabase pink".
In the example below, which doesn't work but might illustrate my faulty method, I get the non-fatal error
I appreciate Ren'py's polite manner but it does little to soothe my frustration.
Script
Question the Second: I want to alter the variable hero_color using buttons and have the sprite update immediately. (I've borrowed the main menu code for now). Can I a) call my charabase sprite on my hero_custom screen or b) have it updated in the background behind the screen?
Screens
In the example below, which doesn't work but might illustrate my faulty method, I get the non-fatal error
Code: Select all
Image 'charabase' can't take parameters 'white'. (Perhaps you got the name wrong?)I appreciate Ren'py's polite manner but it does little to soothe my frustration.
Script
Code: Select all
# You can place the script of your game in this file.
init:
$ hero_color = "white"
# Declare images below this line, using the image statement.
image charabase = "CharaBase.png"
image charabase white = "CharaBase.png"
image charabase violet = im.Recolor("CharaBase.png", 183, 79, 207)
image charabase indigo = im.Recolor("CharaBase.png", 115, 79, 207)
image charabase pink = im.Recolor("CharaBase.png", 207, 79, 128)
# Declare characters used by this game.
define t = Character('tutor', color="#c8ffc8")
# The game starts here.
label start:
show charabase [hero_color] at truecenter
t "This is the base character sprite."
t "Currently the base color is [hero_color]."
t "Press the buttons at right to change the skin color."
call screen hero_custom:
return
Question the Second: I want to alter the variable hero_color using buttons and have the sprite update immediately. (I've borrowed the main menu code for now). Can I a) call my charabase sprite on my hero_custom screen or b) have it updated in the background behind the screen?
Screens
Code: Select all
##############################################################################
# Hero Chara Customization
#
# Screen that's used to display and customize the Hero Character
screen hero_custom:
# This ensures that any other menu screen is replaced.
# Which I don't want - I want the previous BG to be seen (and affected)
# So commented out.
## tag menu
# The background of the main menu. Commented out to be transparent
##window:
## style "mm_root"
# The main menu buttons.
frame:
style_group "mm"
xalign .98
yalign .98
has vbox
textbutton _("Pink") action SetVariable("hero_color", "pink")
textbutton _("Violet") action SetVariable("hero_color", "violet")
textbutton _("Indigo") action SetVariable("hero_color", "indigo")
textbutton _("Done") action Return
init -2 python:
# Make all the main menu buttons be the same size.
style.mm_button.size_group = "mm"