API / core/frame
core/frame
이미지 영역. (프레임)
- 원본 core/frame.js 를 옮긴 것이다. 프레임 루프가 아니라 스프라이트 이미지 한 장, 또는 시트 안의 한 칸이다. Animation 이 이것을 목록으로 들고 차례로 넘긴다.
- 원본은 image 가 null 이면 예외를 던진다. 러스트 판은
Rc<Image>를 받아서 비어 있을 수 없다. - 원본처럼 영역을 이미지 크기 안으로 자르지 않는다. (원본도 그 줄은 주석으로 꺼 두었다)
Image region. (frame)
- A port of the original core/frame.js. Not a frame loop, but one sprite image or one cell in a sheet. Animation holds these as a list and steps through them in order.
- The original throws an exception if image is null. The Rust version takes
Rc<Image>so it cannot be empty. - Like the original, it does not clip the region to the image size. (the original also has that line commented out)
예제Example시트 한 장을 네 칸 프레임으로 나누기Splitting one sheet into four cell frames
use vanilla::{Frame, Image, Rect};
let image = Image::create_from_pixels(64, 16, vec![0u8; 64 * 16 * 4]);
let mut frame_list = Vec::new();
for index in 0..4 {
let cell_rect = Rect::create(index as f64 * 16.0, 0.0, 16.0, 16.0);
frame_list.push(Frame::new(image.clone(), Some(cell_rect)));
}
assert_eq!(frame_list.len(), 4);
assert_eq!(frame_list[3].get_image_rect(), Rect::create(48.0, 0.0, 16.0, 16.0));Framestruct traits Clone
이미지 영역.
- 이미지 한 장과 그 안의 사각형 영역(픽셀)을 같이 든다. 복제하면 이미지는
Rc로 같이 쓴다.
Image region.
- Holds one image together with a rectangular region (pixels) in it. When cloned, the image is shared through
Rc.
예제Example이미지 전체 프레임과 한 칸 프레임A whole-image frame and a one-cell frame
use std::rc::Rc;
use vanilla::{Frame, Image, Rect};
let image = Image::create_from_pixels(64, 32, vec![0u8; 64 * 32 * 4]);
let whole_frame = Frame::new(image.clone(), None);
assert_eq!(whole_frame.get_image_rect(), Rect::create(0.0, 0.0, 64.0, 32.0));
assert!(Rc::ptr_eq(whole_frame.get_image(), &image));
let cell_frame = Frame::new(image, Some(Rect::create(16.0, 8.0, 16.0, 16.0)));
assert_eq!(cell_frame.get_image_rect(), Rect::create(16.0, 8.0, 16.0, 16.0));생성. (rect 가 없으면 이미지 전체를 영역으로 한다)
Constructor. (uses the whole image as the region if rect is None)
- imageRc<Image>
- 영역을 뗄 이미지.Image to take the region from.
- rectOption<Rect>
- 이미지 안의 영역. (픽셀, 이미지 왼쪽 위 기준) None 이면 (0, 0, 이미지 너비, 이미지 높이). 이미지 밖으로 나가도 자르지 않는다.Region in the image. (pixels, from the top left of the image) None means (0, 0, image width, image height). Not clipped even if it goes outside the image.
반환ReturnsFrame 새 프레임.New frame.
짝Counterpart: vanilla.js Frame.constructor
이미지 반환.
Returns the image.
반환Returns&Rc<Image> 프레임이 든 이미지의 참조.Reference to the image the frame holds.
짝Counterpart: vanilla.js Frame.getImage
이미지 내부 영역 반환.
Returns the image inner region.
반환ReturnsRect 이미지 안의 영역. (픽셀, 복사본)Region in the image. (pixels, a copy)
짝Counterpart: vanilla.js Frame.getImageRect