Communitygithub.com

phido0410/rive

在網頁上播放 Rive 互動式動畫 (.riv 檔案) — 整合 @rive-app/webgl2 / canvas 執行環境、React hooks (useRive、資料綁定 hooks)、狀態機、資料綁定 (檢視模型),以及 @remotion/rive 用於影片。當使用者提供 .riv 檔案或要求使用 Rive、互動式吉祥物/圖示、或狀態機驅動的動畫時使用。

rive 是什麼?

這個技能讓 AI 代理能夠在網頁專案中整合 Rive 互動式動畫 (.riv 檔案)。它涵蓋了多種 JavaScript 執行環境,包括用於 Vanilla JS 的 @rive-app/webgl2 和 @rive-app/canvas、用於 React 應用程式的 @rive-app/react-webgl2 或 @rive-app/react-canvas,以及用於 Remotion 影片專案的 @remotion/rive。技能文件解釋瞭如何使用資料綁定 API(檢視模型)來替代已棄用的狀態機輸入方法,從而驅動動畫屬性,如數字、字串、布林值、顏色、列舉和觸發器。對於 React,它提供專用的 hooks,如 useRive、useViewModel 和 useViewModelInstance,以簡化整合;對於 Remotion 影片,它強調使用時間軸動畫來確保在渲染期間同步播放。此技能適用於打造互動式吉祥物、圖示或狀態機驅動的動畫,支援最新版本的執行環境套件。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/phido0410/claude-video-skills/tree/HEAD/skills/rive

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

rive 是做什麼的?

檢查日期 2026-10:@rive-app/canvas 2.45、@rive-app/react-canvas 4.37、@remotion/rive 4.0。

.riv 檔案是在 Rive 編輯器 (rive.app) 中製作的。程式碼可以播放和控制它們,但無法創作它們。請向使用者索取檔案,或使用來自 Rive 市集的社群檔案。

套件

需求套件
Vanilla JS,建議使用@rive-app/webgl2
Vanilla JS,Canvas2D@rive-app/canvas(若無文字、佈局、腳本、音訊則使用 @rive-app/canvas-lite)
React@rive-app/react-webgl2 或 @rive-app/react-canvas
Remotion@remotion/rive

Vanilla JS

import { Rive } from '@rive-app/webgl2'

const r = new Rive({
  src: '/hero.riv',
  canvas: document.getElementById('canvas'),
  stateMachines: 'State Machine 1',  // 編輯器中的名稱
  autoplay: true,
  autoBind: true,                     // 綁定預設的檢視模型實例
  onLoad: () => r.resizeDrawingSurfaceToCanvas(),
})
window.addEventListener('resize', () => r.resizeDrawingSurfaceToCanvas())
// 稍後:r.cleanup()

資料綁定(目前驅動 .riv 的方式)

狀態機輸入 (r.stateMachineInputs(name)、.value、.fire()) 在執行階段類型中已棄用。僅在沒有檢視模型的舊檔案中使用它們。

const vmi = r.viewModelInstance          // 需要 autoBind: true
vmi.number('Progress').value = 0.75
vmi.string('Title').value = 'Hello'
vmi.boolean('Active').value = true
vmi.color('Accent').value = 0xFFFF5500    // ARGB
vmi.enum('Mood').value = 'Happy'
vmi.trigger('Jump').trigger()
vmi.number('Progress').on((e) => console.log(e.data))

React

import { useRive, useViewModel, useViewModelInstance,
  useViewModelInstanceNumber, useViewModelInstanceTrigger } from '@rive-app/react-canvas'

const { rive, RiveComponent } = useRive({ src: '/hero.riv', stateMachines: 'State Machine 1', autoplay: true })
const vm = useViewModel(rive)
const vmi = useViewModelInstance(vm, { useDefault: true, rive })
const { setValue: setProgress } = useViewModelInstanceNumber('Progress', vmi)
const { trigger: jump } = useViewModelInstanceTrigger('Jump', vmi)

return <RiveComponent style={{ width: 400, height: 400 }} onClick={jump} />

容器需要明確的大小;RiveComponent 會填滿其父容器。

用於影片

在 Remotion 中使用來自 @remotion/rive 的 <RemotionRiveCanvas src="..." /> — 它會與目前影格同步播放檔案(請查閱 remotion-docs 了解其 props)。等待點擊/滑入的互動式狀態機邏輯在渲染時不會執行;請設計一個包含時間軸動畫的 .riv 檔案以用於影片。

Individual skills in this repo

This repo contains 4 individual skills — each has its own dedicated page.

相關技能