My problem now is I don't know how do I integrate Sprite class as Component.
Simple, write it like this:
public class SpriteComponent implements Component {
public Sprite sprite;
}
**Note: implement Poolable as well if you are working with PooledComponents.
In below example, If I use it like this the PositionComponent will be thrown away? because sprite has x and y fields.
There's nothing wrong with having a SpriteComponent and a PositionComponent.
The x and y fields in the sprite are used to know where to position the sprite. Whereas, the x and y fields in your PositionComponent are used to identify the position of your entity.
If you have an entity that can have a position but no sprite then this setup seems logical.
Also I want to use the method of Sprite setOriginCenter(), in that case do I still need to create another component which is OriginComponent? or completely leave it to SpriteComponent?
No. I would not create this component as this data is held in the Sprite already. You can just access it from SpriteComponent.
my problem is I am using TextureComponent too, do I need to completely use SpriteComponent over TextureComponent? or I could use it both?
Depends what you need. If your entities can have either a texture or a sprite then yes, you may use both. However, if all entities that have sprites also have texures you may want to ask yourself what you are doing with both and if both are really needed.
Remember, Components are just 'data bags' for entities. So just think like: Am I ever going to have an entity in my game that can have this particular data? If so, will this entity already have this data within another component?
If you answered YES and then NO, then you should probably create a Component for it.
If you answered YES and then YES, then ask yourself: Do you really require both?
If you answered a third YES, then you should probably create a Component for it.
Cheers ;)