本帖最后由 电波 于 2024-10-23 11:53 编辑
blackpineapple 发表于 2024-10-23 05:54
你看的是哪个教程,不贴代码别人也很难跟进。。
感谢回复!
教程:【renpy教程】定制鼠标光标的悬浮、按下和特殊效果
https://www.renpy.cn/forum.php?mod=viewthread&tid=1272
(出处: RenPy中文空间)
原教程提供的代码网址:https://github.com/libudu/renpy-mouse/tree/master
我本人是从代码网址中复制粘贴了mouse.rpy的部分,在screens.rpy中添加了mouse "mousehover"的代码,
我的mouse.rpy与添加的代码部分如下:
【mouse.rpy】
[RenPy] 纯文本查看 复制代码 define config.mouse = {
'default': [
('mouse.png', 0, 0)
],
'mousedown': [
('mousedown.png', 0, 0)
],
'mousehover': [
('mousehover.png', 0, 0)
],
}
# renpy暂未提供鼠标按下时的定制接口
# 通过替换Interface中的原有方法来实现定制鼠标按下时的光标变化
init python:
import pygame
Interface = renpy.display.core.Interface
def _mock_get_mouse_name(self, cache_only=False, interaction=True):
global _old_get_mouse_name
if renpy.config.mouse.get("mousedown") != None and pygame.mouse.get_pressed()[0]:
return "mousedown"
return Interface._old_get_mouse_name(self, cache_only, interaction)
# 先判断是否已存在,避免交互式编辑启动时会重载init python代码,导致递归
if not hasattr(Interface, "_old_get_mouse_name"):
Interface._old_get_mouse_name = Interface.get_mouse_name
Interface.get_mouse_name = _mock_get_mouse_name
# 使用transform做动态可视组件
transform MouseSnowTransform(last_time, rotate):
im.FactorScale("mouse.png", 0.2)
parallel:
linear last_time alpha 0.0
parallel:
linear last_time rotate rotate
init python:
# 下雪的鼠标
import random
class MouseSnow():
def __init__(self):
# 持续时间
self.last_time = 1
# 下落的可视组件
self.snow_image_list = [
MouseSnowTransform(self.last_time, 360),
MouseSnowTransform(self.last_time, 180),
MouseSnowTransform(self.last_time, -360),
MouseSnowTransform(self.last_time, -180),
]
# 下落区域的宽度
self.snow_width = 50
# 每隔多少秒生成一个
self.break_time = 0.1
# 下落速度
self.speed_y = 1.5
# 控制是否继续生成
self.open = False
# 同屏最大数量,等于持续时间/间隔生成时间
self.max_count = self.last_time / self.break_time
self.sprite_list = []
self.sprite_manager = SpriteManager(update=self.sprite_update)
# 粒子不断下落
def sprite_update(self, st):
for i in self.sprite_list:
i.y += self.speed_y
return 0.01
# 生成一个粒子
def add_sprite(self):
if self.open:
snow_image = random.choice(self.snow_image_list)
sprite = self.sprite_manager.create(snow_image)
mouse_pos = renpy.get_mouse_pos()
sprite.x = mouse_pos[0]
sprite.y = mouse_pos[1]
sprite.x += random.random() * self.snow_width
self.sprite_list.append(sprite)
# 超过最大存在数则移除第一个
if len(self.sprite_list) > self.max_count:
self.sprite_list.pop(0).destroy()
mouse_snow = MouseSnow()
# 光标雪花效果的置顶图层
config.top_layers.append("mouse")
# 光标雪花效果的界面
screen MouseSnowScreen():
layer "mouse"
add mouse_snow.sprite_manager
timer mouse_snow.break_time action mouse_snow.add_sprite repeat True
# 进入主菜单之前,开始显示鼠标界面
label before_main_menu:
show screen MouseSnowScreen
【添加的代码】
[RenPy] 纯文本查看 复制代码 screen navigation():
vbox:
style_prefix "navigation"
xpos gui.navigation_xpos
yalign 0.5
spacing gui.navigation_spacing
if main_menu:
textbutton _("开始游戏"):
mouse "mousehover"
action Start()
else:
textbutton _("历史"):
mouse "mousehover"
action ShowMenu("history")
textbutton _("保存"):
mouse "mousehover"
action ShowMenu("save")
textbutton _("读取游戏"):
mouse "mousehover"
action ShowMenu("load")
textbutton _("设置"):
mouse "mousehover"
action ShowMenu("preferences")
if _in_replay:
textbutton _("结束回放"):
mouse "mousehover"
action EndReplay(confirm=True)
elif not main_menu:
textbutton _("标题菜单"):
mouse "mousehover"
action MainMenu()
textbutton _("关于"):
mouse "mousehover"
action ShowMenu("about")
if renpy.variant("pc") or (renpy.variant("web") and not renpy.variant("mobile")):
## “帮助”对移动设备来说并非必需或相关。
textbutton _("帮助"):
mouse "mousehover"
action ShowMenu("help")
if renpy.variant("pc"):
## 退出按钮在 iOS 上是被禁止使用的,在安卓和网页上也不是必要的。
textbutton _("退出"):
mouse "mousehover"
action Quit(confirm=not main_menu)
|