因此,我试图在ROBLOX中制作一个基本的GUI动画系统,使用单个框架和一个循环将它们放入图像标记中。
这是一项功能:
local playAnimation = coroutine.create(function(anim,pos,tank)
while true do
local animBase = sp.AnimBase:Clone()
animBase.Parent = tank
animBase.Visible = true
animBase.Position = pos -- line that causes the error mentioned below.
local frame = 1
for i = 0, animations[anim]["FrameNum"] do
frame = frame + 1
animBase.Image = animations[anim]["Frames"][frame]
NewWait(.1) --this right here, the wait, interfears with the yield.
if frame >= animations[anim]["FrameNum"] then
pos,anim,tank = coroutine.yield()
break
end
end
animBase:Destroy()
end
end)这有两个主要问题:每次运行时,我都会得到以下错误:
20:41:01.934 - Players.Player1.PlayerGui.ScreenGui.Gui-MAIN:65: bad argument #3 to 'Position' (UDim2 expected, got number)尽管这个错误似乎没有起到任何作用。(例如,完全停止脚本)
导致错误的行被标记为注释。
我已经确认了pos是正确的。我甚至尝试在设置它之前打印它,它打印正确的东西:{0,120},{0,65}
另一个主要的问题是我不能在使用它一次之后继续使用它。它可以多次很好地运行这一行:
coroutine.resume(playAnimation,"Cannon Fire",UDim2.new(0,120,0,68-25),tank.Frame)但它不能运行:
if tank2:FindFirstChild("Ammo") and isTouching(ammoFrame,tank2:GetChildren()[3]) then
local lastAmmoPos = ammoFrame.Position
ammoFrame:Destroy()
coroutine.resume(playAnimation,"Explosion",lastAmmoPos-UDim2.new(0,25-(ammoTypes[type]["Size"].X.Offset)/2,0,25),tank.Frame)
tank2:GetChildren()[3]:Destroy()
end是的,如果语句运行良好。ammoFrame被摧毁了,tank2的第三个孩子也被摧毁了。合作线就不会恢复了。
发布于 2016-05-29 15:24:20
通过完全删除coroutine并将for循环封装在一个产卵函数中进行修正。
local playAnimation = function(anim,pos,tank)
local animBase = sp.AnimBase:Clone()
animBase.Parent = tank
animBase.Visible = true
animBase.Position = pos
local frame = 1
spawn(function()
for i = 0, animations[anim]["FrameNum"] do
frame = frame + 1
animBase.Image = animations[anim]["Frames"][frame]
wait(.1) --this right here, the wait, interfears with the yield.
if frame >= animations[anim]["FrameNum"] then
break
end
end
animBase:Destroy()
end)
endhttps://stackoverflow.com/questions/37503233
复制相似问题