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)
根据浮生梦老师前端课程内容,要实现螺旋旋转动画,可以使用`ActionSpawn`组合旋转和移动动作。以下是修改后的代码:
```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 = {}
-- 获取nd_Item的起始位置
local startNode = self.ui.nd_Item
local startPos = GUI:getPosition(startNode)
local startX = startPos.x
local startY = startY
-- 重新创建红点,使用当前转盘对应的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 }
-- 设置起始位置为nd_Item位置
GUI:setPosition(item, startX, startY)
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:ActionSpawn(
GUI:ActionMoveTo(0.5, originalPositions[i].x, originalPositions[i].y), -- 移动到原始位置
GUI:ActionRotateBy(0.5, 720) -- 旋转720度(2圈)
)
)
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. **起始位置**:所有item从`nd_Item`控件的位置开始
2. **螺旋效果**:使用`GUI:ActionSpawn()`同时执行移动和旋转动作
3. **旋转参数**:`GUI:ActionRotateBy(0.5, 720)`在0.5秒内旋转720度(2圈)
4. **延迟效果**:每个item延迟0.1秒开始,形成依次出现的视觉效果
**注意:**
- 需要确保`self.ui.nd_Item`控件存在且不为空
- 旋转角度可以根据需要调整(360度为1圈)
- 如果希望旋转方向相反,可以使用负值如`-720`
如果还有不理解的地方,随时问浮生梦老师哦!