How do I add a container to a follower?

Hi!

The title of the thread is very straight forward about what I am trying to achieve. I have a sprite which is added to a follower but now I need to attach more elements to it (in this case a text). I know that the way to go is to use a container but I am not managing to figure how to join container, sprite and follower together. This is what I tried:

var enemy = "enemy";
this[enemy] = this.add.follower(aPaths[path], 0, 0, enemy+'Right').startFollow({
            duration: 20000,
            loop: 0
        });

this["t_"+enemy] = this.add.bitmapText(0, 0, 'komikax_18', "Enemy name", 18);

this[enemy].add(this["t_"+enemy]);

However the very last line returned me the error this[enemy].add is not a function.

I also tried:

this[enemy] = this.add.follower(aPaths[path], 0, 0, enemy+'Right').startFollow({
            duration: 20000,
            loop: 0
        }).add.container(0,0);

and tried too:

this[enemy] = this.add.container(0,0).add.follower(aPaths[path], 0, 0, enemy+'Right').startFollow({
            duration: 20000,
            loop: 0
        });

But both returned me errors as well.

Any clue?

Thanks!

Interesting assumption. Except a PathFollower extends a Sprite, so this just won’t work. Nice feature request though :slight_smile:
You could render the container to the follower Sprite of course…

Hey Milton, so are you saying that containers can NOT be attached to a follower?

PS: I ended resolving my issue the other way but yeah, it would be a great feature… being a game coder coming from Actionscript where you can have containers (movieclips) and put whatever you want within it I would find it a fantastic advantage.

:slight_smile:

Obviously you can’t attach a container to a Sprite, But a Sprite just holds a Texture. So if you render the Container to a RenderTexture, and then use that as the Sprite Texture, you’re basically faking it :slight_smile: Graphics only though, no other container features (input etc).

1 Like

Thanks for the clearification Milton!