-
Notifications
You must be signed in to change notification settings - Fork 9
Atlas Render Component
First see Components, Loading Resources.
The AtlasRenderComponent
is a custom render component used to selectively render a texture from an atlas. The texture being rendered can be changed via the setRegion
method.
The AtlasRenderComponent
can be created in two ways. The first way takes a String path to the atlas file and the initial region. In order for this constructor to work, the atlas found at the given path must have already been loaded by the ResourceService
found at ServiceLocator.getResourceService()
.
public AtlasRenderComponent(String atlasPath, String region)
The second takes a TextureAtlas and the initial region.
public AtlasRenderComponent(TextureAtlas atlas, String region)
Before using the AtlasRenderComponent
you must first include it in your file.
import com.csse3200.game.rendering.AtlasRenderComponent;
The AtlasRenderComponent
can then be added to an entity as follows.
Entity entity = new Entity();
entity.addComponent(new AtlasRenderComponent("images/test.atlas", "region1"));
You can also scale the entity to have the correct width to height ratio. A scaled entity will be 1f
in width and the height will be the correct ratio.
entity.getComponent(AtlasRenderComponent.Class).scaleEntity();
Change the region being rendered by using setRegion
.
entity.getComponent(AtlasRenderComponent.Class).setRegion("region2");
or if you want the entity to be rescaled to match the new region call
entity.getComponent(AtlasRenderComponent.Class).setRegion("region2", true);
Testing for the AtlasRenderComponent
was implemented using JUnit and Mockito. The tests ensure that the correct region is drawn on the screen with the correct position. There are also tests to ensure changing between regions functions as expected and that the scaling of the entity functions as expected.
Escape Earth Game
Interaction Controller and Interactable Components
Game and Entity Configuration Files
Loading Game Configuration Files