MapboxSpriteImage
帧动画图标层,雪碧图切帧后由 symbol 逐帧循环播放。
简介
MapboxSpriteImage 把一张雪碧图(行优先排布的多帧)切帧后注册为帧驱动图标,symbol 图层逐帧循环播放,零解码依赖;frames / columns / rows / frameWidth / frameHeight / fps / size 控制切帧与播放。
用法
加载一张 18 帧雪碧图并循环播放:
<script setup lang="ts">
import type { FeatureCollection } from 'geojson'
const data: FeatureCollection = {
type: 'FeatureCollection',
features: [
{ type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [116.397, 39.908] } }
]
}
</script>
<template>
<div class="h-115 w-full overflow-hidden rounded-(--ui-radius) border border-default">
<MapboxMap
:options="{ style: 'mapbox://styles/mapbox/light-v11', center: [116.397, 39.908], zoom: 13 }"
>
<!-- Phaser 公开雪碧图:18 帧 37×45 单行 -->
<MapboxSpriteImage
:data="data"
image="https://labs.phaser.io/assets/sprites/metalslug_mummy37x45.png"
:frames="18"
:columns="18"
:frame-width="37"
:frame-height="45"
:fps="12"
:size="90"
/>
</MapboxMap>
</div>
</template>
API
Props
| Prop | Default | Type |
|---|---|---|
data | string | GeoJSON.Point | GeoJSON.MultiPoint | GeoJSON.LineString | GeoJSON.MultiLineString | GeoJSON.Polygon | GeoJSON.MultiPolygon | GeoJSON.GeometryCollection<GeoJSON.Geometry> | GeoJSON.Feature<GeoJSON.Geometry, { [name: string]: any; }> | GeoJSON.FeatureCollection<GeoJSON.Geometry, { [name: string]: any; }>点要素数据(GeoJSON 或其 URL) | |
image | string雪碧图 URL(所有帧拼一张图,行优先排布) | |
frames | number总帧数 | |
columns | number列数;省略时等于 frames(单行) | |
rows | 1 | number行数 |
frameWidth | number单帧宽(像素);省略由图宽/列数推算 | |
frameHeight | number单帧高(像素);省略由图高/行数推算 | |
fps | 12 | number播放帧率(帧/秒) |
size | 64 | number上图图标边长(像素) |
layerId | string图层 id;省略时自动生成 | |
beforeId | string插入到该图层之前 |
Changelog
No recent changes