"Pulsating" effect...what's the proper method?
I have frame "frame". I want it to fade from alpha "1" to alpha "0", then back to alpha "1" and repeat until I say otherwise to make a "pulsing" effect.
I tried doing this in a manner like so, and...well...yeah, infinite loops are bad. lua Code:
Hello, Mr. Client Crash. :o |
Code:
local SHINE_FADE_IN = 0.15; |
Well did a quick search and there isn't much around on that subject so perhaps they hit a wall.
So far all I have seen is people utilising it on Enter and Leave scripts to do the different Fading functions. So how about this. If you have an Update function that you call every so often perhaps you can put it in there to fadein if it has faded out or to fade out if it has faded in. Then keep a variable to store the last value updated. It's not perfect but might be the only way you can deal with it and even throwing the cycle in every event you watch may be a good idea too. The combination of the two functions may be enough to make it look passable at least. Edit: Or what d87 said :D |
Pretty elegant IMO:
lua Code:
|
*book marks post so I can come back and ste... erm I mean utilise the code* :D
Quote:
|
You'll want to hide the frame doing the OnUpdate when it's done, else you'll be needlessly using CPU.
|
Quote:
|
Quote:
(Also bookmarking as a reference page) |
Quote:
lua Code:
|
Quote:
Quote:
|
Quote:
FINAL VERSION(I hope): lua Code:
|
Quote:
Anyway: Saying "it's using so little CPU" and then ignoring that is rather dismissive - people running 200+ AddOns which do this are suddenly using a metric ****-ton of CPU for no reason whatsoever. If you aren't currently generating a pulse, the frame should be hidden so its OnUpdate will not be run. |
Quote:
Quote:
**EDIT: Just discovered something while we're on the topic of performance that I thought should be part of this: You can set this thing to absolutely ridiculous speeds (I've personally tried it up to 150, WELL beyond my refresh rate, just to see what would happen). The only upper limit here is your computers' crash threshold. BE CAREFUL WHEN DOING THIS. The reason it was/is using so little CPU is because apparently Blizz uses GPU time for this. On my machine at 1440x900, Ultra settings w/ some cVar tweaks, fullscreen windowed, and a frame pulsing at 150, I hit around 50%-ish GPU usage on average (peak no higher than 65%) with dual 5700-series ATis. At any "normal" speed (say, 0.3 to 10.0 at the fastest) it's negligible, though. I'm also pulsing a pretty big frame (1024x256). Really, if you need something faster than 10...don't. You're gonna give kids seizures. |
Check blackbox (http://wow.curseforge.com/addons/blackboxlua/)
You may want to look at the animation system. Blizzard uses this kind of stuff for the Glyph window. http://wowprogramming.com/utils/xmlb...rd_GlyphUI.lua Look out for "PulseGlow". The cool stuff is that you can "PLAY" and "STOP" those animations as you wish. I cannot recommend onUpdate stuff anymore, the animations are much more valuable imo since they eat nearly no cpu usage instead of those nasty onupdates. I'm using the animation system for rFrameRotater. Since you can "LOOP" animations it will start and never stop. (If you say so.) Very simple rotate-function that I'm using to rotate stuff. Code:
function a:rotateme(texture,width,height,scale,anchorframe,framelevel,texr,texg,texb,alpha,duration,side,blendmode,point,pointx,pointy) So sth. like this could be it, don't know the exact syntax http://wowprogramming.com/docs/widgets/Alpha/SetChange Code:
local h = CreateFrame("Frame",nil,UIParent) With the animation system you can do this in just one animationgroup. - move (translate) - rotate - scale - change alpha You can even add a path the frame will move on. |
Cool, I was wondering the use for animation barring prettifying movement around the screen. But if it's the better option than onUpdate it may be the way to go.
|
I'm not sure about how it would work in lua, but any pulsating effect can be achieved with a simple sinus function.
pseudo code: var sequence = 0; sequence ++; AlphaProperty = sin(sequence); this would result in the AlphaProperty going from 0 to 1, then from 1 to 0 and so on. google 'math sin lua' for more info :) Good luck |
http://www.wowwiki.com/API_UIFrameFlash
UIFrameFlash(frame, fadeInTime, fadeOutTime, flashDuration, showWhenDone, flashInHoldTime, flashOutHoldTime) if you call it more than once(while it's active) - you'll need something that blocks this calls: (atleast for UIFrameFadeIn it makes it nearly go to infinite time - if called unnecessary times (even if you use :GetAlpha()) - you would need something like spareTime=totaltime-(GetAlpha()/totaltime)) (Note this is for UIFrameFadeIn, and not UIFrameFlash) Code:
local fade_in = {} (Note inTable returns boolean,index of value in table(numeric)) dunno if you can 'calculate' the Pulse-time or want to fix it to some number |
Quote:
|
Quote:
Code:
do |
Quote:
Code:
last_update = last_update -0.25 |
Quote:
|
Quote:
120 fps: approx. elapsed = 1/120 = 0.0083333333333333s per OnUpdate ( called frequence g in rest of text ) sampling frequency f = 0.25 Hz (or 4fps = 1/4Hz) f = 30*g so every 30-frame((n*30)%120, n<-N{0,1,2,..) the SinusFunction() is called - at this point it works fine now think of ppl having an average fps of not 120fps - like you said 10fps drawing frequency h = 1/10 Hz sampling frequency f = 0.25 Hz resulting that point of collide = frame2.5, as there is no frame 2.5, it will take frame 3 (>=) time between frame2.5 and frame3 is t=((frame3-frame2)/2); frame2 is drawn after 0.2s, frame3 after second 0.3 (on time graph) - would result in a 0.05s delay so with last_update=0, it will result in: frame1 drawn - frame2 drawn - frame3 drawn - function fires, last_update is now 0 again - frame4 drawn - frame5 drawn (NOW it should fire again - but it doesn't as this is again 0.2 not 0.25) - frame6 drawn - function fires and again 3 frames required with last_update=last_update-sampling_frequency: frame1 drawn - frame2 drawn - frame3 drawn - function fires, last_update now is 0.05 - frame4 drawn (last_update 0.15) - frame5 drawn(last_update 0.25) - function fires correctly at (50% of fps as it should with sampling frequency 0.25 - and not at 60%) - frame 6 drawn - etc... and ppl have not an average fps of continuously 120fps (atleast not the most have) |
Quote:
|
Quote:
Code:
do Code:
do |
Quote:
nah i meant this : Code:
do Quote:
|
Oh I see... That's pretty amazing :P
I still think though that using sin every quarter of a second isn't NEARLY as efficient then multiplying by -1. And I see the disadvantage of my function, it uses SetAlpha WAAAAAAAAAY too often. This should be much much more efficient. Code:
frame.mult = 1 #1 Code:
self.tslu = self.tslu + elapsed Code:
self.tslu = self.tslu + elapsed |
Quote:
i would say permanently incrementing of a variable may cause an overflow (dunno about max value in lua) - as you aren't calc the modulo and store it Code:
self.tslu = (self.tslu + elapsed)%.25 |
If I hadn't stopped playing atm I would post you an example with the animation system.
Using onUpdates to do this is out of date. |
Quote:
|
Sorry for thread hijack, but how can this code be applied to a single animation instead of a looping 'pulse'? I'm trying to add opening/closing animations to some addon frames, for example in the following code:
Code:
local function Stuffing_Open() |
Quote:
frame:SetScript('OnShow', doSomethingOnShow) or frame:SetScript('OnHide', doSomethingOnHide) ? |
Quote:
|
Use the built-in animation code:
Code:
local alpha = animationGroup:CreateAnimation("Alpha"); |
Arrrr, sometimes thread necrotism is good stuff, indeed. I somehow missed this one. *bookmarks thread* :D
|
Quote:
|
If you wanted to use the Blizzard animation API in XML, you could do something like:
Code:
<Frame> |
All times are GMT -6. The time now is 09:44 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI