# resource/animationclip (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/resource/animationclip/

애니메이션 클립.

## AnimationClip extends Object

애니메이션 클립.
- 프레임은 스프라이트 시트 안의 영역(Rect) 목록이다. (Animator 가 그 영역을 스프라이트의 setImageRect 로 건다)

예제: 아틀라스 JSON 으로 걷기 클립 만들기

```js
import { AnimationClip } from "./build/vanilla.js";

const atlasJson = {
	frames: {
		walk0: { frame: { x: 0, y: 0, w: 200, h: 200 } },
		walk1: { frame: { x: 200, y: 0, w: 200, h: 200 } },
		walk2: { frame: { x: 400, y: 0, w: 200, h: 200 } },
	},
};
const clip = AnimationClip.fromAtlas(atlasJson, ["walk0", "walk1", "walk2"], 12, true);
const firstRect = clip.getFrame(0);
console.log(clip.getFrameCount(), clip.getDuration(), clip.isLoop(), firstRect.width);
```

- `constructor()` (constructor, since 0.0.8): 생성.
- `static fromAtlas(atlasJson, frameIds, fps = 10, isLoop = true)` (static, since 0.3.0): 아틀라스 JSON 으로 클립 생성. (정적)
  - TexturePacker 형식({ frames: { 이름: { frame: {x,y,w,h} } } })과
    배열 형식([{x,y,w,h}, ...]) 둘 다 받는다.
  - frameIds 순서대로 프레임을 뽑아 duration = frameCount / fps 로 만든다.
  - `atlasJson` object: 아틀라스 JSON. (TexturePacker 형식 객체나 영역 배열, 영역은 x, y 와 w, h 나 width, height)
  - `frameIds` string[] | number[]: 뽑을 프레임 이름이나 번호의 차례. (아틀라스에 없는 것은 건너뛴다)
  - `fps` number: 초당 프레임 수. (기본 10, 0 이하이면 지속 시간 0)
  - `isLoop` boolean: 반복 재생 여부. (기본 참)
  - returns AnimationClip: 만든 클립. (프레임은 Rect 목록)
- `setFrames(frames)` (method, since 0.0.8): 프레임 목록 설정.
  - `frames` Rect[]: 프레임 영역 목록. (스프라이트 시트 안의 픽셀 영역, fromAtlas 도 Rect 목록을 넣는다)
- `setLoop(isLoop)` (method, since 0.0.8): 반복 재생 여부 설정.
  - `isLoop` boolean: 반복 재생하면 참.
- `setDuration(duration)` (method, since 0.0.8): 애니메이션 지속 시간 설정.
  - `duration` number: 지속 시간. (초)
- `isLoop()` (method, since 0.0.8): 반복 재생 여부 반환.
  - returns boolean: 반복 재생하면 참. (기본 거짓)
- `getFrame(index)` (method, since 0.0.8): 대상 인덱스에 대한 프레임 반환.
  - `index` number: 프레임 번호. (0 부터)
  - returns Rect: 그 번호의 프레임 영역. (범위 밖이면 undefined)
- `getFrames()` (method, since 0.0.8): 프레임 목록 반환.
  - returns Rect[]: 프레임 영역 목록.
- `getFrameCount()` (method, since 0.0.8): 전체 프레임 수 반환.
  - returns number: 프레임 수.
- `getDuration()` (method, since 0.0.8): 애니메이션 지속 시간 반환.
  - returns number: 지속 시간. (초, 기본 0)
