use of de.gurkenlabs.litiengine.graphics.animation.IAnimationController in project litiengine by gurkenlabs.
the class Environment method load.
/**
* Loads the specified entiy by performing the following steps:
* <ol>
* <li>add to physics engine</li>
* <li>register entity for update</li>
* <li>register animation controller for update</li>
* <li>register movement controller for update</li>
* <li>register AI controller for update</li>
* </ol>
*
* @param entity
*/
private void load(final IEntity entity) {
// 1. add to physics engine
this.loadPhysicsEntity(entity);
// 2. register for update or activate
this.loadUpdatableOrEmitterEntity(entity);
// 3. register animation controller for update
final IAnimationController animation = Game.getEntityControllerManager().getAnimationController(entity);
if (animation != null) {
Game.getLoop().attach(animation);
}
// 4. register movement controller for update
if (entity instanceof IMobileEntity) {
final IMovementController<? extends IMobileEntity> movementController = Game.getEntityControllerManager().getMovementController((IMobileEntity) entity);
if (movementController != null) {
Game.getLoop().attach(movementController);
}
}
// 5. register ai controller for update
final IEntityController<? extends IEntity> controller = Game.getEntityControllerManager().getAIController(entity);
if (controller != null) {
Game.getLoop().attach(controller);
}
if (entity instanceof LightSource || entity instanceof StaticShadow) {
this.updateColorLayers(entity);
}
}
use of de.gurkenlabs.litiengine.graphics.animation.IAnimationController in project litiengine by gurkenlabs.
the class Environment method unload.
/**
* Unload the specified entity by performing the following steps:
* <ol>
* <li>remove entities from physics engine</li>
* <li>unregister units from update</li>
* <li>unregister ai controller from update</li>
* <li>unregister animation controller from update</li>
* <li>unregister movement controller from update</li>
* </ol>
*
* @param entity
*/
private void unload(final IEntity entity) {
// 1. remove from physics engine
if (entity instanceof CollisionBox) {
final CollisionBox coll = (CollisionBox) entity;
if (coll.isObstacle()) {
Game.getPhysicsEngine().remove(coll.getBoundingBox());
} else {
Game.getPhysicsEngine().remove(coll);
}
} else if (entity instanceof ICollisionEntity) {
final ICollisionEntity coll = (ICollisionEntity) entity;
Game.getPhysicsEngine().remove(coll);
}
// 2. unregister from update
if (entity instanceof IUpdateable) {
Game.getLoop().detach((IUpdateable) entity);
}
// 3. unregister ai controller from update
final IEntityController<? extends IEntity> controller = Game.getEntityControllerManager().getAIController(entity);
if (controller != null) {
Game.getLoop().detach(controller);
}
// 4. unregister animation controller from update
final IAnimationController animation = Game.getEntityControllerManager().getAnimationController(entity);
if (animation != null) {
Game.getLoop().detach(animation);
}
// 5. unregister movement controller from update
if (entity instanceof IMobileEntity) {
final IMovementController<? extends IMobileEntity> movementController = Game.getEntityControllerManager().getMovementController((IMobileEntity) entity);
if (movementController != null) {
Game.getLoop().detach(movementController);
}
}
if (entity instanceof Emitter) {
Emitter em = (Emitter) entity;
em.deactivate();
}
}
use of de.gurkenlabs.litiengine.graphics.animation.IAnimationController in project litiengine by gurkenlabs.
the class Camera method getViewPortDimensionCenter.
@Override
public Point2D getViewPortDimensionCenter(final IEntity entity) {
final Point2D viewPortLocation = this.getViewPortLocation(entity);
final IAnimationController animationController = Game.getEntityControllerManager().getAnimationController(entity);
if (animationController == null || animationController.getCurrentAnimation() == null) {
return new Point2D.Double(viewPortLocation.getX() + entity.getWidth() * 0.5, viewPortLocation.getY() + entity.getHeight() * 0.5);
}
final Spritesheet spriteSheet = animationController.getCurrentAnimation().getSpritesheet();
return new Point2D.Double(viewPortLocation.getX() + spriteSheet.getSpriteWidth() * 0.5, viewPortLocation.getY() + spriteSheet.getSpriteHeight() * 0.5);
}
use of de.gurkenlabs.litiengine.graphics.animation.IAnimationController in project litiengine by gurkenlabs.
the class EntityControllerManager method disposeControllers.
public void disposeControllers(final IEntity entity) {
final IEntityController<? extends IEntity> aiController = this.getAIController(entity);
if (aiController != null) {
Game.getLoop().detach(aiController);
this.aiControllers.remove(entity);
}
if (entity instanceof IMobileEntity) {
final IMovementController<? extends IMobileEntity> controller = this.getMovementController((IMobileEntity) entity);
if (controller != null) {
Game.getLoop().detach(controller);
this.movementControllers.remove(entity);
}
}
final IAnimationController animationController = this.getAnimationController(entity);
if (animationController != null) {
animationController.dispose();
this.animationControllers.remove(entity);
}
}
use of de.gurkenlabs.litiengine.graphics.animation.IAnimationController in project litiengine by gurkenlabs.
the class RenderEngine method renderEntity.
@Override
public void renderEntity(final Graphics2D g, final IEntity entity) {
if (entity == null) {
return;
}
if (entity.getRenderType() == RenderType.NONE || !this.canRender(entity)) {
return;
}
final RenderEvent<IEntity> renderEvent = new RenderEvent<>(g, entity);
if (!this.entityRenderingConsumer.isEmpty()) {
for (final Consumer<RenderEvent<IEntity>> consumer : this.entityRenderingConsumer) {
consumer.accept(renderEvent);
}
}
final IAnimationController animationController = Game.getEntityControllerManager().getAnimationController(entity);
if (animationController != null) {
final BufferedImage img = animationController.getCurrentSprite();
if (img == null) {
return;
}
if (animationController instanceof IEntityAnimationController<?> && ((IEntityAnimationController<?>) animationController).isAutoScaling()) {
final double ratioX = entity.getWidth() / img.getWidth();
final double ratioY = entity.getHeight() / img.getHeight();
renderScaledImage(g, img, Game.getCamera().getViewPortLocation(entity.getLocation()), ratioX, ratioY);
} else {
float deltaX = (entity.getWidth() - img.getWidth()) / 2.0f;
float deltaY = (entity.getHeight() - img.getHeight()) / 2.0f;
renderImage(g, img, Game.getCamera().getViewPortLocation(entity.getX() + deltaX, entity.getY() + deltaY), animationController.getAffineTransform());
}
}
if (entity instanceof IRenderable) {
((IRenderable) entity).render(g);
}
if (!this.entityRenderedConsumer.isEmpty()) {
for (final Consumer<RenderEvent<IEntity>> consumer : this.entityRenderedConsumer) {
consumer.accept(renderEvent);
}
}
}
Aggregations