Skip to content
本页导读

Sprite

组件类型:UxSpriteComponentPublicInstance

平台兼容性

UniApp X

AndroidiOSweb鸿蒙 Next小程序
x

UniApp Vue Nvue

AndroidiOSweb鸿蒙 Next小程序
xxxx

Props

属性名类型默认值说明
framesArray精灵图集
durationNumber100每帧周期
playBooleanfalse是否播放
loopBooleanfalse循环播放
autoplayBooleanfalse自动播放

Events

事件名说明参数
start开始时触发
end结束时触发

示例代码

html
<template>
	<ux-page :stack="showDoc">
		<ux-navbar :title="title" :border="false">
			<template v-slot:right>
				<!-- #ifndef MP -->
				<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
				<!-- #endif -->
			</template>
		</ux-navbar>
		
		<ux-scroll>
			<ux-card direction="column" icon="flag-filled" title="png序列帧动画" :bold="true">
				<ux-text text="支持播放本地png序列帧动画"></ux-text>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="循环播放" :bold="true">
				<view class="w-100 h-100">
					<ux-sprite ref="uxSpriteRef1" :autoplay="true" :loop="true" :frames="anims"></ux-sprite>
				</view>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="播放一次" :bold="true">
				<view class="w-100 h-100">
					<ux-sprite ref="uxSpriteRef2" class="w-100 h-100" :play="play" :frames="anims" @start="start" @end="end"></ux-sprite>
				</view>
				
				<ux-button text="放技能" @click="onPlay()"></ux-button>
			</ux-card>
			
			<ux-placeholder :height="200">
				<ux-row justify="center" align="center" style="height: 100%;">
					<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
				</ux-row>
			</ux-placeholder>
		</ux-scroll>
	</ux-page>
</template>
<template>
	<ux-page :stack="showDoc">
		<ux-navbar :title="title" :border="false">
			<template v-slot:right>
				<!-- #ifndef MP -->
				<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
				<!-- #endif -->
			</template>
		</ux-navbar>
		
		<ux-scroll>
			<ux-card direction="column" icon="flag-filled" title="png序列帧动画" :bold="true">
				<ux-text text="支持播放本地png序列帧动画"></ux-text>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="循环播放" :bold="true">
				<view class="w-100 h-100">
					<ux-sprite ref="uxSpriteRef1" :autoplay="true" :loop="true" :frames="anims"></ux-sprite>
				</view>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="播放一次" :bold="true">
				<view class="w-100 h-100">
					<ux-sprite ref="uxSpriteRef2" class="w-100 h-100" :play="play" :frames="anims" @start="start" @end="end"></ux-sprite>
				</view>
				
				<ux-button text="放技能" @click="onPlay()"></ux-button>
			</ux-card>
			
			<ux-placeholder :height="200">
				<ux-row justify="center" align="center" style="height: 100%;">
					<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
				</ux-row>
			</ux-placeholder>
		</ux-scroll>
	</ux-page>
