Animation
Contents
[
Hide
]
This article demonstrates how to create simple animations and manage their sequence using Aspose.Slides for .NET.
Add an Animation
Create a rectangle shape and apply a fade effect triggered on click.
static void AddAnimation()
{
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 100, 100);
// Fade effect.
slide.Timeline.MainSequence.AddEffect(shape, EffectType.Fade, EffectSubtype.None, EffectTriggerType.OnClick);
}
Access an Animation
Retrieve the first animation effect from the slide timeline.
static void AccessAnimation()
{
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 100, 100);
slide.Timeline.MainSequence.AddEffect(shape, EffectType.Fade, EffectSubtype.None, EffectTriggerType.OnClick);
// Access the first animation effect.
var effect = slide.Timeline.MainSequence[0];
}
Remove an Animation
Remove an animation effect from the sequence.
static void RemoveAnimation()
{
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 100, 100);
var effect = slide.Timeline.MainSequence.AddEffect(shape, EffectType.Fade, EffectSubtype.None, EffectTriggerType.OnClick);
// Remove the effect.
slide.Timeline.MainSequence.Remove(effect);
}
Sequence Animations
Add multiple effects and demonstrate the order in which animations occur.
static void SequenceAnimations()
{
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape1 = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 100, 100);
var shape2 = slide.Shapes.AddAutoShape(ShapeType.Ellipse, 200, 50, 100, 100);
var sequence = slide.Timeline.MainSequence;
sequence.AddEffect(shape1, EffectType.Fly, EffectSubtype.Bottom, EffectTriggerType.OnClick);
sequence.AddEffect(shape2, EffectType.Fly, EffectSubtype.Bottom, EffectTriggerType.OnClick);
}