View Single Post
07-21-19, 06:58 AM   #13
wildcard25
An Aku'mai Servant
 
wildcard25's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2012
Posts: 30
Originally Posted by Terenna View Post
Lua Code:
  1. local function OnUpdate(self, elapsed, x, y)
  2.     self.elapsed = self.elapsed + elapsed
  3.     while self.elapsed > 0.5 do --only update the coords 2/second
  4.         if mapID then
  5.             x, y = GetPlayerMapPosition(mapID, 'player')
  6.             if x then
  7.                 self.text:SetFormattedText('%.1f, %.1f', x * 100, y * 100)
  8.             else
  9.                 self.text:SetText('')
  10.             end
  11.         end
  12.  
  13.         self.elapsed = self.elapsed - 0.5
  14.     end
  15. end
I'd probably only update the co-ordinates once in the OnUpdate function, then wait for at least another half a second before doing it again. Currently this keeps recalculating the same thing until it gets the elapsed time under half a second. If the pc is already under enough load that more than 1 second has passed between frames, then this would just be adding to the work load.
Lua Code:
  1. local function OnUpdate(self, elapsed, x, y)
  2.     self.elapsed = (self.elapsed or 0) + elapsed
  3.     if self.elapsed > 0.5 then --only update the coords 2/second
  4.         if mapID then
  5.             x, y = GetPlayerMapPosition(mapID, 'player')
  6.             if x then
  7.                 self.text:SetFormattedText('%.1f, %.1f', x * 100, y * 100)
  8.             else
  9.                 self.text:SetText('')
  10.             end
  11.         end
  12.  
  13.         self.elapsed = 0
  14.     end
  15. end
  Reply With Quote