</template>
ts
<script setup>
	import * as plus from '@/uni_modules/ux-plus'
	
	const uxSpriteRef1 = ref<UxSpriteElement | null>(null)
	const uxSpriteRef2 = ref<UxSpriteElement | null>(null)
	
	const title = ref('')
	
	// #ifdef MP
	const anims = ref<string[]>([
		'https://www.uxframe.cn/source/assets/x1.png',
		'https://www.uxframe.cn/source/assets/x2.png', 
		'https://www.uxframe.cn/source/assets/x3.png', 
		'https://www.uxframe.cn/source/assets/x4.png', 
		'https://www.uxframe.cn/source/assets/x5.png', 
		'https://www.uxframe.cn/source/assets/x6.png', 
		'https://www.uxframe.cn/source/assets/x7.png', 
		'https://www.uxframe.cn/source/assets/x8.png', 
		'https://www.uxframe.cn/source/assets/x9.png',
		'https://www.uxframe.cn/source/assets/x10.png',
		'https://www.uxframe.cn/source/assets/x11.png',
		'https://www.uxframe.cn/source/assets/x12.png'
	] as string[])
	// #endif
	
	// #ifndef MP
	const anims = ref<string[]>([
		'/static/x1.png',
		'/static/x2.png', 
		'/static/x3.png', 
		'/static/x4.png', 
		'/static/x5.png', 
		'/static/x6.png', 
		'/static/x7.png', 
		'/static/x8.png', 
		'/static/x9.png',
		'/static/x10.png',
		'/static/x11.png',
		'/static/x12.png'
	] as string[])
	// #endif
	
	const play = ref(false)
	
	function start() {
		
	}
	
	function end() {
		play.value = false
	}
	
	function onPlay() {
		play.value = true
	}
	
	const showDoc = ref(false)
	
	function onDoc() {
		plus.openWeb({
			title: '在线文档',
			url: 'https://www.uxframe.cn/component/sprite.html',
			// blur: 1,
			success: () => {
				showDoc.value = true
			},
			complete: () => {
				showDoc.value = false
			}
		})
	}
	
	onLoad((e) => {
		title.value = e['title'] ?? ''
		
		// #ifdef APP-IOS
		setTimeout(function() {
			uxSpriteRef1.value?.setDatas(anims.value)
			uxSpriteRef2.value?.setDatas(anims.value)
		}, 100);
		// #endif
	})
</script>
<script setup>
	import * as plus from '@/uni_modules/ux-plus'
	
	const uxSpriteRef1 = ref<UxSpriteElement | null>(null)
	const uxSpriteRef2 = ref<UxSpriteElement | null>(null)
	
	const title = ref('')
	
	// #ifdef MP
	const anims = ref<string[]>([
		'https://www.uxframe.cn/source/assets/x1.png',
		'https://www.uxframe.cn/source/assets/x2.png', 
		'https://www.uxframe.cn/source/assets/x3.png', 
		'https://www.uxframe.cn/source/assets/x4.png', 
		'https://www.uxframe.cn/source/assets/x5.png', 
		'https://www.uxframe.cn/source/assets/x6.png', 
		'https://www.uxframe.cn/source/assets/x7.png', 
		'https://www.uxframe.cn/source/assets/x8.png', 
		'https://www.uxframe.cn/source/assets/x9.png',
		'https://www.uxframe.cn/source/assets/x10.png',
		'https://www.uxframe.cn/source/assets/x11.png',
		'https://www.uxframe.cn/source/assets/x12.png'
	] as string[])
	// #endif
	
	// #ifndef MP
	const anims = ref<string[]>([
		'/static/x1.png',
		'/static/x2.png', 
		'/static/x3.png', 
		'/static/x4.png', 
		'/static/x5.png', 
		'/static/x6.png', 
		'/static/x7.png', 
		'/static/x8.png', 
		'/static/x9.png',
		'/static/x10.png',
		'/static/x11.png',
		'/static/x12.png'
	] as string[])
	// #endif
	
	const play = ref(false)
	
	function start() {
		
	}
	
	function end() {
		play.value = false
	}
	
	function onPlay() {
		play.value = true
	}
	
	const showDoc = ref(false)
	
	function onDoc() {
		plus.openWeb({
			title: '在线文档',
			url: 'https://www.uxframe.cn/component/sprite.html',
			// blur: 1,
			success: () => {
				showDoc.value = true
			},
			complete: () => {
				showDoc.value = false
			}
		})
	}
	
	onLoad((e) => {
		title.value = e['title'] ?? ''
		
		// #ifdef APP-IOS
		setTimeout(function() {
			uxSpriteRef1.value?.setDatas(anims.value)
			uxSpriteRef2.value?.setDatas(anims.value)
		}, 100);
		// #endif
	})
</script>
css
<style lang="scss">
	
</style>
<style lang="scss">
	
</style>