core/animation
애니메이션 처리기.
Animation handler.
Animationextends Object
애니메이션 처리기.
Animation handler.
import { ImageAsset, Animation, Rect } from "./build/vanilla.js";
const imageAsset = new ImageAsset();
await imageAsset.load("examples/assets/spritesheet.png");
const image = imageAsset.getImage();
const rects = [];
for (let row = 0; row < 3; ++row) {
for (let column = 0; column < 3; ++column) {
rects.push(Rect.create(column * 200, row * 200, 200, 200));
}
}
const animation = new Animation();
animation.setFramesFromRects(image, rects);
animation.setAnimationSpeed(8);
animation.setLoop(false);
animation.setOnComplete(() => {
console.log("complete", animation.getCurrentFrameIndex());
});
animation.play();
animation.tick(0.5);
console.log(animation.getCurrentFrameIndex(), animation.getTotalFrameCount());
animation.tick(1.0);
console.log(animation.isPlaying());갱신.
Update.
- timeDeltanumber
- 지난 시간. (초, 재생 중이고 프레임이 있고 속도가 0 보다 클 때만 넘긴다)Elapsed time. (seconds, advances only while playing, with frames and a speed above 0)
짝Counterpart: vanilla-engine Animation.tick
일시정지. (지금 프레임과 쌓인 시간을 그대로 둔다)
Pause. (keeps the current frame and the accumulated time as they are)
짝Counterpart: vanilla-engine Animation.pause
재개. (멈춘 프레임에서 이어 간다)
Resume. (continues from the paused frame)
짝Counterpart: vanilla-engine Animation.resume
정지. (첫 프레임으로 되돌린다. 멈춰 있어도 되돌린다)
Stop. (returns to the first frame. Returns to it even when already stopped)
짝Counterpart: vanilla-engine Animation.stop
프레임 설정.
Sets the frames.
- framesFrame[]
- 프레임 목록. (배열이 아니면 무시한다, 넣으면 stop 처럼 첫 프레임으로 되돌리고 멈춘다)Frame list. (ignored if not an array, setting it rewinds to the first frame and stops like stop)
짝Counterpart: vanilla-engine Animation.set_frames
프레임 설정. (낱장의 스프라이트 이미지 목록)
Sets the frames. (a list of individual sprite images)
- imagesHTMLImageElement[]
- 낱장 이미지 목록. (이미지마다 전체 영역 프레임 하나, 비었거나 배열이 아니면 무시한다)List of single images. (one whole-image frame per image, ignored if empty or not an array)
짝Counterpart: vanilla-engine Animation.set_frames_from_images
프레임 설정. (스프라이트 시트)
Sets the frames. (sprite sheet)
- imageHTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap
- 스프라이트 시트 그림. (이미지, 캔버스, ImageBitmap 만 받고 그 밖의 값은 무시한다)Sprite sheet picture. (only images, canvases, OffscreenCanvas and ImageBitmap are accepted; other values are ignored)
- rectsRect[]
- 시트 안의 프레임 영역 목록. (픽셀, 비었거나 배열이 아니면 무시한다)List of frame regions in the sheet. (pixels, ignored if empty or not an array)
짝Counterpart: vanilla-engine Animation.set_frames_from_rects
초당 프레임 숫 설정.
- 예) 60으로 지정시 초당 이미지 60회 변경됨.
Sets the frames per second.
- e.g.) When set to 60, the image changes 60 times per second.
- animationSpeednumber
- 초당 프레임 수. (기본 10, 0 이하이면 넘기지 않는다)Frames per second. (default 10, does not advance if 0 or less)
짝Counterpart: vanilla-engine Animation.set_animation_speed
반복 여부 설정.
Sets whether to loop.
- valueboolean
- 반복하면 참. (기본 참, 거짓이면 마지막 프레임에서 멈추고 완료 콜백을 부른다)True to loop. (default true, if false it stops at the last frame and calls the complete callback)
짝Counterpart: vanilla-engine Animation.set_loop
애니메이션 완료 콜백 설정.
Sets the animation completion callback.
- callbackFunction
- 반복하지 않는 애니메이션이 마지막 프레임에 닿으면 부를 함수. (인자 없음, null 이면 부르지 않는다)Function called when a non-looping animation reaches the last frame. (no arguments, not called if null)
짝Counterpart: vanilla-engine Animation.set_on_complete
특정 프레임으로 이동하여 재생합니다.
Moves to a specific frame and plays.
- indexnumber
- 프레임 번호. (0 부터, 범위 밖이면 처음이나 끝으로 자른다)Frame index. (from 0, clamped to the first or last if out of range)
짝Counterpart: vanilla-engine Animation.goto_and_play
특정 프레임으로 이동하여 정지합니다.
Moves to a specific frame and stops.
- indexnumber
- 프레임 번호. (0 부터, 범위 밖이면 처음이나 끝으로 자른다)Frame index. (from 0, clamped to the first or last if out of range)
짝Counterpart: vanilla-engine Animation.goto_and_stop
재생 중인지 여부 반환.
Returns whether playing.
반환Returnsboolean 재생 중이면 참.True if playing.
짝Counterpart: vanilla-engine Animation.is_playing
현재 프레임 반환.
Returns the current frame.
반환ReturnsFrame 현재 프레임. (프레임이 없으면 null)Current frame. (null if there are no frames)
짝Counterpart: vanilla-engine Animation.get_current_frame
현재 이미지 반환.
Returns the current image.
반환ReturnsHTMLImageElement 현재 프레임의 이미지. (프레임이 없으면 null)Image of the current frame. (null if there are no frames)
짝Counterpart: vanilla-engine Animation.get_current_image
현재 영역 반환.
Returns the current region.
반환ReturnsRect | null 현재 프레임의 이미지 안 영역. (픽셀, 프레임이 없으면 null)Region inside the image of the current frame. (pixels, null if there are no frames)
짝Counterpart: vanilla-engine Animation.get_current_rect
현재 프레임 번호 반환.
Returns the current frame number.
반환Returnsnumber 현재 프레임 번호. (0 부터)Current frame index. (from 0)
짝Counterpart: vanilla-engine Animation.get_current_frame_index
모든 프레임 수 반환.
Returns the total number of frames.
반환Returnsnumber 프레임 수.Frame count.
짝Counterpart: vanilla-engine Animation.get_total_frame_count