Replace element sprite texture atlas

Hi there,

What I am trying to do is dynamically load external spritesheets and replace current texture atlas.

Loading and replacing is only successfull on sprite components.

I am wondering why this won’t work on sprites assigned to an element component.

// initialize code called once per entity
ReplaceTextureAtlas.prototype.initialize = function () {
    this.entity.button.on("click", function () {
        // replace sprite atlas texture"Sprite").sprite._clips['Clip 1']._sprite._atlas._texture = LoadVisuals.awardWin.resources[0];

        // replace element sprite atlas texture"Element Sprite").element._image._sprite._atlas._texture = LoadVisuals.awardWin.resources[0];

        console.log("Element Sprite").element);
    }, this);

Here’s a test project to show what is (not) going on.

What am I missing?


Hmm, I wouldn’t do it at the component level but rather at the sprite asset level, let me take a look at the project

1 Like


1 Like

This is a more efficient way indeed!

I will have to implement it in the old LoadVisuals script in the original project as there are a lot of assets being loaded depending on the user.

Thanks @yaustar!