大嘴猴 发表于 6 天前

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

<pre><code class="language-local">SL:RegisterLUAEvent(&quot;LUA_EVENT_MAPINFOCHANGE&quot;, &quot;地图切换&quot;, function(data)
-- 安全获取地图名称
local mapName = SL:GetMetaValue(&quot;MAP_NAME&quot;)
if mapName == &quot;盟重省&quot; or mapName == &quot;沙巴克皇宫&quot; then
return
end
SL:print(mapName)
if not mapName or mapName == &quot;&quot; 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(
&quot;&quot;..mapName,-- 添加前缀更友好
&quot;Arial&quot;,-- 明确指定字体
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
</code></pre>
<p><img src="data/attachment/forum/202508/20/120549ogv1z6frkla6rgfp.webp" alt="182513bbf1785865e4afcfe839ea551e_f4587ab3a7cf45a312a100ff45343f0f34a354d16b460-2.webp" title="182513bbf1785865e4afcfe839ea551e_f4587ab3a7cf45a312a100ff45343f0f34a354d16b460-2.webp" /></p>
页: [1]
查看完整版本: 【多余】Lua前端效果 切换地图渐变效果