1. #1
    Deleted

    [lua] Animationgroup

    hello all,

    i've written this little combatindicator for my interface.
    what it should basically do is to scroll down from the top, stay the for combat, and scroll up when combat ends.

    it's the first time i use the "translation" animation.

    Code:
        BEUCombat1 = CreateFrame("FRAME", nil, UIParent)
            BEUCombat1:SetWidth(100)
            BEUCombat1:SetHeight(100)
            BEUCombat1:SetPoint("BOTTOM", UIParent, "TOP", 0, 0)
            BEUCombat1:SetFrameStrata("BACKGROUND")
            BEUCombat1:SetFrameLevel(0)
            BEUCombat1:Show()
            
            BEUCombat1Tex = BEUCombat1:CreateTexture()
                BEUCombat1Tex:SetAllPoints()
                BEUCombat1Tex:SetTexture("Interface\\AddOns\\!beatemupmedia\\statusbar\\white.tga")
                BEUCombat1Tex:SetVertexColor(1, 1, 0, 1)
    
    
                
        BEUCombat2 = CreateFrame("FRAME", nil, UIParent)
            BEUCombat2:SetWidth(100)
            BEUCombat2:SetHeight(100)
            BEUCombat2:SetPoint("BOTTOM", UIParent, "TOP", 0, -100)
            BEUCombat2:SetFrameStrata("BACKGROUND")
            BEUCombat2:SetFrameLevel(0)
            BEUCombat2:Hide()
      
            BEUCombat2Tex = BEUCombat2:CreateTexture()
                BEUCombat2Tex:SetAllPoints()
                BEUCombat2Tex:SetTexture("Interface\\AddOns\\!beatemupmedia\\statusbar\\white.tga")
                BEUCombat2Tex:SetVertexColor(1, 0, 1, 1)
               
                
                    BEUCombat1.ag = BEUCombat1:CreateAnimationGroup()
                        BEUCombat1.ag.a1 = BEUCombat1.ag:CreateAnimation("Translation")
                        BEUCombat1.ag.a1:SetSmoothing("OUT")
                        BEUCombat1.ag.a1:SetOffset(0, -72)
                        BEUCombat1.ag.a1:SetDuration(2)
                        BEUCombat1.ag:SetLooping("NONE")
    
                        
                    BEUCombat2.ag = BEUCombat2:CreateAnimationGroup()
                        BEUCombat2.ag.a2 = BEUCombat2.ag:CreateAnimation("Translation")
                        BEUCombat2.ag.a2:SetSmoothing("OUT")
                        BEUCombat2.ag.a2:SetOffset(0, 100)
                        BEUCombat2.ag.a2:SetDuration(2)
                        BEUCombat2.ag:SetLooping("NONE")
                    
    
                BEUCombat1:RegisterEvent("PLAYER_ENTERING_WORLD")
                BEUCombat1:RegisterEvent("PLAYER_REGEN_DISABLED")
                BEUCombat1:RegisterEvent("PLAYER_REGEN_ENABLED")
    
                BEUCombat2:RegisterEvent("PLAYER_ENTERING_WORLD")
                BEUCombat2:RegisterEvent("PLAYER_REGEN_DISABLED")
                BEUCombat2:RegisterEvent("PLAYER_REGEN_ENABLED")
    
    
                BEUCombat1:SetScript("OnEvent", function(frame, event) if event == "PLAYER_ENTERING_WORLD" then BEUCombat1:Show() end end)
                BEUCombat2:SetScript("OnEvent", function(frame, event) if event == "PLAYER_ENTERING_WORLD" then BEUCombat2:Hide() end end)
                
                BEUCombat1:SetScript("OnEvent", function(frame, event) 
                        if
                            event == "PLAYER_REGEN_DISABLED" 
                        
                        then
                            BEUCombat1.ag:Play()
                            BEUCombat1.ag:SetScript("OnFinished",function() BEUCombat2:Show() BEUCombat1:Hide() end) 
                      
                        elseif
                            event == "PLAYER_REGEN_ENABLED"
                            
                        then
                            BEUCombat2.ag:Play()
                            BEUCombat2.ag:SetScript("OnFinished",function() BEUCombat1:Show() BEUCombat2:Hide() end)
                      
                    end
                end)
    how can this be done better?

    oh and one or two other questions.
    why does the first frame pops up for like 0.1 sec after combat ends?
    why do i have to set the offset from frame one to -72 to fit the textures together?


    thx for helping

  2. #2
    Deleted
    The first things I noticed:

    1. Do you have a good reason for those frame variables to be globals? I can't see any from your code.
    2. You SetScript two different OnEvent scripts on BEUCombat1. The second one will overwrite the first one. Also, the two PLAYER_ENTERING_WORLD events aren't really needed (you already set initial state properly) unless you want them to show/hide each time you go through a loading screen.
    3. You create a new function for OnFinished every time it is called. Just setting them once will do the same, as you never change them, just replace them with the same function.

    As for your actual questions, I sadly can't help you, as I've never worked with animgroups much.

  3. #3
    Quote Originally Posted by Vyntrox View Post
    why does the first frame pops up for like 0.1 sec after combat ends?
    why do i have to set the offset from frame one to -72 to fit the textures together?
    Both are basically the results of quirks with the animation system. You could achieve a similar result just using the animation as a timer and have more control:
    Code:
    local frame = CreateFrame("Frame", nil, UIParent)
    frame:SetSize(100, 100)
    frame:SetPoint("TOP", 0, 100)
    frame:SetFrameStrata("BACKGROUND")
    frame:SetFrameLevel(0)
    
    local texture = frame:CreateTexture()
    texture:SetAllPoints()
    texture:SetTexture([[Interface\AddOns\!beatemupmedia\statusbar\white.tga]])
    texture:SetVertexColor(1, 0, 1)
    
    local animationGroup = frame:CreateAnimationGroup()
    animationGroup:SetLooping("REPEAT")
    local animation = animationGroup:CreateAnimation()
    animation:SetDuration(2 / 100)    -- 2 seconds to shift 100 pixels
    
    local offset, offsetAdjust = 100, 1
    
    animationGroup:SetScript("OnLoop", function(self)
        offset = offset + offsetAdjust
        if offset >= 100 then
            offset = 100
            self:Stop()
        elseif offset <= 0 then
            offset = 0
            self:Stop()
            texture:SetVertexColor(1, 0, 1)
        end
        frame:SetPoint("TOP", 0, offset)
    end)
    
    frame:SetScript("OnEvent", function(self, event)
        if event == "PLAYER_REGEN_DISABLED" then
            if offset > 0 then
                offsetAdjust = -1
                animationGroup:Play()
                texture:SetVertexColor(1, 1, 0)
            end
        elseif offset < 100 then
            offsetAdjust = 1
            animationGroup:Play()
            texture:SetVertexColor(1, 0, 1)
        end
    end)
    frame:RegisterEvent("PLAYER_REGEN_DISABLED")
    frame:RegisterEvent("PLAYER_REGEN_ENABLED")

  4. #4
    Deleted
    @vexxilus: wow,works like a charm now

    thanks to both of you for helping me that fast.

  5. #5
    Deleted
    If you want to dig more into animationgroups check this thread: http://www.wowinterface.com/forums/s...ad.php?t=35104

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •