프로그래밍/Corona SDK2013. 8. 28. 16:24
번역 : windship (windship@gmail.com)



graphics.newImageSheet()

타입

라이브러리graphics.*
리턴값ImageSheet
버전Current Public Release (2013.1137)
키워드sprite sheet, texture atlas, texture memory, images
참고Image Sheets (Sprite Sheets)

ImageSheet objects allow you to load multiple graphics from a single image file (also known as a spritesheet). Image sheets can be used for static images (useful for preloading many static images) and animated sprites.

ImageSheet 오브젝트는 하나의 이미지 파일로부터 여러 장의 조각 그림을 얻어낸다(spritesheet라고도 불리운다). 이미지 시트는 정적인 이미지들을 미리 로드하거나, 애니메이션 스프라이트를 만드는 데에 사용된다.

텍스처 샘플링

By default, new image sheets will use a linear sampling filter, so that the image will look smooth when the actual rendered region is larger or smaller than the pixel dimensions of the loaded texture.

기본적으로, 이미지 시트는 linear 샘플링 필터를 사용하게 되며, 로딩된 텍스처의 실제 크기보다 렌더링되는 크기가 크거나 작으면 이미지가 부드럽게 필터링되어 보이게 된다.

You can change the default texture filter by callingdisplay.setDefault(). Once an image is loaded the first time, the same sampling filter will be applied for any subsequent loads of the same file. This is because textures are loaded once per file.

텍스처의 필터링 방식은 display.setDefault() 함수를 호출함으로써 바꿀 수 있다. 처음 이미지 하나가 로드되면, 같은 파일을 여러번 로드하더라도 같은 필터가 계속 적용된다. 이것은 텍스처가 파일당 한번만 로드되기 때문이다.

Gotchas

Image sheet packing tools such as Texture Packer will output thesourceXsourceYsourceWidth, and sourceHeight parameters fortrimmed frames. When displaying these frames on the screen, the image will be positioned in respect to the center point of the untrimmed frame size.

Texture Packer와 같은 툴을 사용해 만든 이미지 시트는 조각그림을 자르는 데 필요한 sourceX, sourceY, sourceWidth, sourceHeight과 같은 파라미터 정보를 포함시킨다. 스크린에 이 그림들을 표시할 때, 이미지는 잘리지 않은 프레임 사이즈의 중점을 참고하여 표시된다.

graphics.newImageSheet( filename, [baseDir, ] options )
filename (필수)

String. This is the filename of the image file that includes all frames of the image sheet. This file is also called a spritesheet image.

문자열. 이미지 시트의 모든 프레임이 들어있는 이미지 파일의 파일명이다. 이 파일은 spritesheet 이미지라고도 불린다.

baseDir (선택)

Constant. Specifies the base directory where filename is located. Options include system.ResourceDirectory,system.DocumentsDirectorysystem.TemporaryDirectory andsystem.CachesDirectory. Default is system.ResourceDirectory.

상수. 위의 이미지 파일이 있는 디렉토리명이다. system.ResourceDirectory,system.DocumentsDirectorysystem.TemporaryDirectory 그리고 system.CachesDirectory 를 옵션으로 선택할 수 있으며, 디폴트는 system.ResourceDirectory이다.

options (필수)

Table. Table with keys that represent specific options related to the resulting image sheet. There are two different formats for this table: Simple and Complex. See 'Formats for options' below.

테이블. 키를 가진 테이블로써 이미지 시트에 관련된 특정 옵션들을 제공한다. 이 테이블에는 간단한 것과 복합적인 것 2가지 형식이 있다. 아래의 옵션 형식 항목을 보라.

options에 사용되는 형식들

단 타입

This configuration assumes all frames in the image sheet texture share identical properties.

이 형식은 동일 프로퍼티를 공유하는 이미지 시트 텍스처의 모든 프레임을 포함한다.

local options =
{
    width = 50,
    height = 50,
    numFrames = 3
}
width (필수)

Number. Width of all images (frames) in the image sheet texture.

수치값. 이미지 시트 텍스처에 있는 모든 이미지들(프레임들)의 가로폭.

height (필수)

Number. Height of all images (frames) in the image sheet texture.

수치값. 이미지 시트 텍스처에 있는 모든 이미지들(프레임들)의 세로폭.

numFrames (필수)

Number. Total number of images (frames) in the image sheet.

