问题描叙:现在序列帧的原点坐标一直在在装备提示框的最底部需要把他挂载到最顶部
EquipmentTooltip.lua文件如下:
EquipmentTooltip = {}
-- 装备名字与序列帧路径的映射配置
EquipmentTooltip.frameSettings = {
-- 格式:装备名字 = {序列帧路径, 序列帧数量}
["圣战戒指"] = {"res/custom2/comm/itemeff/01/1_", 10},
-- 可以继续添加更多装备配置
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-05-06 17:21:35 |
👁️ 阅读: 11
根据浮生梦老师前端课程内容,序列帧原点坐标在装备提示框底部的问题,可以通过调整锚点设置来解决。在您提供的代码中,序列帧创建后需要设置正确的锚点来定位到顶部。
在 `EquipmentTooltip.lua` 文件的 `createFrameAnimation` 函数中,序列帧创建后需要设置锚点。根据知识库中的 `GUI:setAnchorPoint` 函数,可以将锚点设置为顶部(0, 1)表示左上角对齐。
以下是修改后的 `createFrameAnimation` 函数代码:
```lua
function EquipmentTooltip:createFrameAnimation(parent, ID, x, y, framePath, frameCount, width, height)
local ext = {
count = frameCount,
speed = 10,
loop = -1,
finishhide = 0 -- 播放结束不隐藏
}
local frameSprite = GUI:Frames_Create(
parent,
ID,
0,
0,
framePath,
".png",
1,
frameCount,
ext
)
-- 检查是否创建成功
if GUI:Win_IsNull(frameSprite) then
SL:Print("序列帧创建失败!")
return nil
else
SL:Print("序列帧创建成功")
-- 关键修改:设置锚点为左上角(0,1)
GUI:setAnchorPoint(frameSprite, 0, 1)
-- 设置位置为顶部
local parentSize = GUI:getContentSize(parent)
local frameSize = GUI:getContentSize(frameSprite)
-- 计算顶部位置
local topY = parentSize.height
GUI:setPosition(frameSprite, 0, topY)
return frameSprite
end
end
```
关键修改说明:
1. `GUI:setAnchorPoint(frameSprite, 0, 1)` - 将锚点设置为左上角(水平左对齐,垂直顶部对齐)
2. 获取父容器尺寸后,将序列帧的Y坐标设置为父容器高度,使其定位到顶部
3. X坐标设置为0,保持左对齐
这样修改后,序列帧的原点坐标就会挂载到装备提示框的顶部位置。
← 返回问答库