gpt4 book ai didi

lua - 为什么不补间位置?

转载 作者:行者123 更新时间:2023-12-05 07:22:26 24 4
gpt4 key购买 nike

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

关于lua - 为什么不补间位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56503874/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com