Announcement

Collapse
No announcement yet.

Loading online assets at runtime

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loading online assets at runtime

    Hello.

    Is there a way to load online assets at runtime?

    I'm making "game center" application where game assets would load only after player selected the game he wants to play.

    Is this accomplished with a normal C# async method?

    e.g. the link provided.

    And if this is all there is to it, how can I then use these imges in the scene?


    Thanks.

  • #2
    Hello there Mark

    You can load online assets at runtime. Here is an example.

    Code:
    Texture2D texture;
    
    var httpClient = new HttpClient();
    
    using(var stream = await httpClient.GetStreamAsync(IMAGE_URL).ConfigureWaveAwait(WaveTaskContinueOn.Background))
    {
        texture = Texture2D.FromFile(WaveServices.GraphicsDevice, stream);
    }
    
    await WaveForegroundTask.Run(()=>
    {
        // Set the material diffuse texture here
        material.Diffuse = texture;
    
        // You can also set a sprite texture
        sprite.Texture = texture;
    });
    You have to add System.Net.Http as a reference in your project.

    In case you need it, there's a sample that uses code very similar to this one. You can find it here: https://github.com/WaveEngine/Sample...nce/AsyncAwait

    I hope you find this helpful!

    Comment

    Working...
    X