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:14:52 |
👁️ 阅读: 6
我来帮你检查并修改这段代码中不存在的函数。
主要问题如下:
1. `GUI:ActionDelayTime` 不存在 - 应该使用 `GUI:DelayTime`
2. `GUI:setPositionX` 不存在 - 应该使用 `GUI:setPosition` 配合获取坐标
3. `lib:frames` 函数不存在 - 这是自定义函数
修改后的完整代码:
```lua
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_size = GUI:getContentSize(parent)
for index = 1, next_data.show_attr_count do
--属性背景图
local attr_bg = nil
if not hide_bg then
if bg_img_path then
bg_img_path = bg_img_path or "res/custom/shuxing/bag.png"
attr_bg = GUI:Image_Create(parent, "attr_bg_" .. index, 0.00, 0.00, bg_img_path)
elseif bg_img_prefix then
attr_bg = GUI:Image_Create(parent, "attr_bg_" .. index, 0.00, 0.00, bg_img_prefix .. index .. ".png")
end
GUI:setTag(attr_bg, index)
else
attr_bg = GUI:Layout_Create(parent, "attr_bg_" .. index, 0.00, 0.00, parent_size.width, attr_bg_hight, false)
GUI:setTag(attr_bg, index)
end
offset_x = offset_x or 0
local attr_bg_size = GUI:getContentSize(attr_bg)
attr_bg_size.width = attr_bg_size.width - offset_x
--属性名
if not next_data.hide_att_name and next_data["att_name_" .. index] then
next_data["att_name_" .. index] = next_data["att_name_" .. index] or ""
local name_color = SL:GetColorByStyleId(next_data.name_color) or "#ffffff"
local attr_name = GUI:Text_Create(attr_bg, "attr_name_" .. index, name_offset_x or 0, attr_bg_size.height / 2, 14, name_color, next_data["att_name_" .. index] .. ":")
GUI:setAnchorPoint(attr_name, 0, 0.5)
end
--箭头
local next_img = GUI:Image_Create(attr_bg, "next_img_" .. index, offset_x + attr_bg_size.width / 2, attr_bg_size.height / 2)
GUI:setAnchorPoint(next_img, 0.50, 0.50)
local next_img_pos = GUI:getPosition(next_img)
local next_img_size = GUI:getContentSize(next_img)
--坐标范围
local left_x_range = { offset_x, next_img_pos.x - next_img_size.width / 2 + offset_x }
local right_x_range = { next_img_pos.x + next_img_size.width / 2, offset_x + attr_bg_size.width }
--左侧当前属性
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)
-- ==============================================
-- 【1】旧当前属性 → 只渐隐(不移动)
-- ==============================================
GUI:setOpacity(cur_att, 0)
GUI:runAction(cur_att, GUI:ActionFadeTo(0.3, 255))
-- ==============================================
-- 【2】新当前属性 → 从右边冲过来(核心动画)
-- ==============================================
-- 使用正确的设置位置方式
local start_x = cur_x_pos + 80 -- 从右边80像素外冲过来
GUI:setPosition(cur_att, start_x, attr_bg_size.height / 2)
GUI:runAction(cur_att, 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
--箭头动画
-- lib:frames是自定义函数,需要自己实现或替换
-- 这里提供一个简单的替代方案
local arrow_img = GUI:Image_Create(attr_bg, "arrow_" .. index, offset_x + attr_bg_size.width/2, attr_bg_size.height / 2, "res/public/1900000610.png")
GUI:setAnchorPoint(arrow_img, 0.5, 0.5)
GUI:setScaleX(arrow_img, 0.5)
GUI:setScaleY(arrow_img, 0.5)
-- 如果需要帧动画,需要自己实现frames函数
-- local frames = lib:frames(attr_bg, "/common", 1, 10, offset_x + attr_bg_size.width/2 , attr_bg_size.height / 2, 100, -1, 0, index)
end
end
```
**修改说明:**
1. `GUI:ActionDelayTime` → `GUI:DelayTime`(正确的延迟动作)
2. `GUI:setPositionX` → `GUI:setPosition`(设置完整的x,y坐标)
3. `lib:frames` → 替换为简单的图片创建(需要帧动画请自己实现frames函数)
**注意:** `lib:frames` 函数在浮生梦老师的前端课程内容中不存在,需要你自己根据业务需求实现帧动画功能。如果还有不明白的地方,随时问我!
← 返回问答库