为什么位置补间不起作用?

我对Lua还比较新,正在尝试在Roblox中制作游戏。我目前正在为我的矿工GUI上的打开和关闭按钮工作。

代码

local Frame = script.Parent.Parent.Parent.Parent.Parent.MinerGuiManager.MinerFrame
local Opened = false
if Opened == false then
    print('Gui已关闭')
    Opened = true
end
if Opened == true then
    print('Gui已打开')
end
script.Parent.Button.MouseButton1Click:connect(function()
    GUI:TweenPosition(UDim2.new(1, 0, 1, 0),'Bounce',1.5)


end)

我想让GUI消失和重新出现

游戏

点赞
用户2860267
用户2860267

GUIObject:TweenPosition 函数有一些参数。有些参数是默认值,但是如果你想覆盖它们,你需要按正确的顺序覆盖它们。你的例子似乎缺少了 easingDirection 参数。

此外,你需要在要动画的对象上调用 TweenPosition。在你的例子中,它将是变量 Frame

-- 定义一些变量并相对于脚本的位置获取一些 UI 元素
local Button = script.Parent.Button
local Frame = script.Parent.Parent.Parent.Parent.Parent.MinerGuiManager.MinerFrame
local Opened = false

Button.MouseButton1Click:connect(function()
    local TargetPos
    if Opened then
        -- 将框架移出屏幕到右下角
        -- 注意 - 一旦移出屏幕,我们将无法点击按钮
        --        并将其带回屏幕...(稍后更改此数字)
        TargetPos = UDim2.new(1, 0, 1, 0)
    else
        -- 将框架移动到屏幕中心
        local frameWidthOffset = Frame.Size.X.Offset * -0.5
        local frameHeightOffset = Frame.Size.Y.Offset * -0.5
        TargetPos = UDim2.new(0.5, frameWidthOffset, 0.5, frameHeightOffset)
    end

    -- 将框架动画到目标位置,持续 1.5 秒
    local EaseDir = Enum.EasingDirection.Out
    local EaseStyle = Enum.EasingStyle.Bounce
    Frame:TweenPosition(TargetPos, EaseDir, EaseStyle, 1.5)

    -- 切换 Opened 的值
    Opened = not Opened
end)
2019-06-18 20:38:26