function zhuanpanOBJ:createItemShow()
-- 先清理已存在的红点
for i = 1, 8 do
local item = self.ui["item_" .. i]
if item and not GUI:Win_IsNull(item) then
local oldRedDot = GUI:getChildByName(item, "Image_bg_" .. i)
根据浮生梦老师前端课程内容,我来帮你实现道具创建后的飞入动画效果。
```lua
function zhuanpanOBJ:createItemShow()
-- 先清理已存在的红点
for i = 1, 8 do
local item = self.ui["item_" .. i]
if item and not GUI:Win_IsNull(item) then
local oldRedDot = GUI:getChildByName(item, "Image_bg_" .. i)
if oldRedDot and not GUI:Win_IsNull(oldRedDot) then
GUI:removeFromParent(oldRedDot)
end
end
end
-- 保存道具原始位置
local originalPositions = {}
-- 重新创建红点,使用当前转盘对应的cfg表格
local currentCfg = self.cfg[self.currentTable]
for i = 1, 8 do
local cfgData = currentCfg[i]
if cfgData then
local item = GUI:ItemShow_Create(self.ui["item_" .. i], "item", 0, 0,
{ index = cfgData.showReward[1][1], look = true, count = cfgData.showReward[1][2] })
GUI:setAnchorPoint(item, 0.5, 0.5)
-- 记录原始位置
local pos = GUI:getPosition(self.ui["item_" .. i])
originalPositions[i] = {x = pos.x, y = pos.y}
-- 先将道具移动到屏幕中心
local centerX = 480 -- 假设屏幕中心X坐标
local centerY = 320 -- 假设屏幕中心Y坐标
GUI:setPosition(item, centerX, centerY)
GUI:setOpacity(item, 0) -- 初始透明
-- 检查数据有效性,使用当前转盘的数据
if self.Data and self.Data[tostring(self.currentTable)] and
self.Data[tostring(self.currentTable)].reward and
self.Data[tostring(self.currentTable)].reward[tostring(i)] == 1 then
-- 添加红点标记已获取
local imgPath = "res/custom/common/zt/zaixian1.png"
local Image_bg = GUI:Image_Create(item, "Image_bg_" .. i, -25, -15, imgPath)
GUI:setOpacity(Image_bg, 0) -- 红点也初始透明
end
-- 创建飞行动画序列
local flyAction = GUI:ActionSequence(
GUI:DelayTime(i * 0.1), -- 依次延迟显示
GUI:ActionFadeTo(0.2, 255), -- 淡入
GUI:ActionMoveTo(0.5, originalPositions[i].x, originalPositions[i].y) -- 飞到原始位置
)
GUI:runAction(item, flyAction)
-- 红点动画(如果有)
local redDot = GUI:getChildByName(item, "Image_bg_" .. i)
if redDot and not GUI:Win_IsNull(redDot) then
local redDotAction = GUI:ActionSequence(
GUI:DelayTime(i * 0.1 + 0.5), -- 道具到位后显示红点
GUI:ActionFadeTo(0.3, 255)
)
GUI:runAction(redDot, redDotAction)
end
end
end
end
```
**关键点说明:**
1. **位置记录**:先保存每个道具的原始位置到`originalPositions`表中
2. **初始设置**:创建后立即将道具移动到屏幕中心并设置为透明
3. **动画序列**:使用`ActionSequence`组合多个动作
4. **延迟效果**:通过`DelayTime`实现道具依次飞出的效果
5. **红点处理**:道具到位后再淡入红点标记
**注意事项:**
- 屏幕中心坐标(480, 320)需要根据你的实际界面调整
- 动画时间参数可以根据需要调整:0.5秒飞行时间,0.1秒间隔
- 如果道具父节点不是绝对定位,可能需要调整坐标计算方式
这样实现后,8个道具会依次从屏幕中心飞到各自的原始位置,形成漂亮的飞入效果!