-
Notifications
You must be signed in to change notification settings - Fork 9
Damage Texture Component
The DamageTextureComponent is a custom component used to add varying textures to an entity - which will vary based on their health (from CombatStatsComponent). It is required that the entity also implements a CombatStatsComponent for this to work. When created, a single texture is added - this is the base texture and has a threshold of MAX_INT. For all additional textures the health threshold at which they display must be passed in the function.
The DamageTextureComponent
is created by first passing the path of the base texture - this path must be loaded by the ServiceLocator.getResourceService()
. Alternatively, a Texture
object can be passed directly to the constructor.
DamageTextureComponent dtc = new DamageTextureComponent("[BASE TEXTURE PATH].[EXT]");
or
Texture baseTexture = new Texture(...);
DamageTextureComponent dtc = new DamageTextureComponent(baseTexture);
Additional textures can be added to the component by calling addTexture()
. An integer threshold must be passed and either a texture path or texture object - exactly the same as the constructor. The integer threshold will determine when the texture will be shown, i.e. if the threshold is 30 then the texture specified will be shown whenever the entity has health <= 30. Note that when multiple textures have been added then the texture will the lowest threshold will be shown. i.e. if there are two additional thresholds of 30 and 20 and the health is 15, then the texture with the threshold of 20 will be displayed.
dtc.addTexture(THRESHOLD, [TEXTURE PATH OR TEXTURE OBJECT]);
The addTexture()
method has been implemented using the builder design pattern and thus can be chained together with the constructor or multiple addTexture()
calls. See the example below for an alternate way to initialise and add multiple textures to the DamageTextureComponent
.
DamageTextureComponent dtc = new DamageTextureComponent("baseTexture.png")
.addTexture(50, "HalfHealthTexture.png")
.addTexture(0, "BrokenTexture.png");
This component then just needs to be added to any entity, as you would any other component.
Entity newEntity = new Entity().addComponent(dtc);
This component has unspecified functionality in the following situations and thus should be avoided:
- Another component is specifiying the texture or animation of the entity
- Multiple calls to
addTexture()
are made with the same threshold - no guarantee of what texture will show
Escape Earth Game
Interaction Controller and Interactable Components
Game and Entity Configuration Files
Loading Game Configuration Files