1. #1

    kgpanels lua script

    Hey I am hoping you all can help me figure it out.

    I am wanting to animate a texture, sort of like how sexymaps does with the runes around the map, but after looking through code, I just can't quite get my head around how to do it in kgpanels, to make it rotate like sexymaps. Is it possible to do this or no?

    Thanks for the help

  2. #2
    Quote Originally Posted by Felyna View Post
    Hey I am hoping you all can help me figure it out.

    I am wanting to animate a texture, sort of like how sexymaps does with the runes around the map, but after looking through code, I just can't quite get my head around how to do it in kgpanels, to make it rotate like sexymaps. Is it possible to do this or no?

    Thanks for the help
    So, in WoW's api, there's a type of frame called texture which handles is the actual texture that is displayed. Looking through the WoW api listing over on wowprogramming.com I found texture:SetRotation() (Here) which is a method defined for the texture frame which takes in an angle in radians (0-2 Pi domain, 0 being 0 degrees, 2*pi being 360 degrees) and rotates the texture to that angle. A positive value will rotate that value CCW, while a negative value will rotate it CW.


    I don't have access to a WoW client atm, so anything I give you for a few hours will be untested, and may or may not work, so don't be surprised if it doesn't :P When I get home I'll get a working version.


    KGPanels, from what I can tell, refers to the texture frame as frame.bg, so, using that information, in your onUpdate script for the frame you want to rotate, try the following:

    Code:
    local texture, elapsed = self.bg, ...
    
    
    local speed = 15 
    -- degrees/second
    
    
    local direction = 1 
    -- 1 = CCW rotation, -1 = CW rotation
    
    
    
    local rad = elapsed*direction*speed*Math.pi/180
    texture:SetRotation(rad)

    I think that'll do what you want. Like I said before, it's completely and utterly untested, so I hope it works for you. You can change the 15 to be whatever speed you want in degrees per second, and can change the direction = 1 to a negative 1 if you want the texture to rotate clockwise.

    I hope it works

  3. #3
    i copied and pasted that into the onupdate and it theew an error:

    "cannot use '...' outside a vararg function near '...' "

    Thanks so far for the help

  4. #4
    Quote Originally Posted by Felyna View Post
    i copied and pasted that into the onupdate and it theew an error:

    "cannot use '...' outside a vararg function near '...' "

    Thanks so far for the help
    Hmmmm, so I can't use that... I need to find a way to get access to the elapsed argument of the original onupdate....... Try changing the ... to time. Soooooo,

    Code:
    local texture, elapsed = self.bg, time
    
    
    local speed = 15 
    -- degrees/second
    
    
    local direction = 1 
    -- 1 = CCW rotation, -1 = CW rotation
    
    
    
    local rad = elapsed*direction*speed*Math.pi/180
    texture:SetRotation(rad)

  5. #5
    Deleted
    Code:
    local curTime = GetTime()
    local elapsed = self.lastOnUpdate and (curTime-self.lastOnUpdate) or 0
    self.lastOnUpdate = curTime
    ?

  6. #6
    That would probably work, but I'm trying to avoid unnecessary calls as it's an onupdate script and'll be running a lot, to the point where I'd be slightly worried about calling GetTime that often when there is probably a already defined value. I was looking through the KGPanels code and found

    Code:
    if hook == "UPDATE" and strlen(code) > 1 then
    		local func, errorMessage = loadstring("return function(self,time) "..makeRef().." "..code.." end",name.."_OnUpdate")
    		if func then
    			frame:SetScript("OnUpdate",func())
    		else
    			self:Print(errorMessage)
    		end
    which is where I thought that the variable time might already be declared.

  7. #7
    Okay, i tried the update Brusalk. No error but the background texture still didn't rotate. In fact, the script caused my frame rate go from 60 vsync'd to 20.

    Tried yours Treeston but it didn't do anything

  8. #8
    Deleted
    Also, your first script doesn't consider the current rotation - it will consistently set the texture to be rotated the fraction of a degree in the selected direction from the "normal" rotation.

  9. #9
    Quote Originally Posted by Treeston View Post
    Also, your first script doesn't consider the current rotation - it will consistently set the texture to be rotated the fraction of a degree in the selected direction from the "normal" rotation.
    Guess who feels like an idiot right now. (Hint, he also has two thumbs)

    Did some more accurate research now that I'm at home, and I found a different way to go about it.

    Code:
    local duration = 60
    
    local frame = self
    local ag = frame:CreateAnimationGroup()    
    local anim = ag:CreateAnimation("Rotation")
    anim:SetDegrees(360)
    anim:SetDuration(duration)    
    ag:Play()
    ag:SetLooping("REPEAT")
    Stick that in the onLoad script (Not OnUpdate!) for the frame you want to turn around. Change duration to change the amount of time it takes it to rotate 360 degrees.

    If your panel is using a border, it'll look really strange, I don't know enough about how borders work in WoW to explain why, but it gets all sorts of separated and strange. So, if you want a border on the texture, it'll probably take more investigating, unless someone else can help you with that part :P

  10. #10
    Thanks so much! that did work and it rotates!

    Just one more quick question, if i want it to rotate clockwise, what would I do?

  11. #11
    Try changing SetDegrees to -360 rather than 360 and then reload your ui after saving the change.

  12. #12
    Excellent, thanks so much for the help

  13. #13
    You're very welcome. Can I ask what you were doing with it?

  14. #14
    With how large I have my minimap on my ui, the arrows and such are huge, and sexymap doesn't support shrinking the icons on the map, so I want to use kg to make the rotating runes and use the other minimap addon that does shrink the blips.

    Now if only i could zoom the map out further... (I used to use carbonite but have moved away from it, but i miss the large amount of map i could see)

Posting Permissions

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