How exactly do I use a Sprite in a SpriteComponent programatically?

I have looked up on the net and on this forum but I couldn’t find something clear.
I have a texture loaded in memory, then I want to attach a sprite to my entity. For now this works, but it feels like it is a long way to do something so basic:

var texProvider = new SpriteFromTexture();
spriteComponent = new SpriteComponent();
texProvider.Texture = TankAIGame.TankTexture;
spriteComponent.SpriteProvider = texProvider;
Entity.Add(spriteComponent);

Is this how it is supposed to be done ?

Thanks

Hi @MehdiSaffar,

Unless there is a specific reason why you need to create the entity entirely in code. I would suggest you look into Sprite Sheets and Prefabs. That way you can design a “Tank” entity in Game Studio and just instantiate tanks and set whatever properties you need i.e. position. Other than that I don’t think you are going to reduce the amount of code.

For future reference these sort of questions are best suited for the Q&A site.

Cheers,
dfkeenan