Roblox Studio如何制作一个画框向上下弹跳后定位于某一位置
2019-3-1 15:29:27
收藏:0
阅读:98
评论:2
我试图制作一个画框,当事件被触发时可以向上下弹跳(已经解决了该事件,并且它运行得非常完美)。然而,我不知道如何处理画框,我真的希望能够让画框产生上述效果。另外一件事是,当另一个事件被触发时,它能否滑下并离开屏幕?
点赞
用户2860267
嘿,既然你想在用户悬停在帧上时动画化,那么请按照以下步骤执行...
1)在StarterGui中创建一个ScreenGui。
2)将一个Frame添加到ScreenGui中,将其名称更改为HoverFrame,我们将在此监听鼠标事件以切换动画状态。
3)在ScreenGui中添加另一个Frame,将其名称更改为TweenFrame,向其添加一些内容。自定义它,将它移动到屏幕上,这是我们将在屏幕上动画化的内容。
4)在ScreenGui中添加一个LocalScript。双击打开它,并添加以下内容到脚本中...
-- 获取一些UI元素
local hoverFrame = script.Parent.HoverFrame
local testFrame = script.Parent.TweenFrame
-- 创建一些变量
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)
-- 创建一个辅助函数来动画化帧
local function tweenToPos(thing, target)
local tweenInfo = TweenInfo.new(0.5, -- 播放时间(秒)
Enum.EasingStyle.Bounce, -- << 这将为您提供反弹的外观
Enum.EasingDirection.Out,
0, -- 重复的次数
false, -- 反方向
0) -- 动画延迟的时间
local propertyTable = {
Position = target,
}
local tween = TweenService:Create(thing, tweenInfo, propertyTable)
return tween
end
-- 创建另一个辅助函数来处理动画化帧的过渡
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
-- 监听鼠标悬停在按钮上的事件,并动画化帧
hoverFrame.MouseEnter:Connect(function(x, y)
-- 如果有正在播放的动画,则取消它。
cancelTweenIfPlaying()
-- 将帧动画化为中心位置
currentTween = tweenToPos(testFrame, onscreenPos)
currentTween:Play()
end)
-- 监听鼠标停止悬停在按钮上的事件
hoverFrame.MouseLeave:Connect(function(x, y)
-- 如果动画正在运行,则取消它
cancelTweenIfPlaying()
-- 动画化为屏幕外位置
currentTween = tweenToPos(testFrame, offscreenPos)
currentTween:Play()
end)
希望能对你有所帮助!
2019-03-05 17:22:58
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

嘿,开发人员中心有关于使用Frames和Guis的教程!
听起来TweenService是可以解决您的问题的东西!
我不知道您正在使用的信号,但是下面是一个简单的例子:
1)在StarterGui中创建一个ScreenGui。
2)在ScreenGui中添加一个TextButton,我们将在其上监听单击以打开和关闭Frame。
3)在ScreenGui中添加一个Frame,添加一些内容。自定义它,移动它。
4)在ScreenGui中添加一个LocalScript,并将以下代码添加到脚本中:
-- 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,这应该可以正常工作。希望能对您有所帮助!