resource/animationclip
애니메이션 클립. (스프라이트 시트 프레임 영역 목록 + 반복 여부 + 길이)
- 원본 resource/animationclip.js 를 옮긴 것이다. Animator 의 AnimationState 가 이것을 든다.
- 원본 주석은 프레임 목록을 Frame[] 이라 하지만 from_atlas 가 넣는 것은 Rect 다. 러스트 판은 Rect 목록으로 정했다. (Frame 은 이미지를 꼭 들어야 해서, 이미지 없는 아틀라스 영역을 담을 수 없다)
- 원본과 다른 점:
- get_frame 은 범위를 넘으면 None 이다. (원본 undefined)
- from_atlas 의 기본 인자(fps = 10, is_loop = true)는 러스트에 없어서 늘 넘긴다. frame_ids 는 Display 되는 무엇이든(문자열, 정수) 받는다. 배열 아틀라스는 그 글을 번호로 읽는다.
- 3D 의 AnimationClip(graphics3d::skinnedmodel)과 이름이 같아서 lib.rs 에서 다시 내보내지 않는다. vanilla::resource::animationclip::AnimationClip 으로 쓴다.
Animation clip. (list of sprite sheet frame areas + whether it loops + duration)
- A port of the original resource/animationclip.js. Animator's AnimationState holds it.
- The original comment calls the frame list Frame[], but what from_atlas puts in is Rect. The Rust version settles on a list of Rect. (a Frame must hold an image, so it cannot hold an atlas area without an image)
- Differences from the original:
- get_frame is None when out of range. (the original undefined)
- Rust has no default arguments for from_atlas (fps = 10, is_loop = true), so they are always passed. frame_ids accepts anything that implements Display (strings, integers). Array atlases read that text as an index.
- It has the same name as the 3D AnimationClip (graphics3d::skinnedmodel), so it is not re-exported from lib.rs. Use it as vanilla::resource::animationclip::AnimationClip.
AnimationClipstruct traits Clone, Debug, Default, PartialEq
애니메이션 클립.
- 스프라이트 시트의 프레임 영역(Rect) 목록과 반복 여부, 길이(초)를 든다.
Animation clip.
- Holds a list of sprite sheet frame areas (Rect), whether it loops, and its duration (seconds).
use vanilla::Rect;
use vanilla::resource::animationclip::AnimationClip;
let mut clip = AnimationClip::new();
clip.set_frames(vec![Rect::create(0.0, 0.0, 32.0, 32.0), Rect::create(32.0, 0.0, 32.0, 32.0)]);
clip.set_loop(true);
clip.set_duration(0.2);
assert_eq!(clip.get_frame_count(), 2);
assert_eq!(clip.get_frame(1), Some(&Rect::create(32.0, 0.0, 32.0, 32.0)));
assert_eq!(clip.get_frame(2), None);
assert!(clip.is_loop());
assert_eq!(clip.get_duration(), 0.2);생성. (빈 프레임, 길이 0, 반복 안 함)
Creates one. (no frames, duration 0, no looping)
반환ReturnsAnimationClip 빈 클립.Empty clip.
짝Counterpart: vanilla.js AnimationClip.constructor
pub fn from_atlas<T: Display>(atlas_json: &Value, frame_ids: &[T], fps: f64, is_loop: bool) -> AnimationClip#아틀라스 JSON 으로 클립 생성. (정적)
- TexturePacker 형식({ frames: { 이름: { frame: {x,y,w,h} } } })과 배열 형식([{x,y,w,h}, ...]) 둘 다 받는다.
- frame_ids 차례로 프레임을 뽑아 duration = 프레임 수 / fps 로 만든다. 없는 이름은 건너뛴다.
- 영역은 frame 칸이 있으면 그것을, 없으면 항목 자체를 읽는다. 가로와 세로는 w, h 가 없으면 width, height 를 읽고, 없는 값은 0 이다.
Creates a clip from atlas JSON. (static)
- Accepts both the TexturePacker format ({ frames: { name: { frame: {x,y,w,h} } } }) and the array format ([{x,y,w,h}, ...]).
- Picks frames in frame_ids order and makes duration = frame count / fps. Missing names are skipped.
- For the area, reads the frame field if present, otherwise the entry itself. For width and height, reads width, height if w, h are missing, and missing values are 0.
- atlas_json&Value
- 아틀라스 JSON. (TexturePacker 객체 형식이나 배열 형식)Atlas JSON. (TexturePacker object format or array format)
- frame_ids&[T]
- 뽑을 프레임 이름이나 번호의 차례. (Display 되는 무엇이든, 배열 형식은 그 글을 번호로 읽는다)Order of frame names or indices to pick. (anything that implements Display, the array format reads that text as an index)
- fpsf64
- 초당 프레임 수. (0 이하이면 길이 0)Frames per second. (duration 0 if 0 or less)
- is_loopbool
- 반복 재생 여부.Whether to loop playback.
반환ReturnsAnimationClip 찾은 프레임만 차례로 담은 클립.Clip holding only the frames found, in order.
짝Counterpart: vanilla.js AnimationClip.fromAtlas
use vanilla::Rect;
use vanilla::resource::animationclip::AnimationClip;
let atlas_json = serde_json::json!({ "frames": {
"run0": { "frame": { "x": 0, "y": 0, "w": 32, "h": 48 } },
"run1": { "frame": { "x": 32, "y": 0, "w": 32, "h": 48 } },
} });
let clip = AnimationClip::from_atlas(&atlas_json, &["run0", "missing", "run1"], 4.0, true);
assert_eq!(clip.get_frame_count(), 2);
assert_eq!(clip.get_frame(1), Some(&Rect::create(32.0, 0.0, 32.0, 48.0)));
assert_eq!(clip.get_duration(), 0.5);use vanilla::Rect;
use vanilla::resource::animationclip::AnimationClip;
let atlas_json = serde_json::json!([{ "x": 0, "y": 0, "width": 16, "height": 16 }, { "x": 16, "y": 0, "w": 16, "h": 16 }]);
let clip = AnimationClip::from_atlas(&atlas_json, &[1, 0], 10.0, false);
assert_eq!(clip.get_frames(), &[Rect::create(16.0, 0.0, 16.0, 16.0), Rect::create(0.0, 0.0, 16.0, 16.0)]);
assert!(!clip.is_loop());프레임 목록 설정.
Sets the frame list.
- framesVec<Rect>
- 프레임 영역 목록. (스프라이트 시트 픽셀 좌표, 재생 차례)List of frame areas. (sprite sheet pixel coordinates, playback order)
짝Counterpart: vanilla.js AnimationClip.setFrames
반복 재생 여부 설정.
Sets whether to loop.
- is_loopbool
- 반복 재생 여부.Whether to loop playback.
짝Counterpart: vanilla.js AnimationClip.setLoop
애니메이션 지속 시간 설정. (초)
Sets the animation duration. (seconds)
- durationf64
- 한 바퀴 재생 시간. (초)Playback time for one loop. (seconds)
짝Counterpart: vanilla.js AnimationClip.setDuration
반복 재생 여부 반환.
Returns whether it loops.
반환Returnsbool 반복 재생하면 true. (기본 false)true to loop playback. (default false)
짝Counterpart: vanilla.js AnimationClip.isLoop
대상 번호의 프레임 반환. (범위를 넘으면 None)
Returns the frame at the target index. (None if out of range)
- indexusize
- 프레임 번호. (0 부터)Frame index. (from 0)
반환ReturnsOption<&Rect> 그 번호의 프레임 영역. 범위를 넘으면 None.Frame area at that index. None if out of range.
짝Counterpart: vanilla.js AnimationClip.getFrame
프레임 목록 반환.
Returns the frame list.
반환Returns&[Rect] 프레임 영역 목록. (재생 차례)List of frame areas. (playback order)
짝Counterpart: vanilla.js AnimationClip.getFrames
전체 프레임 수 반환.
Returns the total frame count.
반환Returnsusize 프레임 수.Frame count.
짝Counterpart: vanilla.js AnimationClip.getFrameCount
애니메이션 지속 시간 반환. (초)
Returns the animation duration. (seconds)
반환Returnsf64 한 바퀴 재생 시간. (초, 기본 0)Playback time for one loop. (seconds, default 0)
짝Counterpart: vanilla.js AnimationClip.getDuration