> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-ko/sdk7/2d-ui/ui_background.md).

# UI 배경

UI 엔티티의 배경과 테두리를 설정합니다.

다음 속성을 사용해 UI 엔티티의 배경과 테두리를 설정합니다.

## 배경

A `uiBackground` 컴포넌트는 엔티티 영역에 색상이나 텍스처를 지정합니다. 이 컴포넌트는 엔티티의 `uiTransform`.

다음 필드를 구성할 수 있으며, 모두 선택 사항입니다.

* `color`: 엔티티에 사용할 색상으로, [Color4](https://docs.decentraland.org/creator/content-creator-ko/sdk7/3d/color-types.md) 값입니다.

{% hint style="info" %}
**💡 팁**: 의 4번째 값을 1보다 작게 설정하면 엔티티를 반투명하게 만들 수 있습니다. `Color4` 로 설정합니다.
{% endhint %}

* `texture`: 엔티티에 표시할 텍스처입니다. 텍스처 관련 매개변수가 포함된 객체를 지정합니다. 다음 항목의 텍스처와 동일한 속성을 사용할 수 있습니다. [3D 엔티티의 머티리얼](https://docs.decentraland.org/creator/content-creator-ko/sdk7/3d/materials.md#using-textures).

  * `src`: 텍스처로 사용할 이미지 파일의 경로입니다. (문자열)

  * `filterMode`: *(선택 사항)* 렌더링할 때 텍스처의 픽셀을 늘리거나 압축하는 방식을 결정합니다. 자세한 내용은 [텍스처 크기 조정](https://docs.decentraland.org/creator/content-creator-ko/sdk7/3d/materials.md#texture-scaling)을 참조하세요. (FilterMode = 'point' | 'bi-linear' | 'tri-linear')

  * `wrapMode`: *(선택 사항)* 텍스처를 엔티티에 타일 형태로 적용하는 방식을 결정합니다. 다음에서 값을 지정합니다. `TextureWrapMode` 열거형입니다. \[텍스처 래핑]\(([문서 참조](https://github.com/decentraland/docs/tree/main/creator/sdk7/README.md))을 참조하세요. (WrapMode = 'repeat' | 'clamp' | 'mirror')

  > 팁: 하나의 `texture` 및 `color` 속성을 함께 사용하면 `uiBackground` 컴포넌트에서 텍스처에 색조를 입힐 수 있습니다.
* `textureMode`: 텍스처가 적용된 엔티티의 크기에 맞춰 텍스처를 조정하는 방식을 선택합니다. (TextureMode = 'nine-slices' | 'center' | 'stretch') 다음 값을 지원하는 열거형입니다.
  * `center`: 텍스처를 늘리지 않고 엔티티의 중앙에 배치합니다. 엔티티 크기에 따라 텍스처의 일부가 잘릴 수 있습니다.
  * `stretch`: 텍스처를 늘려 엔티티의 전체 표면에 맞춥니다.
  * `nine-slices`: 텍스처의 여백은 늘리지 않고 일부 영역만 늘려 엔티티의 전체 표면에 맞춥니다. 자세한 내용은 [나인 슬라이스 텍스처](#nine-slice-textures).
* `avatarTexture`: 아바타 ID를 기반으로 아바타 프로필 썸네일을 표시합니다. \[아바타 초상화]\(([문서 보기](https://github.com/decentraland/docs/tree/main/creator/sdk7/README.md)).
* `textureSlices`: 나인 슬라이스 텍스처 모드를 사용할 때 적용할 여백을 지정합니다. 자세한 내용은  [나인 슬라이스 텍스처](#nine-slice-textures)를 참고하세요. 이미지의 전체 너비 또는 높이에 대한 비율로 1보다 작은 숫자를 설정합니다.

단순한 색상:

***ui.tsx 파일:***

```tsx
import { ReactEcs, UiEntity } from '@dcl/sdk/react-ecs'
import { Color4 } from '@dcl/sdk/math'

export const uiMenu = () => (
  <UiEntity
    uiTransform={{
      width: 700,
      height: 400
    }}
    uiBackground={{
		color: Color4.create(0.5, 0.8, 0.1, 0.6)
	}}
  />
)
```

***index.ts 파일:***

```ts
import { ReactEcsRenderer } from '@dcl/sdk/react-ecs'
import { uiMenu } from './ui'

export function main() {
    ReactEcsRenderer.setUiRenderer(uiMenu, { virtualWidth: 1920, virtualHeight: 1080 })
}
```

{% hint style="warning" %}
**📔 참고**: 이 페이지의 다음 모든 코드 조각은 다음과 같은 `.ts` 파일에서 위와 비슷하게 `ReactEcsRenderer.setUiRenderer()` 함수를 실행한다고 가정합니다.
{% endhint %}

반복 텍스처 패턴:

```ts
import { UiEntity, ReactEcs } from '@dcl/sdk/react-ecs'

export const uiMenu = () => (
  <UiEntity
    uiTransform={{
      width: 700,
      height: 400
    }}
    uiBackground={{
		textureMode: 'center',
		texture: {
			src: "images/brick-wall-texture.png",
			wrapMode: 'repeat'
		}
	}}
  />
)
```

## 테두리

UI 엔터티 주위에 테두리를 설정할 때 사용하는 몇 가지 속성이 있습니다. 이 속성은  `uiTransform`  컴포넌트에 있습니다. 각 속성은 테두리의 모든 면에 단일 값을 적용하거나 면마다 서로 다른 값을 설정할 수 있습니다.

* `borderColor`: 엔터티에 적용할 색상으로,  [Color4](https://docs.decentraland.org/creator/content-creator-ko/sdk7/3d/color-types.md)  값입니다.
* `borderWidth`: 테두리의 너비를 픽셀 단위로 지정합니다. 백분율 값도 지원합니다. 예를 들어  `borderWidth: '2%'` 를 설정하면 테두리 너비가 엔터티 너비의 2%가 됩니다.
* `borderRadius`: 이 속성을 사용하면 엔터티의 모서리를 둥글게 만들 수 있습니다. 모서리의 반경을 픽셀 단위로 설정합니다.

```ts
import { UiEntity, ReactEcs } from '@dcl/sdk/react-ecs'
import { Color4 } from '@dcl/sdk/math'

export const uiMenu = () => (
  <UiEntity
    uiTransform={{
      width: 700,
      height: 400,
      borderColor: Color4.Red(),
      borderWidth: 4,
      borderRadius: 10
    }}
  />
)
```

`borderWidth`, `borderColor` 및 `borderRadius` 도 엔터티의 면마다 서로 다른 값으로 설정할 수 있습니다.

```ts
import { UiEntity, ReactEcs } from '@dcl/sdk/react-ecs'
import { Color4 } from '@dcl/sdk/math'

export const uiMenu = () => (
  <UiEntity
    uiTransform={{
      width: 700,
      height: 400,
      borderColor: { top: Color4.White(), left: Color4.Red(), right: Color4.Blue(), bottom: Color4.Gray() },
      borderRadius: { topLeft: 20, topRight: 20, bottomLeft: 20, bottomRight:0 },
      borderWidth: { top: 3, left: 2, right: 3, bottom: 4 }
    }}
  />
)
```

## 불투명도

의  `opacity`  속성을  `uiTransform`  컴포넌트에서  `UiEntity` 에 사용하면 엔터티와 모든 자식 엔터티에 투명도를 적용할 수 있습니다. opacity 속성은 0부터 1까지의 값이며, 0은 완전히 투명하고 1은 완전히 불투명합니다.

```ts
import { UiEntity, ReactEcs } from '@dcl/sdk/react-ecs'
import { Color4 } from '@dcl/sdk/math'

export const uiMenu = () => (
  <UiEntity
    uiTransform={{
      width: 700,
      height: 400,
      opacity: 0.7
    }}
    uiBackground={{ color: Color4.Green() }}
  >
    <UiEntity
        uiTransform={{
          width: 100,
          height: 30,
        }}
        uiText={{
          value: "이 텍스트도 투명합니다",
          fontSize: 40
        }}
      />
   </UiEntity>
)
```

불투명도 값은 UiEntity의 모든 자식에 영향을 주며, 배경색, 텍스트 색상, 배경 이미지에 투명도를 적용합니다. 부모와 자식 모두 불투명도 값을 지정한 경우, 자식의 최종 불투명도는 자식 값과 부모 값의 곱입니다.

```ts
import { UiEntity, ReactEcs } from '@dcl/sdk/react-ecs'
import { Color4 } from '@dcl/sdk/math'

export const uiMenu = () => (
  <UiEntity
    uiTransform={{
      width: 700,
      height: 400,
      opacity: 0.7
    }}
    uiBackground={{ color: Color4.Green() }}
  >
    <UiEntity
      uiTransform={{
        width: 100,
        height: 30,
        opacity: 0.7
      }}
      uiText={{
        value: "이 텍스트는 훨씬 더 투명합니다",
        fontSize: 40
      }}
    />
  </UiEntity>
)
```

## 나인패치 텍스처

텍스처에 [9슬라이스 스케일링](https://en.wikipedia.org/wiki/9-slice_scaling) 을 사용하면 모서리와 여백이 고르지 않게 늘어나는 것을 방지할 수 있습니다.

널리 사용되는 이 기법에서는 이미지를 9개의 영역으로 나누고, 여백과 모서리의 비율을 유지하도록 각 영역을 서로 다른 방식으로 늘립니다. 예를 들어, 크기에 따라 쉽게 조정되는 둥근 모서리 배경을 만들 때 사용할 수 있습니다. 다음 이미지를 살펴보세요(Wikipedia에서 가져옴: [위키백과](https://en.wikipedia.org/wiki/9-slice_scaling#/media/File:Traditional_scaling_vs_9-slice_scaling.svg)):

![](https://3980763956-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-c07e3501f6f9fda01f510b0c0c237ea207d00e3d%2F9-slice.webp?alt=media)

이 이미지에서는 원본 텍스처(왼쪽 위)와 일반적인 방식으로 크기를 조정한 결과(오른쪽 위)를 볼 수 있습니다. 모서리가 어떻게 변형되는지 확인해 보세요. 그 아래에는 9개 영역으로 나눈 텍스처(왼쪽 아래)와 9슬라이스 방식에 따라 이미지를 늘린 결과(오른쪽 아래)가 있습니다.

위 이미지를 기준으로 각 영역에 어떤 변화가 생기는지 살펴보겠습니다.

* 영역 5만 이미지에서 x축과 y축 양쪽으로 완전히 늘어납니다.
* 영역 1, 3, 7, 9(모서리)은 전혀 늘어나지 않습니다.
* 영역 2와 8은 가로 방향으로만 늘어납니다.
* 4번과 6번 세그먼트는 세로 방향으로만 늘어납니다.

엔티티에서 나인 슬라이스 늘이기를 사용하려면 다음을 설정합니다. `textureMode` 를 `'nine-slices'`로 설정합니다. 필요에 따라 각 변의 여백 너비도 `textureSlices`.

```ts
import { UiEntity, ReactEcs } from '@dcl/sdk/react-ecs'

export const uiMenu = () => (
  <UiEntity
    uiTransform={{ width: 700, height: 400 }}
    uiBackground={{
      textureMode: 'nine-slices',
      texture: {
        src: 'images/rounded_alpha_square.png'
      },
      textureSlices: {
        top: 0.2,
        bottom: 0.2,
        left: 0.2,
        right: 0.2
      }
	}}
  />
)
```

다음 `textureSlices` 값은 요소의 크기가 아니라 **텍스처의** 크기를 기준으로 한 분수입니다. 값이 `0.125` 128픽셀 텍스처에서는 16픽셀 모서리가 만들어지며, 요소가 100픽셀 버튼이든 1,400픽셀 패널이든 모서리의 너비는 가상 픽셀 기준으로 항상 16픽셀입니다. 데스크톱 클라이언트에서는 요소가 커져도 모서리 셀은 커지지 않습니다.

따라서 화면에 표시할 모서리 크기에 맞춰 아트를 만드세요. 가상 픽셀 기준으로 모서리 크기를 정한 다음, 텍스처를 그 크기가 다음 값이 되도록 그립니다. `textureSlices` × 텍스처의 크기. 디자인에 버튼용 작은 모서리와 패널용 큰 모서리가 모두 있다면, 크기마다 별도의 텍스처를 사용하세요. 같은 이미지에서 더 큰 `textureSlices` 값을 사용해도 모서리 아트가 커지지는 않기 때문입니다.

## 텍스처 UV

의 `uvs` 속성을 `uiBackground` 텍스처의 특정 영역을 표시하는 컴포넌트입니다. 스프라이트 시트에서 개별 스프라이트를 선택하거나 이미지를 회전할 때 유용합니다.

&#x20;`uvs`  필드는 숫자 8개로 이루어진 배열을 받으며, 텍스처 영역의 네 모서리에 해당하는 UV 좌표 쌍 4개를 나타냅니다. 순서는 다음과 같습니다. **왼쪽 아래**, **왼쪽 위**, **오른쪽 위**, **오른쪽 아래**입니다. 각 값의 범위는 0\~1이며,  `(0, 0)` 는 이미지의 왼쪽 아래 모서리이고 `(1, 1)` 는 오른쪽 위 모서리입니다.

{% hint style="info" %}
**💡 팁**: 사용자 지정  `uvs`를 사용할 때는  `textureMode` 를  `'stretch'` 로 설정하면 선택한 영역이 엔티티 영역을 가득 채웁니다.
{% endhint %}

### 스프라이트 시트의 스프라이트

큰 이미지의 일부(예: 여러 장의 카드가 포함된 스프라이트 시트에서 카드 한 장)를 표시하려면  `uvs` 를 해당 영역의 좌표로 설정합니다.

```ts
import { UiEntity, ReactEcs } from '@dcl/sdk/react-ecs'

// 텍스처의 왼쪽 절반 표시(예: 2열 시트의 첫 번째 카드)
export const uiMenu = () => (
  <UiEntity
    uiTransform={{ width: 200, height: 300 }}
    uiBackground={{
      textureMode: 'stretch',
      texture: { src: 'images/card-atlas.png' },
      uvs: [
        // 왼쪽 아래, 왼쪽 위, 오른쪽 위, 오른쪽 아래
        0, 0,
        0, 1,
        0.5, 1,
        0.5, 0
      ]
    }}
  />
)
```

프레임이 격자 형태로 배치된 스프라이트 시트(예: 4열 2행)의 경우, 원하는 프레임의 열과 행을 기준으로 UV 좌표를 계산합니다.

```ts
import { UiEntity, ReactEcs } from '@dcl/sdk/react-ecs'

// 격자형 스프라이트 시트에서 프레임 하나 선택
function getFrameUVs(col: number, row: number, totalCols: number, totalRows: number): number[] {
  const stepU = 1 / totalCols
  const stepV = 1 / totalRows
  const left = col * stepU
  const right = (col + 1) * stepU
  const top = 1 - row * stepV
  const bottom = 1 - (row + 1) * stepV
  return [
    left, bottom,
    left, top,
    right, top,
    right, bottom
  ]
}

// 4x2 스프라이트 시트의 2열 0행 표시
export const uiMenu = () => (
  <UiEntity
    uiTransform={{ width: 128, height: 128 }}
    uiBackground={{
      textureMode: 'stretch',
      texture: { src: 'images/spritesheet.png' },
      uvs: getFrameUVs(2, 0, 4, 2)
    }}
  />
)
```

### UV 좌표로 이미지 회전

UV 좌표에 2D 회전을 적용하여 텍스처를 회전할 수 있습니다. 변환 기반 회전을 사용하지 않고 스피너나 로딩 표시기를 만들 때 유용합니다.

```ts
import { UiEntity, ReactEcs } from '@dcl/sdk/react-ecs'
import { engine } from '@dcl/sdk/ecs'

// 중심을 기준으로 2D 점 회전
function rotate2D(angle: number, x: number, y: number, cx: number, cy: number): number[] {
  const cos = Math.cos(angle)
  const sin = Math.sin(angle)
  return [
    cos * (x - cx) - sin * (y - cy) + cx,
    sin * (x - cx) + cos * (y - cy) + cy
  ]
}

// 회전된 UV 좌표 생성
function rotateUVs(angle: number): number[] {
  const uv00 = rotate2D(angle, 0, 0, 0.5, 0.5)
  const uv01 = rotate2D(angle, 0, 1, 0.5, 0.5)
  const uv11 = rotate2D(angle, 1, 1, 0.5, 0.5)
  const uv10 = rotate2D(angle, 1, 0, 0.5, 0.5)
  return [uv00[0], uv00[1], uv01[0], uv01[1], uv11[0], uv11[1], uv10[0], uv10[1]]
}

let spinnerAngle = 0

// 매 프레임 각도를 업데이트하는 시스템
engine.addSystem((dt: number) => {
  spinnerAngle += dt * 5
})

export const uiMenu = () => (
  <UiEntity
    uiTransform={{ width: 128, height: 128 }}
    uiBackground={{
      textureMode: 'stretch',
      texture: { src: 'images/spinner.png' },
      uvs: rotateUVs(spinnerAngle)
    }}
  />
)
```

&#x20;`rotateUVs`  함수는 네 개의 UV 모서리를 중심점을 기준으로 회전합니다. 각도는 `(0.5, 0.5)` 라디안 단위로 지정합니다. React와 유사한 렌더러가 매 프레임 이 함수를 호출하므로 스피너가 부드럽게 회전합니다.

그림만 회전합니다. 요소 자체와 클릭 가능한 영역, 자식 요소 및 텍스트는 제자리에 그대로 있습니다. 깔끔하게 회전하려면 다음 사항에 유의하세요:

* **요소를 정사각형으로 유지하세요**. 정사각형이 아닌 상자에서는 회전하는 이미지가 찌그러집니다.
* **그림 주위에 투명한 여백을 두세요**. 45°를 넘으면 회전 영역의 모서리가 텍스처 밖으로 벗어나고, 가장자리 픽셀이 늘어나 그 모서리를 채웁니다. 그림을 정사각형에 들어가는 원 안쪽에 배치하고 주위에는 투명 픽셀을 두세요.
* **텍스처에 `wrapMode: 'clamp'`** 를 설정하면 가장자리가 반복되지 않고 늘어납니다: `texture: { src: 'images/spinner.png', wrapMode: 'clamp' }`.

{% hint style="info" %}
**💡 팁**: 스프라이트, 애니메이션 스프라이트 시트, 스피너 등을 포함한 전체 작동 예제는 다음을 참조하세요: [UI 애니메이션](https://github.com/decentraland/sdk7-goerli-plaza/tree/main/ui-animations) 예제 씬.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.decentraland.org/creator/content-creator-ko/sdk7/2d-ui/ui_background.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
