Thread Tools Display Modes
Prev Previous Post   Next Post Next
12-30-23, 05:10 PM   #1
x2infinity
A Defias Bandit
Join Date: Apr 2013
Posts: 2
Texture position lags behind cursor

Hey,

I've been using the StarCursor addon but I noticed the texture lags behind the cursor when moving the mouse. I'd rather it fix to the cursor position. Here is the code for the addon:

Lua Code:
  1. local frame = CreateFrame("Frame", nil, UIParent);
  2. frame:SetFrameStrata("TOOLTIP");
  3. local texture = frame:CreateTexture();
  4. texture:SetTexture([[Interface\Cooldown\star4]]);
  5. --texture:SetVertexColor(1, 0, 0,.5);
  6. texture:SetBlendMode("ADD");
  7. texture:SetAlpha(0.4);
  8. local x = 0;
  9. local y = 0;
  10. local speed = 0;
  11.  
  12. local function OnUpdate(_, elapsed)
  13.   --Somehow speed or something else is getting to -nan, reset if so (temporary fix by raymar_of_brovaria)
  14.   if speed + 1 == speed then
  15.     speed = 0
  16.   end
  17.   if x + 1 == x then
  18.     x = 0
  19.   end
  20.   if y + 1 == y then
  21.     y = 0
  22.   end
  23.   --end of temp fix
  24. --local function OnUpdate(_, elapsed)
  25.   local dX = x;
  26.   local dY = y;
  27.   x, y = GetCursorPosition();
  28.   dX = x - dX;
  29.   dY = y - dY;
  30.   local weight = 2048 ^ -elapsed;
  31.   speed = math.min(weight * speed + (1 - weight) * math.sqrt(dX * dX + dY * dY) / elapsed, 1024);
  32.   local size = speed / 8 - 16;
  33.   if (size > 0) then
  34.     local scale = UIParent:GetEffectiveScale();
  35.     texture:SetHeight(size);
  36.     texture:SetWidth(size);
  37.     texture:SetPoint("CENTER", UIParent, "BOTTOMLEFT", (x + 0.5 * dX) / scale, (y + 0.5 * dY) / scale);
  38.     texture:Show();
  39.   else
  40.     texture:Hide();
  41.   end
  42. end
  43. frame:SetScript("OnUpdate", OnUpdate);

I've tried playing with SetPoint but haven't been able to figure it out.

EDIT: Ok so I've figured out the issue seems to be framerate, if I lock my frames the texture stays on the cursor as intended, if I uncap the framerate the texture will begin to lag behind the cursor. I'm going to assume this has something to do with how updating the position works and isn't something you can change via the addon? But I'll leave this up in case someone knows how this works.

Last edited by x2infinity : 12-30-23 at 06:42 PM.
  Reply With Quote
 

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Texture position lags behind cursor


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

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