我正在尝试制作一个在触发事件时上下跳动的帧(已经完成了事件并且它完美地工作)但是我不知道如何使用帧并且我真的想让帧执行效果如上所述,另外一件事是它可以在触发另一个事件后向下滑动并离开屏幕吗?
Heyo,开发者中心有很棒的tutorials for working with with Frames and Guis!这听起来像TweenService将解决你的问题!
我不知道你正在接受什么信号,但这里有一个你想做的事情的简单例子:
1)在StarterGui中创建一个ScreenGui。
2)将一个TextButton添加到ScreenGui,我们将听取对此的点击以切换框架的打开和关闭。
3)向ScreenGui添加一个Frame,添加一些东西。自定义它,移动它。
4)将LocalScript添加到ScreenGui。将其添加到脚本中......
-- grab some UI Elements
local TweenService = game:GetService("TweenService")
local btn = script.Parent.TextButton
local testFrame = script.Parent.Frame
-- make some variables
local isVisible = false
local currentTween
local onscreenPos = testFrame.Position
local offscreenPos = UDim2.new(onscreenPos.X.Scale - 1,
onscreenPos.X.Offset,
onscreenPos.Y.Scale,
onscreenPos.Y.Offset)
-- make a helper function for animating the frame
local function tweenToPos(thing, target)
local tweenInfo = TweenInfo.new(0.5, -- how long should this play (seconds)
Enum.EasingStyle.Bounce, -- << This will give you the bounce in look
Enum.EasingDirection.Out,
0, -- number of times to repeat
false, -- reverses
0) -- how many seconds to delay the animation
local propertyTable = {
Position = target,
}
local tween = TweenService:Create(thing, tweenInfo, propertyTable)
return tween
end
-- move the frame off-screen to begin with
testFrame.Position = offscreenPos
-- connect to the button and toggle between on/offscreen
btn.Activated:Connect(function(inputObj)
-- if the tween is already running, cancel it
if currentTween then
if currentTween.PlaybackState == Enum.PlaybackState.Playing
or currentTween.PlaybackState == Enum.PlaybackState.Delayed
or currentTween.PlaybackState == Enum.PlaybackState.Paused then
currentTween:Cancel()
end
end
-- create a new tween to animate the frame
if isVisible then
currentTween = tweenToPos(testFrame, offscreenPos)
else
currentTween = tweenToPos(testFrame, onscreenPos)
end
-- play the animation
currentTween:Play()
-- toggle which tween to use next
isVisible = not isVisible
end)
进出这应该有一个很好的反弹效果。你可以用你正在听的任何信号换掉btn.Activated:Connect
,这应该可以正常工作。
希望这有帮助!
Heyo,因为当用户在框架上悬停时你试图制作动画,请按照以下步骤操作......
1)在StarterGui中创建一个ScreenGui。
2)向ScreenGui添加一个Frame,将其名称更改为HoverFrame,我们将在其上侦听鼠标事件以切换动画状态。
3)向ScreenGui添加另一个Frame,将其名称更改为TweenFrame,添加一些内容。自定义它,移动它,这是我们将在屏幕上制作动画。
4)将LocalScript添加到ScreenGui。双击打开它,然后将其添加到脚本中......
-- grab some UI Elements
local hoverFrame = script.Parent.HoverFrame
local testFrame = script.Parent.TweenFrame
-- make some variables
local TweenService = game:GetService("TweenService")
local currentTween
local onscreenPos = UDim2.new(0,0,0.443,0)
local offscreenPos = UDim2.new(0,0,0.914,0)
-- make a helper function for animating the frame
local function tweenToPos(thing, target)
local tweenInfo = TweenInfo.new(0.5, -- how long should this play (seconds)
Enum.EasingStyle.Bounce, -- << This will give you the bounce in look
Enum.EasingDirection.Out,
0, -- number of times to repeat
false, -- reverses
0) -- how many seconds to delay the animation
local propertyTable = {
Position = target,
}
local tween = TweenService:Create(thing, tweenInfo, propertyTable)
return tween
end
-- make another helper function for handling the animation tween
local function cancelTweenIfPlaying()
if currentTween then
if currentTween.PlaybackState == Enum.PlaybackState.Playing
or currentTween.PlaybackState == Enum.PlaybackState.Delayed
or currentTween.PlaybackState == Enum.PlaybackState.Paused then
currentTween:Cancel()
end
end
end
-- listen for when the mouse hovers over the button, and animate the frame
hoverFrame.MouseEnter:Connect(function(x, y)
-- if there is an animation playing, cancel it.
cancelTweenIfPlaying()
-- animate the frame to center stage
currentTween = tweenToPos(testFrame, onscreenPos)
currentTween:Play()
end)
-- listen for when the mouse stops hovering over the button
hoverFrame.MouseLeave:Connect(function(x, y)
-- if the tween is already running, cancel it
cancelTweenIfPlaying()
-- animate to offscreen
currentTween = tweenToPos(testFrame, offscreenPos)
currentTween:Play()
end)
希望这有帮助!