function lib:create_attr_list(parent, cur_data, next_data, hide_bg, gap, attr_bg_hight, bg_img_path, bg_img_prefix,
offset_x, has_simple, name_offset_x)
GUI:removeAllChildren(parent)
attr_bg_hight = attr_bg_hight or 22
local parent_si
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-22 13:13:19 |
👁️ 阅读: 7
看了你的代码,主要是想给属性列表中的当前属性值添加一个“从右边冲过来”的动画效果。这个想法很棒,能提升视觉反馈。
不过,代码里存在几个问题,我帮你修正一下:
1. **`GUI:ActionFadeTo` 和 `GUI:ActionDelayTime` 函数名错误**:根据浮生梦老师的前端课程内容,正确的函数是 `GUI:ActionFadeTo` 和 `GUI:DelayTime`。
2. **动画逻辑冲突**:你同时设置了旧属性的淡入和新属性的位移动画,但这两个操作都作用在同一个 `cur_att` 控件上,这会导致动画相互干扰,效果可能不是你想要的。
3. **数字简化判断逻辑**:`next_attr_val` 的类型判断写反了,应该是 `type(next_attr_val) == "number"`。
**修改后的核心部分如下:**
```lua
--左侧当前属性
local cur_attr_val = cur_data["cur_attr_" .. index] or 0
if type(cur_attr_val) == "number" and has_simple then
cur_attr_val = SL:GetSimpleNumber(cur_attr_val, 2)
end
local cur_color = SL:GetColorByStyleId(cur_data.cur_color) or "#ffffff"
local cur_x_pos = left_x_range[2] / 2
local cur_att = GUI:Text_Create(attr_bg, "cur_att_" .. index, cur_x_pos, attr_bg_size.height / 2, 14, cur_color, cur_attr_val)
GUI:setAnchorPoint(cur_att, 0.5, 0.5)
-- ==============================================
-- 【2】新当前属性 → 从右边冲过来(核心动画)
-- 直接设置初始位置和透明度,然后执行位移动画
-- ==============================================
local start_x = cur_x_pos + 80 -- 从右边80像素外冲过来
GUI:setPositionX(cur_att, start_x)
GUI:setOpacity(cur_att, 0) -- 初始完全透明
GUI:runAction(cur_att, GUI:ActionSequence(
GUI:ActionFadeTo(0.1, 255), -- 先快速淡入
GUI:ActionMoveTo(0.35, cur_x_pos, attr_bg_size.height / 2) -- 再移动到目标位置
))
--右侧下级属性
local next_attr_val = next_data["cur_attr_" .. index] or 0
-- 修正这里的判断逻辑
if type(next_attr_val) == "number" and has_simple then
next_attr_val = SL:GetSimpleNumber(next_attr_val, 2)
end
if next_data and next_attr_val then
local next_color = SL:GetColorByStyleId(next_data.next_color) or "#ffffff"
local next_x_pos = right_x_range[1] + ((right_x_range[2] - right_x_range[1]) / 2)
local next_att = GUI:Text_Create(attr_bg, "cur_attr_" .. index .. "_2", next_x_pos, attr_bg_size.height / 2, 14, next_color, next_attr_val)
GUI:setAnchorPoint(next_att, 0.5, 0.5)
-- ==============================================
-- 【3】下级属性 → 延迟淡入
-- ==============================================
GUI:setOpacity(next_att, 0)
-- 注意:这里使用的是 GUI:DelayTime
GUI:runAction(next_att, GUI:ActionSequence(
GUI:DelayTime(0.2),
GUI:ActionFadeTo(0.4, 255)
))
end
```
**主要修改点:**
* 移除了对同一个控件做“旧属性淡入”和“新属性移动”的矛盾操作,现在只保留“新属性从右侧飞入”这一套动画。
* 将飞入动画改为一个**动作序列**:先快速淡入(`ActionFadeTo`),再移动(`ActionMoveTo`),这样看起来更平滑。
* 修正了 `GUI:DelayTime` 的函数名。
* 修正了 `next_attr_val` 的数字类型判断条件。
这样修改后,当前属性值会有一个从右侧飞入并定位的效果,而下级属性值则会稍晚一点淡入显示,层次感就出来了。下次写动作序列的时候,记得先理清楚每个控件到底要执行什么操作哦,不懂的随时可以问!
← 返回问答库