수치값. 이미지 시트에 있는 모든 이미지들(프레임들)의 총 갯수.

border (선택)

Number. The border around each frame, typically used for tiles whose edges are extruded to eliminate seam artifacts. Default is 0. When > 0, this overrides the trimming options for cropping the frame.

수치값. 각 프레임 사이의 경계선. 보통 타일 경계선이 흐려지거나 할 때를 위해서 쓴다. 디폴트값은 0. 만약 0보다 큰 값이 설정되면, 프레임을 자를 때 자르는 옵션이 된다.

합 타입

This configuration is required if the image sheet has frames of varying sizes. In this configuration, options consists of an array of tables within a parent frames table. Each table in the array represents a single frame in the image sheet.

이 설정은 크기가 제각각인 프레임을 가진 이미지 시트가 필요할 경우 사용한다. 이 설정에서, options는 부모 frames 테이블 안에 있는 테이블 배열을 상속받는다. 배열 안의 각 테이블들은 이미지 시트 안의 하나씩의 프레임을 되돌린다.

local options =
{
    frames =
    {
        -- FRAME 1:
        {
            x = 0,
            y = 70,
            width = 50,
            height = 50
        },

        -- FRAME 2:
        {    
            x = 50,
            y = 70,
            width = 45,
            height = 55
        },

        -- FRAME 3 and so on...
    }
}
(필수)

Number. x-location of the frame in the texture.

수치값. 텍스처 내에서 프레임의 가로 위치.

(필수)

Number. y-location of the frame in the texture.

수치값. 텍스처 내에서 프레임의 세로 위치.

width (필수)

Number. Width of the frame (if cropping, specify cropped width here).

수치값. 프레임의 가로 크기. (만약 잘린다면 여기에 잘릴 가로 크기를 명시한다)

height (필수)

Number. Height of the frame (if cropping, specify cropped height here).

수치값. 프레임의 세로 크기. (만약 잘린다면 여기에 잘릴 세로 크기를 명시한다)

sourceWidth (선택)

Number. Width of the original uncropped frame. Default: same as width (required parameter).

수치값. 잘리지 않은 프레임의 원래 가로 크기. 기본값은 width와 같다.

sourceHeight (선택)

Number. Height of the original uncropped frame. Default: same as height (required parameter).

수치값. 잘리지 않은 프레임의 원래 세로 크기. 기본값은 height와 같다.

sourceX (선택)

Number. The x-origin of the crop rect relative to the uncropped image. Default: 0.

수치값. 잘리지 않은 이미지에 대응하는 잘린 사각형 영역의 가로 기준점. 디폴트값은 0.

sourceY (선택)

Number. The y-origin of the crop rect relative to the uncropped image. Default: 0.

수치값. 잘리지 않은 이미지에 대응하는 잘린 사각형 영역의 세로 기준점. 디폴트값은 0.

border (선택)

Number. The amount of pixels around each individual frame. This is necessary for scaling image sheets without getting blending artifacts around the edges. Default: 0.

수치값. 각각의 프레임 둘레의 픽셀의 양. 이미지 시트가 확대/축소될 때 외곽선에 필터가 영향을 끼치는 것을 막기 위해 사용된다. 디폴트값은 0.

간단 타입 예제:

local options =
{
    -- 아래 파라미터는 필수

    width = 70,
    height = 41,
    numFrames = 2,

    -- 아래 파라미터는 선택적이다. 동적 해상도 지원에 사용된다

    sheetContentWidth = 70,  -- 전체 시트의 원래 100% 가로 사이즈
    sheetContentHeight = 82  -- 전체 시트의 원래 100% 세로 사이즈
}

local imageSheet = graphics.newImageSheet( "fishies.png", options )

복합 타입 예제:

local options =
{
    -- 각각의 프레임을 되돌려 주는 배열 테이블 (필수)
    frames =
    {
        -- 프레임  1:
        {
            -- 각각의 프레임마다 이하의 파라미터는 전부 필요하다
            x = 2,
            y = 70,
            width = 50,
            height = 50
        },

        -- 프레임 2:
        {
            x = 2,
            y = 242,
            width = 50,
            height = 52
        },
    },

    -- 선택 파라미터 : 동적 해상도 지원에 필요하다
    sheetContentWidth = 1024,
    sheetContentHeight = 1024
}

local imageSheet = graphics.newImageSheet( "imageframes.png", options )


Posted by windship