local hualong = {}
function hualong.main(param1, param2, param3, param4)
lib:Require(param1, function(state)
if state then
if param1 then
hualong.parent = lib:openwin(param1, nil, true, param4) or {}
你需要修改特效检测逻辑,让删除特效的条件从 `var >= 5` 改为检测特效是否已经存在且不同。以下是修改后的代码部分:
```lua
-- 原来的代码
SL:Print("varvarvarvarvarvar=======",var)
if var >=5 then
GUI:removeChildByName(ui["Layout_eff"], "Effect_hl")
end
-- 修改后的代码
SL:Print("varvarvarvarvarvar=======",var)
-- 获取当前已有的特效
local oldEffect = GUI:getChildByName(ui["Layout_eff"], "Effect_hl")
-- 检查是否需要删除旧特效
if not GUI:Win_IsNull(oldEffect) then
-- 获取旧特效的ID(假设特效ID存储在tag或其他属性中)
local oldEffectId = GUI:getTag(oldEffect)
-- 如果新特效ID与旧特效ID不同,则删除旧特效
if effid and effid > 0 and oldEffectId ~= effid then
GUI:removeFromParent(oldEffect)
end
end
-- 创建新特效
if effid and effid > 0 then
local x = next_cfg.effect_x
local y = next_cfg.effect_y
local Effect_hl = GUI:Effect_Create(ui["Layout_eff"], "Effect_hl", x, y, 3, effid, 0, 0, 0, 1)
GUI:setScale(Effect_hl, 1)
GUI:setTag(Effect_hl, effid) -- 将特效ID存储在tag中以便后续比较
```
主要修改点:
1. 使用 `GUI:getChildByName()` 获取已存在的特效
2. 使用 `GUI:Win_IsNull()` 判断特效是否存在
3. 通过 `GUI:getTag()` 获取旧特效的ID
4. 比较新旧特效ID,不同时才删除旧特效
5. 创建新特效时用 `GUI:setTag()` 存储特效ID
这样就能确保只有当特效ID发生变化时才删除并重新创建特效,而不是简单地根据 `var >= 5` 来判断。