写一套完整的4把飞剑的代码
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-05-09 21:20:02 |
👁️ 阅读: 6
根据浮生梦老师前端课程内容,要实现4把飞剑的界面,可以这样编写:
```lua
-- 创建主界面
local parent = GUI:Win_Create("GMMain", 0, 0, 0, 0, false, false, true, false, false, false, 1)
-- 创建背景
local bg = GUI:Image_Create(parent, "bg", 0, 0, "res/public_win32/1900000610.png")
GUI:setContentSize(bg, 800, 600)
-- 创建4把飞剑的容器
local swordContainer = GUI:Node_Create(parent, "sword_container", 0, 0)
-- 飞剑1
local sword1 = GUI:Image_Create(swordContainer, "sword_1", 100, 300, "res/custom/153_jianyi/x1.png")
local btn1 = GUI:Button_Create(sword1, "btn_sword1", 0, -50, "res/public_win32/1900000612.png")
GUI:Button_setTitleText(btn1, "飞剑1")
GUI:addOnClickEvent(btn1, function()
SL:print("飞剑1被点击!")
end)
-- 飞剑2
local sword2 = GUI:Image_Create(swordContainer, "sword_2", 300, 300, "res/custom/153_jianyi/x1.png")
local btn2 = GUI:Button_Create(sword2, "btn_sword2", 0, -50, "res/public_win32/1900000612.png")
GUI:Button_setTitleText(btn2, "飞剑2")
GUI:addOnClickEvent(btn2, function()
SL:print("飞剑2被点击!")
end)
-- 飞剑3
local sword3 = GUI:Image_Create(swordContainer, "sword_3", 500, 300, "res/custom/153_jianyi/x1.png")
local btn3 = GUI:Button_Create(sword3, "btn_sword3", 0, -50, "res/public_win32/1900000612.png")
GUI:Button_setTitleText(btn3, "飞剑3")
GUI:addOnClickEvent(btn3, function()
SL:print("飞剑3被点击!")
end)
-- 飞剑4
local sword4 = GUI:Image_Create(swordContainer, "sword_4", 700, 300, "res/custom/153_jianyi/x1.png")
local btn4 = GUI:Button_Create(sword4, "btn_sword4", 0, -50, "res/public_win32/1900000612.png")
GUI:Button_setTitleText(btn4, "飞剑4")
GUI:addOnClickEvent(btn4, function()
SL:print("飞剑4被点击!")
end)
-- 为每把飞剑添加文字描述
local text1 = GUI:Text_Create(sword1, "text_sword1", 76, 284, 18, "#ff9b00", "鱼肠剑")
local text2 = GUI:Text_Create(sword2, "text_sword2", 76, 284, 18, "#ff9b00", "干将剑")
local text3 = GUI:Text_Create(sword3, "text_sword3", 76, 284, 18, "#ff9b00", "莫邪剑")
local text4 = GUI:Text_Create(sword4, "text_sword4", 76, 284, 18, "#ff9b00", "轩辕剑")
-- 设置字体样式
GUI:Text_setFontName(text1, "fonts/FZZZHUNHJW.TTF")
GUI:Text_setFontName(text2, "fonts/FZZZHUNHJW.TTF")
GUI:Text_setFontName(text3, "fonts/FZZZHUNHJW.TTF")
GUI:Text_setFontName(text4, "fonts/FZZZHUNHJW.TTF")
-- 添加描边效果
GUI:Text_enableOutline(text1, "#000000", 1)
GUI:Text_enableOutline(text2, "#000000", 1)
GUI:Text_enableOutline(text3, "#000000", 1)
GUI:Text_enableOutline(text4, "#000000", 1)
-- 设置锚点居中
GUI:setAnchorPoint(text1, 0.50, 0.50)
GUI:setAnchorPoint(text2, 0.50, 0.50)
GUI:setAnchorPoint(text3, 0.50, 0.50)
GUI:setAnchorPoint(text4, 0.50, 0.50)
-- 添加属性描述
local attr1 = GUI:Text_Create(sword1, "attr1", 76, 26, 16, "#5ac83d", "攻击力+10%")
local attr2 = GUI:Text_Create(sword2, "attr2", 76, 26, 16, "#5ac83d", "暴击率+15%")
local attr3 = GUI:Text_Create(sword3, "attr3", 76, 26, 16, "#5ac83d", "攻速+20%")
local attr4 = GUI:Text_Create(sword4, "attr4", 76, 26, 16, "#5ac83d", "全属性+30%")
-- 添加飞剑点击动画效果
local function addSwordAnimation(swordWidget)
local function callback()
SL:print("飞剑动画播放完成")
end
GUI:runAction(swordWidget,
GUI:ActionSequence(
GUI:ActionScaleTo(0.1, 1.4),
GUI:ActionScaleTo(0.1, 1),
GUI:CallFunc(callback)
)
)
end
-- 为每个按钮绑定动画
GUI:addOnClickEvent(btn1, function()
addSwordAnimation(sword1)
end)
GUI:addOnClickEvent(btn2, function()
addSwordAnimation(sword2)
end)
GUI:addOnClickEvent(btn3, function()
addSwordAnimation(sword3)
end)
GUI:addOnClickEvent(btn4, function()
addSwordAnimation(sword4)
end)
-- 添加一个标题
local title = GUI:Text_Create(parent, "title", 400, 500, 24, "#ffffff", "四把飞剑展示")
GUI:Text_setFontName(title, "fonts/font5.ttf")
GUI:setAnchorPoint(title, 0.50, 0.50)
SL:print("四把飞剑界面创建完成!")
```
这段代码创建了一个完整的4把飞剑展示界面,包含:
1. 背景图片
2. 4把飞剑的图标
3. 每把飞剑对应的按钮
4. 飞剑名称和属性描述
5. 点击动画效果
6. 统一的字体样式和描边效果
所有函数都来自996引擎的GUI模块,可以直接使用。如果需要添加更多功能,比如飞剑的获取逻辑、属性加成等,可以在此基础上继续扩展。
← 返回问答库