I think I tracked it down to a bug in the math functions. Textures disappear when using this:
lua Code:
function RotateTexture(self, degrees)
local angle = math.rad(degrees)
local cos, sin = math.cos(angle), math.sin(angle)
self:SetTexCoord((sin - cos), -(cos + sin), -cos, -sin, sin, -cos, 0, 0)
end
Maybe some of the math functions are bugged.
Using 90° steps still works, so here is my workaround using an onFinshed script that rotates the texture 90° by hand and restart the animation. Works perfectly for me. But my rotateTexture function is using predefined values. Nothing that gets calculated.
Full solution
lua Code:
-- cfg
local db = {
[1] = {
frame = {
parent = UIParent,
width = 100,
height = 100,
scale = 1,
alpha = 0.5,
level = 0,
pos = { a1 = "CENTER", x = -120, y = -120, },
},
texture = {
file = "Interface\\AddOns\\rFramerotater\\media\\rectangle",
color = { r = 255/255, g = 255/255, b = 0/255, },
blendmode = "BLEND", --ADD or BLEND
},
anim = {
rotateframe = true, --rotateframe, if false rotates the texture only
duration = 10, --how long should the rotation need to finish 360°
direction = 0, --0 = counter-clockwise, 1 = clockwise
},
},
}
-- functions
local ULx, ULy, LLx, LLy, URx, URy, LRx, LRy = 0,0,0,1,1,0,1,1
local rotateTexture = function(self, degrees)
if degrees == 0 then
self:SetTexCoord(ULx, ULy, LLx, LLy, URx, URy, LRx, LRy) --0°
elseif degrees == 90 then
self:SetTexCoord(LLx, LLy, LRx, LRy, ULx, ULy, URx, URy) --90°
elseif degrees == 180 then
self:SetTexCoord(LRx, LRy, URx, URy, LLx, LLy, ULx, ULy) --180°
elseif degrees == 270 then
self:SetTexCoord(URx, URy, ULx, ULy, LRx, LRy, LLx, LLy) --270°
end
end
function init(id)
--config
local cfg = db[id]
--frame
local h = CreateFrame("Frame",nil,cfg.frame.parent)
h:SetHeight(cfg.frame.height)
h:SetWidth(cfg.frame.width)
h:SetPoint(cfg.frame.pos.a1,cfg.frame.pos.x,cfg.frame.pos.y)
h:SetScale(cfg.frame.scale)
h:SetAlpha(cfg.frame.alpha)
h:SetFrameLevel(cfg.frame.level)
--h.time = GetTime()
--texture
local t = h:CreateTexture(nil,"BACKGROUND")
t:SetAllPoints(h)
t:SetTexture(cfg.texture.file)
t:SetBlendMode(cfg.texture.blendmode)
t:SetVertexColor(cfg.texture.color.r,cfg.texture.color.g,cfg.texture.color.b)
h.t = t
--animation object
local o = t
if cfg.anim.rotateframe then
o = h --frame is object to animate
end
--animationgroup
local ag = o:CreateAnimationGroup()
ag.t = t --keep reference to texture
ag.direction = cfg.anim.direction
ag.count = 0
--animation
local a1 = ag:CreateAnimation("Rotation")
if cfg.anim.direction == 0 then
a1:SetDegrees(90)
else
a1:SetDegrees(-90)
end
a1:SetDuration(cfg.anim.duration/(360/90))
ag.a1 = a1
--onfinished
ag:SetScript("OnFinished", function(ag)
if ag.direction == 0 then
ag.count = ag.count-1
if ag.count < 0 then ag.count = 3 end
else
ag.count = ag.count+1
if ag.count > 3 then ag.count = 0 end
end
rotateTexture(ag.t,90*ag.count)
ag:Play()
end)
--play
ag:Play()
end
local a = CreateFrame("Frame")
a:RegisterEvent("PLAYER_LOGIN")
a:SetScript("OnEvent", function (self,event,...)
for i,v in ipairs(db) do
init(i)
end
end)