为什么位置不补间?

时间:2019-06-08 05:53:36

标签: lua roblox

问题

你好!我对Lua相当陌生,我正尝试在Roblox中进行游戏。我目前正在使用Miner GUI上的打开和关闭按钮。

代码

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


end)

我希望GUI消失并重新出现

游戏

Game

1 个答案:

答案 0 :(得分:0)

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

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

-- define some variables and grab some UI elements relative to the script's location
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
        -- move the frame offscreen to the lower right
        -- NOTE - once we move it offscreen, we won't be able to click the button
        --        and bring it back onscreen... (change this number later)
        TargetPos = UDim2.new(1, 0, 1, 0)
    else
        -- move the frame to the center of the screen
        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

    -- animate the frame to the target position over 1.5 seconds
    local EaseDir = Enum.EasingDirection.Out
    local EaseStyle = Enum.EasingStyle.Bounce
    Frame:TweenPosition(TargetPos, EaseDir, EaseStyle, 1.5)

    -- toggle the Opened value
    Opened = not Opened
end)