Show images faster

Multi tool use
Multi tool use


Show images faster



I want to show a list of achievements each one with a different image. I've downloaded the images from the server but they appear very slow in my game. Is it a way to show them faster? Thank you in advance.



This is my code:


public GameObject filePrefab;
public GameObject contentRef;

private Texture2D downloadedImages;

public void AchievementsList_Bttn()
{
new GameSparks.Api.Requests.LogEventRequest ()
.SetEventKey ("LISTACHIEVEMENTS")
.Send ((response) => {

if(!response.HasErrors)
{
Debug.Log("List Achivements Loaded Sucessfully...");
GSData scriptData = response.ScriptData;
List<GSData> achievements = scriptData.GetGSDataList("achievements"); //retrieve the array of objects
for (int i = 0; i < achievements.Count; i++)
{
string name = achievements[i].GetString("name");
string description = achievements[i].GetString("description");
int? currency1Award = achievements[i].GetInt("currency1Award");
bool? earned = achievements[i].GetBoolean("earned");

GameObject tempFile = Instantiate (filePrefab, contentRef.transform);
Text tempName = tempFile.transform.GetChild(0).GetComponent<Text>();
Text tempDescription = tempFile.transform.GetChild(1).GetComponent<Text>();
Text tempCurrency1Award = tempFile.transform.GetChild(2).GetComponent<Text>();
RawImage tempImage = tempFile.transform.GetChild(3).GetComponent<RawImage>();

tempName.text = name;
tempDescription.text = description;
tempCurrency1Award.text = currency1Award.ToString();

DownloadtheFiles(name, tempImage);
}
}
});
}

public void DownloadtheFiles(string name, RawImage tempImage)
{
new GetDownloadableRequest()
.SetShortCode(name+"_icon")
.Send((response) => {
if(!response.HasErrors)
{
StartCoroutine(DownloadImages((response.Url), tempImage));
}
});
}

public IEnumerator DownloadImages(string downloadUrl, RawImage tempImage)
{
var www = new WWW(downloadUrl);
yield return www;
downloadedImages = new Texture2D(200, 200);
www.LoadImageIntoTexture(downloadedImages);
tempImage.texture = downloadedImages as Texture;
}



And this is what I want to show:



enter image description here





Responding to your "Is any way to do this without download the images from server?" comment below: Why do you download images form the server? It seems to me that you could keep images within your game and then just add the correct text to them?
– john
Jun 30 at 9:01






What do you mean by "appear very slow in my game"? It would be best to measure it an tell us the time in seconds. Also, what's the size of the images?
– Programmer
Jun 30 at 9:17




1 Answer
1



string name = achievements[i].GetString("name");



makes a dictionary lookup in the loop. Get the ordinals of the fields outside the loop, pu them into a variable and then use GetString(variable) (with the variable being integer type) - faster lookips.



Likely DownloadTheFiles is the bottleneck (do NOT make us do your basic work) and there is no way around this outside of hiding it (i.e. preloading or something else). It is, without you doing the base work and actually doing some debugging and profiling, the only thing that stands out because it does need to really do a network round drop for every image.





Is any way to do this without download the images from server?
– Angelsm
Jun 30 at 8:57





You tell me. This is your code and your architecture. Predownload and keep in memory.
– TomTom
Jun 30 at 10:35





How can I do it?
– Angelsm
Jun 30 at 10:54





You tell me. This is your code and your architecture. I will not rearchitect your application on the fly for free. Ask questions - TECHNICAL questions, specific, not "helpless, do it for me" style.
– TomTom
Jun 30 at 11:05





@Angelsm Google "asset bundles"
– Draco18s
Jun 30 at 16:16






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

fTxP73w c i9tfz
loeaknh,BAyQdnq,Ud4

Popular posts from this blog

Delphi Android file open failure with API 26

.

Amasya