hello, I want to ask how to make a imagebutton

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
Posts: 1
Joined: Sun Sep 25, 2011 1:13 am

hello, I want to ask how to make a imagebutton

#1 Post by feierqi » Sun Sep 25, 2011 1:17 am

sorry for ask such a simple question.. but I cannot understand the tutorial and the wiki.. also their examples don't work..
can anybody help me? maybe give a simple example.. I appropriate your help

User avatar
Posts: 461
Joined: Sun Mar 06, 2011 9:01 am
Projects: Elements: The Academy
Organization: Mushroom Samba

Re: hello, I want to ask how to make a imagebutton

#2 Post by Veniae » Mon Sep 26, 2011 2:16 pm

Okay, so I'm a newbie as well, but I hope I can help.

So, here's my imagebutton code:

Code: Select all

    ui.vbox(xpos=0.86, ypos=0.78, focus_mask=True)
             ui.imagebutton("menus/skip button idle1.png", "menus/skip button hover1.png", clicked=toggle_skipping, focus_mask=True)
             ui.imagebutton("menus/save button idle1.png", "menus/save button hover1.png", clicked=ccinc("_game_menu_save"), focus_mask=True)
             ui.imagebutton("menus/load button idle1.png", "menus/load button hover1.png", clicked=ccinc("_game_menu_load"), focus_mask=True)
             ui.imagebutton("menus/quit button idle1.png", "menus/quit button hover1.png", clicked=Quit(), focus_mask=True) 
vbox is a box you can use if you have more than one imagebutton and want to keep them in the same place. The xpos/ypos in the braces determine the position: xpos=0.0, ypos=0.0 is top left and xpos=1.0, ypos=1.0 is bottom right.

Note: If you're not using a vbox, you should put the xpos/ypos coordinates in the braces of the imagebuttons themselves (after defining their functions -see below).

focus_mask=True means that if the buttons are on a transparent BG, only the nontransparent parts of them would be selectable/focused.

Now, the ui.imagebutton is the button itself. The first file in the braces is the image of the idle button (without the mouse over it) and the second is of the button when the mouse hovering over it. clicked= determines what the button does. For example, clicking the Skip button will start skipping. If a button's function is to go to another menu (for example, the load menu), you need to use ccinc like in the example above. In this case, you need to put this

Code: Select all

$ ccinc = renpy.curried_call_in_new_context
in your script (mine is in an init block).

The ui.close() means that's the end of the vbox.

Hope that helped you at least a bit.

Once again, keep in mind that I'm now very confident in my knowledge.

Post Reply

Who is online

Users browsing this forum: Google [Bot], trooper6