lua - 为什么不补间位置?

我是 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

最佳答案

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)

https://stackoverflow.com/questions/56503874/

相关文章:

tensorflow - 基于直方图定义 TF 中的损失函数

c# - 使用 AddOpenIdConnect 时,为什么要添加默认范围?

python - "pyenv virtualenvwrapper"是做什么的?

typescript - Promise.resolve(null) 的目的是什么

reactjs - Webpack 无法导入带有 ` 标记的 React 组件

javascript - 将 Uint8Array 转换为 Float32Array

javascript - 简单的 react-spring 组件在 gatsby 中不起作用 - 元

angular - 我的 Angular 应用程序的规模(缩放)在生产中单独增加

.net-core - 错误 UseHealthChecksUI 遇到意外字符

r - 在 R studio 中安装 factoextra 包