Go Back   WowAce Forums > Tips, FAQs, and Guides

Reply
 
Thread Tools
Old 01-07-2013   #1
funkydude
Administrator
 
funkydude's Avatar
 
Join Date: Nov 2005
Location: Scotland, UK
Posts: 2,987
Default Replacing UIFrameFlash with Animations

It seems there are still authors unaware that the use of UIFrameFlash/Fade functions are a source of taint, and it has been so for quite literally, years. These functions were never actually intended to be used by addons as can be seen by the way they are implemented.

This is a short guide to implementing the same behaviour using the animation system.

Replacing UIFrameFlash:
Quote:
UIFrameFlash(myFrame, fadeInTime, fadeOutTime, flashDuration, showWhenDone, flashInHoldTime, flashOutHoldTime)
The following example assumes "myFrame" is the frame you want to flash. First, create an animation group (container) attached to your frame:
Quote:
local flasher = myFrame:CreateAnimationGroup()
Now you need to create the animations. In this example, I flash my frame in and out. Each fade in/out lasts 0.5 seconds, totalling 1 second. My frame is currently shown but has an Alpha value of 0.

Quote:
local fade1 = flasher:CreateAnimation("Alpha")
fade1:SetDuration(0.5)
fade1:SetChange(1)
fade1:SetOrder(1)

local fade2 = flasher:CreateAnimation("Alpha")
fade2:SetDuration(0.5)
fade2:SetChange(-1)
fade2:SetOrder(2)
The :SetChange call dictates the "direction" you want to fade your frame. In this case, I used "1" to make the frame fully visible, then "-1" to make the frame transparent again.

Now, to execute this flash all I need to call is :Play on the animation group I created.

Quote:
flasher:Play()
That's a simple example of fading a transparent frame in and out, it will return to being transparent once the animation is finished. But what if you want it to be visible after the animation has completed? Here's how to implement the "showWhenDone" functionality.

Quote:
flasher:SetScript("OnFinished", function() myFrame:SetAlpha(1) end)
The OnFinished script runs when your animation finishes, and in this case, makes your frame "show when done".

Now to cover the final args, "holding" time. The animation system has an in-built delay system (:SetStartDelay, :SetEndDelay). In this case, end delay can be used to achieve both "flashOutHoldTime" and "flashInHoldTime". In the following example I've added a hold in and hold out time, lasting 1 second each, using end delays:

Quote:
-- Flashing in
local fade1 = flasher:CreateAnimation("Alpha")
fade1:SetDuration(0.5)
fade1:SetChange(1)
fade1:SetOrder(1)

-- Holding it visible for 1 second
fade1:SetEndDelay(1)

-- Flashing out
local fade2 = flasher:CreateAnimation("Alpha")
fade2:SetDuration(0.5)
fade2:SetChange(-1)
fade2:SetOrder(3)

-- Holding it for 1 second before calling OnFinished
fade2:SetEndDelay(1)
Now my frame will fade in over 0.5 seconds, will sit there for 1 second, will fade out over 0.5 seconds, will sit there faded out for 1 second. After that is done, it will call OnFinished.

Last edited by funkydude; 01-07-2013 at 02:19 AM.
funkydude is offline   Reply With Quote
Old 01-07-2013   #2
Kemayo
Full Member
 
Join Date: Mar 2006
Posts: 204
Default Re: Replacing UIFrameFlash with Animations

You should be able to use `fade2:SetStartDelay(1)` or `fade1:SetEndDelay(1)` to replace the need for `hold`, as I understand it.
Kemayo is offline   Reply With Quote
Old 01-07-2013   #3
funkydude
Administrator
 
funkydude's Avatar
 
Join Date: Nov 2005
Location: Scotland, UK
Posts: 2,987
Default Re: Replacing UIFrameFlash with Animations

Thanks! Edited that in.
funkydude is offline   Reply With Quote
Old 01-08-2013   #4
LaoTseu
Senior Member
 
Join Date: Jun 2006
Posts: 490
Default Re: Replacing UIFrameFlash with Animations

Thanks for this, it makes it very easy to implement.

Quick question : wowpedia doesn't list the script handlers for animation. Anyone can point me where I can get the list? In particular, I'm looking for a "before starting the anim" handler.

[Edit: found it, it's OnPlay. I guess I'll go update the Widget handlers page now.]

Last edited by LaoTseu; 01-08-2013 at 01:32 PM.
LaoTseu is offline   Reply With Quote
Old 01-22-2013   #5
oscarucb
Junior Member
 
oscarucb's Avatar
 
Join Date: Dec 2007
Posts: 68
Default Re: Replacing UIFrameFlash with Animations

Great info!

Is there a guide or organized list somewhere of "best practices" for avoiding common sources of taint in addon dev? (ie what *else* are addons commonly doing wrong)
oscarucb is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:07 PM.