Skip to main content
Version: v1.0

IMG_ANIM

img_anim_sample

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

Create UI widget

const imgAnim = hmUI.createWidget(hmUI.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 hmUI.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

Supported properties hmUI.anim_status

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

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

Get animation status Return type boolean

ValueDescription
hmUI.prop.ANIM_IS_RUNINNGIs the animation running.
hmUI.prop.ANIM_IS_PAUSEWhether the animation is paused.
hmUI.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
Page({
build() {
const imgAnimation = hmUI.createWidget(hmUI.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(hmUI.prop.ANIM_STATUS, hmUI.anim_status.START)
imgAnimation.addEventListener(hmUI.event.CLICK_DOWN, () => {
const isRunning = imgAnimation.getProperty(hmUI.prop.ANIM_IS_RUNINNG)

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