Skip to content

anim‐es

JNightRide edited this page Dec 21, 2023 · 8 revisions

Animaciones

jMe3GL2 proporciona 3 clases-control para gestionar animaciones:

  • IndexAnimatedSprite
  • AnimatedSprite
  • RibbonBoxAnimationSprite

NOTA: Siempre las animaciones van agregadas como control de las geometrías, y siempre hay que limitar su velocidad para que las animaciones se apliquen por igual en cualquier equipo.

IndexAnimatedSprite

Si se tiene un conjunto de sprite en una textura y dentro de ello está una animación, esta clase es perfecta en esta situación dado que recorre esa textura.

Ejemplo:

Geometry animIndexGeom = new Geometry("AnimIndex", new Sprite(1, 1, 20, 20, 0, 12));
animIndexGeom.setMaterial(MaterialUtilities.getUnshadedMaterialFromClassPath(assetManager, "Textures/monochrome_tilemap_transparent_packed.png"));
animIndecGeom.setQueueBucket(RenderQueue.Bucket.Transparent);

IndexAnimatedSprite indexAnimatedSprite = new IndexAnimatedSprite();
indexAnimatedSprite.addAnimation("idle", new Integer[] {
    240, 241, 242, 243, 244, 245, 246
});

animIndexGeom.addControl(indexAnimatedSprite);

indexAnimatedSprite.setSpeed(0.60F);
indexAnimatedSprite.playAnimation("idle", 0.1F);

rootNode.attachChild(animIndexGeom);

AnimatedSprite

Es similar a IndexAnimatedSprite con la diferencias que las texturas son independientes.

Ejemplo:

Geometry animGeom = new Geometry("Anim", new Sprite(0.5F, 0.5F));
animGeom.setMaterial(MaterialUtilities.getUnshadedMaterialFromClassPath(assetManager, "Textures/playerRed_walk1.png"));
animGeom.setQueueBucket(RenderQueue.Bucket.Transparent);

AnimatedSprite animatedSprite = new AnimatedSprite();
animatedSprite.addAnimation("walk", new Texture[] {
    TextureUtilities.getTextureFromClassPath(assetManager, "Textures/playerRed_walk1.png"),
    TextureUtilities.getTextureFromClassPath(assetManager, "Textures/playerRed_walk2.png"),
    TextureUtilities.getTextureFromClassPath(assetManager, "Textures/playerRed_walk3.png"),
    TextureUtilities.getTextureFromClassPath(assetManager, "Textures/playerRed_walk4.png"),
    TextureUtilities.getTextureFromClassPath(assetManager, "Textures/playerRed_walk5.png")
});

animGeom.addControl(animatedSprite);
animGeom.move(1,0,0);

animatedSprite.setSpeed(0.60F);
animatedSprite.setDynamic(true);
animatedSprite.setScaleType(ScaleType.GL2_HEIGHT);
animatedSprite.playAnimation("walk", 0.08F);

rootNode.attachChild(animGeom);

RibbonBoxAnimationSprite

Es una combinación entre IndexAnimatedSprite y AnimatedSprite, con este tipo de animaciones podemos unir dos texturas animadas en una sola (independientemete) y recorrerlas con posiciones.

Ejemplo:

Geometry boxGeom = new Geometry("AnimBox", new Sprite(1, 1, 7, 1, 0, 0));
boxGeom.setMaterial(MaterialUtilities.getUnshadedMaterialFromClassPath(assetManager, "Textures/000-01.png"));
boxGeom.setQueueBucket(RenderQueue.Bucket.Transparent);

RibbonBoxAnimationSprite ribbonBoxAnimationSprite = new RibbonBoxAnimationSprite();
ribbonBoxAnimationSprite.addAnimation("01", new RibbonBox[] {
    new RibbonBox(TextureUtilities.getTextureFromClassPath(assetManager, "Textures/000-01.png"), new int[] {0, 1, 2, 3, 4, 5, 6}, 7, 1),
    new RibbonBox(TextureUtilities.getTextureFromClassPath(assetManager, "Textures/000-02.png"), new int[] {0, 1, 2, 3, 4, 5, 6}, 7, 1)
});

boxGeom.addControl(ribbonBoxAnimationSprite);

ribbonBoxAnimationSprite.setSpeed(0.60F);
ribbonBoxAnimationSprite.playAnimation("01", 0.1F);

rootNode.attachChild(boxGeom);

Siguiente

Clone this wiki locally