Created
January 9, 2015 10:59
-
-
Save Choonster/eb07bbd750776d1254fc to your computer and use it in GitHub Desktop.
An example of OnUpdate throttling in WoW.
This file contains hidden or 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