-
-
Save IgorYunusov/f3c94aa0d59277f9fd8e33d9009b0361 to your computer and use it in GitHub Desktop.
An example of OnUpdate throttling in WoW.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local frame = CreateFrame("Frame") | |
-- The minimum number of seconds between each update | |
local ONUPDATE_INTERVAL = 0.1 | |
-- The number of seconds since the last update | |
local TimeSinceLastUpdate = 0 | |
frame:SetScript("OnUpdate", function(self, elapsed) | |
TimeSinceLastUpdate = TimeSinceLastUpdate + elapsed | |
if TimeSinceLastUpdate >= ONUPDATE_INTERVAL then | |
TimeSinceLastUpdate = 0 | |
-- Do stuff | |
end | |
end) | |
-- When the frame is shown, reset the update timer | |
frame:SetScript("OnShow", function(self) | |
TimeSinceLastUpdate = 0 | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment