-
Notifications
You must be signed in to change notification settings - Fork 3
anim‐en
JNightRide edited this page Dec 21, 2023
·
3 revisions
jMe3GL2 provides 3 control classes to manage animations:
- IndexAnimatedSprite
- AnimatedSprite
- RibbonBoxAnimationSprite
NOTE: Animations are always added as a control to the geometries, and their speed should always be limited so that the animations apply equally on any device.
If you have a texture and inside it there is an animation, this class is perfect in this situation since it cycles through that texture.
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);
It is similar to IndexAnimatedSprite
with the difference that the textures are independent.
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);
It is a combination between IndexAnimatedSprite
and AnimatedSprite
, with this type of animations we can join two animated textures into one (independently) and move through them with positions.
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);