use of com.talosvfx.talos.editor.addons.scene.logic.components.SpriteRendererComponent in project talos by rockbite.
the class SceneEditorWorkspace method createSpriteObject.
public GameObject createSpriteObject(FileHandle importedAsset, Vector2 sceneCords, GameObject parent) {
GameObject spriteObject = createObjectByTypeName("sprite", sceneCords, parent);
SpriteRendererComponent component = spriteObject.getComponent(SpriteRendererComponent.class);
component.path = AssetImporter.relative(importedAsset);
component.reloadTexture();
TextureRegion texture = component.texture;
float aspect = (float) texture.getRegionWidth() / texture.getRegionHeight();
TransformComponent transformComponent = spriteObject.getComponent(TransformComponent.class);
transformComponent.scale.x *= aspect;
return spriteObject;
}
use of com.talosvfx.talos.editor.addons.scene.logic.components.SpriteRendererComponent in project talos by rockbite.
the class SmartTransformGizmo method moveInLayerOrder.
protected void moveInLayerOrder(GameObject gameObject, int direction) {
// direction -1 for down, 1 for up
if (gameObject.hasComponent(SpriteRendererComponent.class)) {
SpriteRendererComponent component = gameObject.getComponent(SpriteRendererComponent.class);
String sortingLayer = component.sortingLayer;
Array<GameObject> list = SceneEditorAddon.get().workspace.getRootGO().getChildrenByComponent(SpriteRendererComponent.class, new Array<>());
for (int i = list.size - 1; i >= 0; i--) {
if (!list.get(i).getComponent(SpriteRendererComponent.class).sortingLayer.equals(sortingLayer)) {
list.removeIndex(i);
}
}
// find closest game object if any that is lower to my index, and swap with it
if (list.size > 1) {
GameObject closest = list.first();
if (list.first() == gameObject) {
closest = list.get(1);
}
int origDst = component.orderingInLayer - closest.getComponent(SpriteRendererComponent.class).orderingInLayer;
for (GameObject candidate : list) {
int dst = component.orderingInLayer - candidate.getComponent(SpriteRendererComponent.class).orderingInLayer;
boolean matchesDirection = false;
boolean matchesDirectionEquals = false;
if (direction == -1 && dst >= 0)
matchesDirectionEquals = true;
if (direction == 1 && dst <= 0)
matchesDirectionEquals = true;
if (direction == -1 && origDst > dst)
matchesDirection = true;
if (direction == 1 && origDst < dst)
matchesDirection = true;
if (matchesDirectionEquals && candidate != gameObject) {
if (matchesDirection) {
origDst = dst;
closest = candidate;
}
}
}
SpriteRendererComponent closestComponent = closest.getComponent(SpriteRendererComponent.class);
if (closestComponent.orderingInLayer > component.orderingInLayer && direction == -1) {
return;
}
if (closestComponent.orderingInLayer < component.orderingInLayer && direction == 1) {
return;
}
if (closestComponent.orderingInLayer == component.orderingInLayer) {
if (direction == -1) {
closestComponent.orderingInLayer++;
Notifications.fireEvent(Notifications.obtainEvent(ComponentUpdated.class).set(closestComponent, false));
} else if (direction == 1) {
component.orderingInLayer++;
Notifications.fireEvent(Notifications.obtainEvent(ComponentUpdated.class).set(component, false));
}
} else {
// swap
int tmp = component.orderingInLayer;
component.orderingInLayer = closestComponent.orderingInLayer;
closestComponent.orderingInLayer = tmp;
Notifications.fireEvent(Notifications.obtainEvent(ComponentUpdated.class).set(component, false));
Notifications.fireEvent(Notifications.obtainEvent(ComponentUpdated.class).set(closestComponent, false));
}
}
}
}
use of com.talosvfx.talos.editor.addons.scene.logic.components.SpriteRendererComponent in project talos by rockbite.
the class SpriteImporter method makeInstance.
@Override
public void makeInstance(FileHandle asset, GameObject parent) {
if (!AssetImporter.getMetadataHandleFor(asset).exists()) {
createMetadataFor(asset);
}
SpriteMetadata metadata = AssetImporter.readMetadataFor(asset, SpriteMetadata.class);
SceneEditorWorkspace workspace = SceneEditorAddon.get().workspace;
Vector2 sceneCords = workspace.getMouseCordsOnScene();
GameObject gameObject = workspace.createSpriteObject(asset, sceneCords, parent);
if (metadata.borderData != null) {
SpriteRendererComponent component = gameObject.getComponent(SpriteRendererComponent.class);
component.renderMode = SpriteRendererComponent.RenderMode.sliced;
} else {
if (gameObject.hasComponent(TransformComponent.class)) {
TransformComponent component = gameObject.getComponent(TransformComponent.class);
Texture texture = new Texture(asset);
component.scale.x = texture.getWidth() / metadata.pixelsPerUnit;
component.scale.y = texture.getHeight() / metadata.pixelsPerUnit;
}
}
}
Aggregations