Preload (Method): Difference between revisions
From Legacy Roblox Wiki
Jump to navigationJump to search
>LPGhatguy Rewording |
>Quenty No edit summary |
||
Line 7: | Line 7: | ||
{{clear floats}} | {{clear floats}} | ||
{{EmphasisBox|[[Image:RsClose_ds.png]] '''WARNING:''' This feature only effectively works in Local scripts.|red| }} | |||
{{Example|Can be used to load an asset (common assets loaded are images) so it doesn't take any time when shown as textures or decals. | {{Example|Can be used to load an asset (common assets loaded are images) so it doesn't take any time when shown as textures or decals. | ||
Line 12: | Line 15: | ||
Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=2453543") | Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=2453543") | ||
</pre>}} | </pre>}} | ||
{{Example|A fast way to load assets is to put them into a table, then loop through the table, and load them. | |||
<pre> | |||
Assets = {2253543,2434541,5133543,2423433,41143243,2453865,21433365,2154549} | |||
for i=1, #Assets do | |||
Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id="..Assets[i]) | |||
end | |||
</pre> | |||
The script will wait until the assets are loaded, then go on. Thus, you can make loading bars using GUIs by changing the scale of a GUI from 0 to 1. | |||
<pre> | |||
Assets = {2253543,2434541,5133543,2423433,41143243,2453865,21433365,2154549} | |||
NumOf = 0 | |||
for i=1, #Assets do | |||
Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id="..Assets[i]) | |||
NumOf = NumOf + 1 | |||
script.Parent.GUI.LoadingBar.Bar.Size = UDim2.new(NumOf/#Assets, 0, 1, 0) | |||
end | |||
</pre> | |||
This way, it ads NumOf each time it uploads a new thing, then calculates how the loading bar should look. The LoadingBar would be sized so it that it would look like the full bar, then the actual 'Bar' would move along with the amount that was done. | |||
}} | |||
[[Category:Methods]] | [[Category:Methods]] |
Revision as of 22:31, 11 July 2011
Preload( string asset ) | |
Returns | nil |
Description: | Downloads the requested asset to the client and prepares it for use. |
Member of: | ContentProvider |
Example
Can be used to load an asset (common assets loaded are images) so it doesn't take any time when shown as textures or decals.
Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=2453543")
Example
A fast way to load assets is to put them into a table, then loop through the table, and load them.
Assets = {2253543,2434541,5133543,2423433,41143243,2453865,21433365,2154549} for i=1, #Assets do Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id="..Assets[i]) end
The script will wait until the assets are loaded, then go on. Thus, you can make loading bars using GUIs by changing the scale of a GUI from 0 to 1.
Assets = {2253543,2434541,5133543,2423433,41143243,2453865,21433365,2154549} NumOf = 0 for i=1, #Assets do Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id="..Assets[i]) NumOf = NumOf + 1 script.Parent.GUI.LoadingBar.Bar.Size = UDim2.new(NumOf/#Assets, 0, 1, 0) end
This way, it ads NumOf each time it uploads a new thing, then calculates how the loading bar should look. The LoadingBar would be sized so it that it would look like the full bar, then the actual 'Bar' would move along with the amount that was done.