---
title: "MapboxSpriteImage"
description: "帧动画图标层，雪碧图切帧后由 symbol 逐帧循环播放。"
seo_title: "MapboxSpriteImage Component"
seo_description: "Sprite-sheet frame animation icons sliced from one image and looped per frame on symbol features."
canonical_url: "https://mapbox.mhaibaraai.cn/docs/effects/sprite-image"
---
# MapboxSpriteImage

> 帧动画图标层，雪碧图切帧后由 symbol 逐帧循环播放。

## 简介

`MapboxSpriteImage` 把一张雪碧图（行优先排布的多帧）切帧后注册为帧驱动图标，symbol 图层逐帧循环播放，零解码依赖；`frames` / `columns` / `rows` / `frameWidth` / `frameHeight` / `fps` / `size` 控制切帧与播放。

## 用法

加载一张 18 帧雪碧图并循环播放：

```vue [SpriteImageExample.vue]
<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

```ts
/**
 * Props for the MapboxSpriteImage component
 */
interface MapboxSpriteImageProps {
  /**
   * 点要素数据（GeoJSON 或其 URL）
   */
  data: string | GeoJSON.GeoJSON<GeoJSON.Geometry, GeoJSON.GeoJsonProperties> | undefined;
  /**
   * 雪碧图 URL（所有帧拼一张图，行优先排布）
   */
  image: string;
  /**
   * 总帧数
   */
  frames: number;
  /**
   * 列数；省略时等于 frames（单行）
   */
  columns?: number | undefined;
  /**
   * 行数
   */
  rows?: number | undefined;
  /**
   * 单帧宽（像素）；省略由图宽/列数推算
   */
  frameWidth?: number | undefined;
  /**
   * 单帧高（像素）；省略由图高/行数推算
   */
  frameHeight?: number | undefined;
  /**
   * 播放帧率（帧/秒）
   * @default "12"
   */
  fps?: number | undefined;
  /**
   * 上图图标边长（像素）
   * @default "64"
   */
  size?: number | undefined;
  /**
   * 图层 id；省略时自动生成
   */
  layerId?: string | undefined;
  /**
   * 插入到该图层之前
   */
  beforeId?: string | undefined;
}
```

## Changelog

See commit history for [src/runtime/components/effects/SpriteImage.vue](https://github.com/mhaibaraai/movk-mapbox/commits/main/src/runtime/components/effects/SpriteImage.vue).


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
