Skip to main content
Version: v3

IMG_ANIM

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

img_anim_sample

Play the pre-given image at the set frame rate to create an animation effect.

Create UI widget

import { createWidget, widget } from '@zos/ui'

const imgAnim = createWidget(widget.IMG_ANIM, Param)

Type

Param: object

PropertiesDescriptionRequiredType
xThe x-coordinate of animation.YESnumber
yThe y-coordinate of animation.YESnumber
anim_pathThe path to the image for animation.YESstring
anim_prefixThe name to the image for animation.YESstring
anim_extImage extensions.YESstring
anim_fpsNumber of frames of animation.YESnumber
repeat_countNumber of animation repetitions, can be set 0: infinite repetition, 1: single repetition.YESnumber
anim_repeatWhether to repeat the playback; this value is true if repeat_count is 0.Noboolean
anim_sizeThe number of images.YESnumber
anim_statusThe status of animation; Reference anim_statusYESnumber
anim_complete_callThis function is callback when the animation is executed successfully. repeat_count is invalid if 0. Parameters anim is an instance to create the animation.NOfunction
stepFrame animation step size, more than '1' will jump frameNOnumber

Supported properties anim_status

Please pay attention to the animation order of the current settings when setting animation properties, the widget has been protected internally.

ValueDescription
anim_status.STARTStart animation; only pause stop is allowed to be called after starting the animation.
anim_status.PAUSEPause animation; can only be called after starting the animation and resuming it.
anim_status.RESUMEResume animation; can only be called after pausing the animation.
anim_status.STOPStop animation; can only be called after starting the animation and resuming it.

Get animation status Return type boolean

ValueDescription
prop.ANIM_IS_RUNINNGIs the animation running.
prop.ANIM_IS_PAUSEWhether the animation is paused.
prop.ANIM_IS_STOPWhether the animation is stopped.

Code example

tip

Please refer to Design Resources for the image resources in the code example

// Resource Storage Directory
.
└── assets
└── gtr-3
└── anim // anim_path
├── animation_0.png
├── animation_1.png
├── animation_2.png
├── animation_3.png
├── animation_4.png
└── animation_5.png
import { createWidget, widget, prop, anim_status } from '@zos/ui'

Page({
build() {
const imgAnimation = createWidget(widget.IMG_ANIM, {
anim_path: 'anim',
anim_prefix: 'animation',
anim_ext: 'png',
anim_fps: 60,
anim_size: 36,
repeat_count: 1,
anim_status: 3,
x: 208,
y: 230,
anim_complete_call: () => {
console.log('animation complete')
}
})

imgAnimation.setProperty(prop.ANIM_STATUS, anim_status.START)
imgAnimation.addEventListener(event.CLICK_DOWN, () => {
const isRunning = imgAnimation.getProperty(prop.ANIM_IS_RUNINNG)

if (!isRunning) {
imgAnimation.setProperty(prop.ANIM_STATUS, anim_status.START)
}
})
}
})