Animations
The DesignCombo Video Editor SDK provides a powerful animation system for creating dynamic and engaging video content.
Animation Basics
Animations allow you to change element properties over time, creating smooth transitions and dynamic effects.
Animation Structure
interface IAnimation {property: string; // Property to animatefrom: number; // Starting valueto: number; // Ending valuedurationInFrames: number; // Duration in framesease: EasingFunction; // Easing functionpreviewUrl?: string; // Preview image URLname?: string; // Animation nametype?: "basic" | "special"; // Animation typedetails?: any; // Additional details}
Animation Types
1. Position Animations
Animate element position and movement.
// Move element from left to rightdispatch(ADD_ANIMATION, {payload: {itemId: "text-item",animation: {property: "x",from: 0,to: 400,durationInFrames: 60,ease: "easeInOut"}}});// Move element in a pathdispatch(ADD_ANIMATION, {payload: {itemId: "image-item",animation: {property: "position",from: 0,to: 1,durationInFrames: 90,ease: "easeInOut"}}});
2. Scale Animations
Animate element size and scaling.
// Scale up elementdispatch(ADD_ANIMATION, {payload: {itemId: "text-item",animation: {property: "scaleX",from: 1,to: 2,durationInFrames: 45,ease: "easeOut"}}});// Scale both dimensionsdispatch(ADD_ANIMATION, {payload: {itemId: "image-item",animation: {property: "scale",from: 1,to: 1.5,durationInFrames: 60,ease: "easeInOut"}}});
3. Rotation Animations
Animate element rotation.
// Rotate elementdispatch(ADD_ANIMATION, {payload: {itemId: "shape-item",animation: {property: "rotation",from: 0,to: 360,durationInFrames: 90,ease: "linear"}}});// Rotate with bounce effectdispatch(ADD_ANIMATION, {payload: {itemId: "text-item",animation: {property: "rotation",from: 0,to: 720,durationInFrames: 60,ease: "bounce"}}});
4. Opacity Animations
Animate element transparency.
// Fade in elementdispatch(ADD_ANIMATION, {payload: {itemId: "text-item",animation: {property: "opacity",from: 0,to: 1,durationInFrames: 30,ease: "easeIn"}}});// Fade out elementdispatch(ADD_ANIMATION, {payload: {itemId: "image-item",animation: {property: "opacity",from: 1,to: 0,durationInFrames: 30,ease: "easeOut"}}});
5. Color Animations
Animate element colors.
// Change text colordispatch(ADD_ANIMATION, {payload: {itemId: "text-item",animation: {property: "color",from: 0,to: 1,durationInFrames: 60,ease: "easeInOut"}}});// Change background colordispatch(ADD_ANIMATION, {payload: {itemId: "shape-item",animation: {property: "fill",from: 0,to: 1,durationInFrames: 90,ease: "easeInOut"}}});easing: "easeInOut"}}});
Easing Functions
Easing functions control how animations accelerate and decelerate.
Built-in Easing Functions
// Linear - constant speedeasing: "linear"// Ease In - slow start, fast endeasing: "easeIn"// Ease Out - fast start, slow endeasing: "easeOut"// Ease In Out - slow start and end, fast middleeasing: "easeInOut"// Bounce - bouncy effecteasing: "bounce"// Elastic - elastic effecteasing: "elastic"// Back - overshoot effecteasing: "back"
Custom Easing Functions
// Custom cubic beziereasing: "cubic-bezier(0.25, 0.46, 0.45, 0.94)"// Custom functioneasing: (t) => t * t * (3 - 2 * t)
Animation Management
Adding Animations
// Add single animationdispatch(ADD_ANIMATION, {payload: {itemId: "item-id",animation: {property: "x",from: 0,to: 400,durationInFrames: 60,ease: "easeInOut"}}});// Add multiple animationsdispatch(ADD_ANIMATIONS, {payload: {itemId: "item-id",animations: [{property: "x",from: 0,to: 400,durationInFrames: 60,ease: "easeInOut"},{property: "opacity",from: 0,to: 1,durationInFrames: 30,ease: "easeIn"}]}});
Updating Animations
// Update animationdispatch("update:animation", {payload: {itemId: "item-id",animationId: "animation-id",updates: {duration: 3000,easing: "bounce"}}});// Update animation timingdispatch(EDIT_OBJECT, {payload: {id: "item-id",updates: {animations: [{property: "x",from: 0,to: 400,durationInFrames: 60,ease: "easeInOut"}]}}});
Removing Animations
// Remove single animationdispatch("remove:animation", {payload: {itemId: "item-id",animationId: "animation-id"}});// Remove all animations from itemdispatch("remove:animations", {payload: {itemId: "item-id"}});// Remove animations by typedispatch("remove:animations:by-type", {payload: {itemId: "item-id",type: "position"}});
Animation Presets
Common Animation Presets
// Fade in presetconst fadeInPreset = {type: "opacity",property: "opacity",startValue: 0,endValue: 1,duration: 1000,easing: "easeIn"};// Slide in from left presetconst slideInLeftPreset = {type: "position",property: "x",startValue: -400,endValue: 0,duration: 1500,easing: "easeOut"};// Scale up presetconst scaleUpPreset = {type: "scale",property: "scale",startValue: { x: 0, y: 0 },endValue: { x: 1, y: 1 },duration: 1000,easing: "easeOut"};// Apply presetdispatch(ADD_ANIMATION_PRESET, {payload: {itemId: "item-id",preset: "fadeIn"}});
Custom Presets
// Create custom presetconst customPreset = {name: "Bounce In",animations: [{property: "scale",from: 0,to: 1.2,durationInFrames: 18,ease: "easeOut"},{property: "scale",from: 1.2,to: 1,durationInFrames: 12,ease: "bounce"}]};// Register custom presettimeline.registerAnimationPreset("bounceIn", customPreset);// Use custom presetdispatch(ADD_ANIMATION_PRESET, {payload: {itemId: "item-id",preset: "bounceIn"}});
Animation Sequences
Creating Sequences
// Create animation sequenceconst sequence = [{property: "x",from: 0,to: 200,durationInFrames: 30,ease: "easeOut"},{property: "rotation",from: 0,to: 360,durationInFrames: 30,ease: "linear"},{property: "scale",from: 1,to: 2,durationInFrames: 30,ease: "easeInOut"}];// Apply sequencedispatch(ADD_ANIMATION_SEQUENCE, {payload: {itemId: "item-id",sequence: ["fadeIn", "slideInRight", "pulseAnimationLoop"]}});
Chaining Animations
// Chain animations automaticallydispatch("add:animation:chain", {payload: {itemId: "item-id",animations: [{type: "position",property: "x",startValue: 0,endValue: 200,duration: 1000},{type: "rotation",property: "rotation",startValue: 0,endValue: 360,duration: 1000}],chain: true // Automatically chain animations}});
Animation Performance
Optimization Techniques
// Enable animation optimizationtimeline.enableAnimationOptimization({useRequestAnimationFrame: true,throttleUpdates: true,updateInterval: 16 // 60fps});// Limit concurrent animationstimeline.setAnimationLimits({maxConcurrent: 10,maxPerItem: 5});// Enable animation cachingtimeline.enableAnimationCaching({enabled: true,cacheSize: 100});
Performance Monitoring
// Monitor animation performancetimeline.onAnimationFrame((frameTime) => {console.log("Animation frame time:", frameTime);if (frameTime > 16) {console.warn("Animation performance issue detected");}});// Get animation statisticsconst stats = timeline.getAnimationStats();console.log("Active animations:", stats.activeCount);console.log("Average frame time:", stats.averageFrameTime);
Animation Events
Animation Lifecycle Events
// Animation starttimeline.onAnimationStart((animation) => {console.log("Animation started:", animation.id);});// Animation updatetimeline.onAnimationUpdate((animation, progress) => {console.log("Animation progress:", progress);});// Animation completetimeline.onAnimationComplete((animation) => {console.log("Animation completed:", animation.id);});// Animation looptimeline.onAnimationLoop((animation) => {console.log("Animation looped:", animation.id);});
Next Steps
- Learn about Transitions
- Explore the API Reference
- Check out Examples for practical usage
- Understand Customization for advanced usage