【多余】Lua前端效果 切换地图渐变效果

发表于:5 天前 57
SL:RegisterLUAEvent("LUA_EVENT_MAPINFOCHANGE", "地图切换", function(data)
-- 安全获取地图名称
local mapName = SL:GetMetaValue("MAP_NAME")
if mapName == "盟重省" or mapName == "沙巴克皇宫" then
return
end
SL:print(mapName)
if not mapName or mapName == "" then return end
-- 获取场景相关对象
local director = cc.Director:getInstance()
local runningScene = director:getRunningScene()
local visibleSize = director:getVisibleSize()
local origin = director:getVisibleOrigin()

-- 创建半透明黑色背景层
local blackLayer = cc.LayerColor:create(cc.c4b(0, 0, 0, 255))  -- 调整为200透明度更柔和
blackLayer:setContentSize(visibleSize)
blackLayer:setPosition(origin)
runningScene:addChild(blackLayer, 999)  -- 确保在最上层显示

-- 创建地图名称文本
local textLabel = cc.Label:createWithSystemFont(
""..mapName,  -- 添加前缀更友好
"Arial",  -- 明确指定字体
51  -- 调大字号
)
textLabel:setColor(cc.c3b(255, 255, 255))
textLabel:enableOutline(cc.c3b(0, 0, 0), 4)  -- 加粗描边
textLabel:setPosition(origin.x + visibleSize.width/2, origin.y + visibleSize.height/2)  -- 居中显示

-- 添加到图层
blackLayer:addChild(textLabel)

-- 创建渐隐动画序列
local fadeDuration = 1  -- 延长动画时间
local textFade = cc.FadeOut:create(fadeDuration)
local layerFade = cc.FadeOut:create(fadeDuration)
local removeLayer = cc.CallFunc:create(function()
blackLayer:removeFromParent(true)
end)

-- 同步执行文本和背景的渐隐
textLabel:runAction(textFade)
blackLayer:runAction(cc.Sequence:create(
layerFade,
removeLayer
))

end)

return switchmap

182513bbf1785865e4afcfe839ea551e_f4587ab3a7cf45a312a100ff45343f0f34a354d16b460-2.webp

收藏
送赞
分享

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

发表回复

作者推荐

话题