Roblox studio Как сделать, чтобы рама качалась вверх и вниз, а затем приземлялась в определенной позиции - PullRequest
0 голосов
/ 01 марта 2019

Я пытаюсь создать кадр, который поднимается и опускается при срабатывании события (уже сработало событие, и оно отлично работает), однако я понятия не имею, как работать с кадрами, и я действительно хотел бы сделать кадрсделать эффект, упомянутый выше, еще одна вещь, может ли он после того, как другое событие срабатывает скользить вниз и с экрана?

Ответы [ 2 ]

0 голосов
/ 05 марта 2019

Heyo, поскольку вы пытаетесь анимировать, когда пользователь наводит курсор на рамку, выполните следующие действия ...

1) Создайте ScreenGui в StarterGui.

2) ДобавьтеКадр для ScreenGui, измените его имя на HoverFrame, мы будем слушать события мыши, чтобы переключать состояния анимации.

3) Добавить еще один кадр в ScreenGui, изменить его имя на 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)

Надеюсь, это помогло!

0 голосов
/ 03 марта 2019

Heyo, Developer Hub имеет отличные учебные пособия по работе с Frames и Guis !Похоже, TweenService - это то, что решит вашу проблему!

Я не знаю, к какому сигналу вы подключаетесь, но вот простой пример того, что вы хотите сделать:

1) Создайте ScreenGui в StarterGui.

2) Добавьте TextButton в ScreenGui, мы послушаем клики по нему, чтобы переключать фреймы в открытое и закрытое.

3) Добавьте рамку в ScreenGui, добавьте к ней некоторые вещи.Настройте его, переместите его.

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 с любым сигналом, который вы слушали, и это должно работать очень хорошо.

Надеюсь, это помогло!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...