代码升级了一下,监听鼠标按键事件,48*48取整,动态添加按钮组件
[RenPy] 纯文本查看 复制代码 # 游戏在此开始。
# 定义玩家的XY坐标位置
define p_x = 0
define p_y = 0
define button_lib = [
(1,1),
]
label start:
call screen snKey
return
screen snKey:
# 设置按键响应
key "input_left" action SetVariable("p_x",p_x-3)
key "input_right" action SetVariable("p_x",p_x+3)
key "input_up" action SetVariable("p_y",p_y-3)
key "input_down" action SetVariable("p_y",p_y +3)
key "button_ignore" action Function(MouseDown)
# 显示玩家的位置
textbutton "玩家":
pos(p_x,p_y)
text_color "#ffffff"
for item in button_lib:
textbutton "按钮":
pos item
text_color "#ffffff"
pass
init python:
def MouseDown():
pos = renpy.get_mouse_pos()
global button_lib
#button_lib.append(pos)
x = pos[0]
y = pos[1]
x = (x//48)*48
y = (y//48)*48
button_lib.append((x,y))
pass
|