目录

Class (PlayImageAnimation)

Modules to Import

import { map } from '@kit.MapKit';
import { image } from '@kit.ImageKit';

PlayImageAnimation

Frame animation for controlling multiple images. This API inherits from Animation.

It is mainly used to implement dynamic image rendering effects in map apps, including path tracking, event marking, and state transitions. By continuously playing a sequence of image frames, you can vividly present movement trajectories, animated icons, or state change processes, enhancing the user's visual feedback and interactive experience.

Frame animation is a technique that creates an animation effect by displaying a series of static images in rapid succession. Each image is called a frame. When these frames are played in a fast sequence, the user perceives smooth motion or changes.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 5.0.0(12).

System capability: SystemCapability.Map.Core

Since: 5.0.0(12)

Example:

let images: Array<ResourceStr | image.PixelMap> = [
   // The icons are stored in resources/rawfile.
   'test1.png',
   'test2.png',
   'test3.png',
   'test4.png'
];
let playImageAnimation: map.PlayImageAnimation = new map.PlayImageAnimation();
await playImageAnimation.addImages(images);

[h2]addImages

addImages(images: Array<ResourceStr | image.PixelMap>): Promise<void>

Adds image resources for an animation. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 5.0.0(12).

System capability: SystemCapability.Map.Core

Since: 5.0.0(12)

Parameters:

Name Type Mandatory Description
images Array<ResourceStr | image.PixelMap> Yes

Image resources for an animation.

Note:

- It is recommended that these images be of the same size.

- The number of images cannot exceed 200.

- The duration must be greater than 33 ms. Otherwise, it will be changed to 33 ms.

- If this parameter is of the string type, store images in resources/rawfile.

Returns:

Type Description
Promise<void> Promise that returns no value.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

ID Error Message
401 Invalid input parameter.

Example:

let images: Array<ResourceStr | image.PixelMap> = [
   // The icons are stored in resources/rawfile.
   'test1.png',
   'test2.png',
   'test3.png',
   'test4.png'
];
await playImageAnimation.addImages(images);