> 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-pt/criar-para-mobile/desenvolver/detect-platform.md).

# Detectar a plataforma

Detecte se sua scene está sendo executada em mobile, desktop ou web.

Use o `isMobile()` função para adaptar sua UI, controles e jogabilidade especificamente para mobile. Esta é a forma recomendada de oferecer uma ótima experiência em todos os clients sem bifurcar completamente a lógica da sua scene.

## Funções disponíveis

```ts
import { getPlatform, isMobile, isDesktop, isWeb } from '@dcl/sdk/platform'
```

* **`getPlatform()`** — retorna a plataforma atual como `'mobile' | 'desktop' | 'web' | null`. Retorna `null` até que o Explorer tenha informado sua plataforma de volta à scene (isso acontece logo após a scene iniciar).
* **`isMobile()`** — retorna `true` se o jogador estiver no client mobile.
* **`isDesktop()`** — retorna `true` se o jogador estiver no client desktop.
* **`isWeb()`** — retorna `true` se o jogador estiver no client web.

{% hint style="warning" %}
**📔 Observação**: Essas funções leem um valor que é preenchido de forma assíncrona quando a scene inicia, e nada garante que ele já esteja disponível no momento em que `main()` é executado. Se você chamá-las cedo demais, elas ainda podem retornar `null` / `false`. Para garantir, adie qualquer configuração dependente da plataforma até `getPlatform()` retorne algo diferente de `null`, por exemplo verificando dentro de um System:

```ts
import { engine } from '@dcl/sdk/ecs'
import { getPlatform } from '@dcl/sdk/platform'

function platformCheckSystem() {
  if (getPlatform() === null) return
  engine.removeSystem(platformCheckSystem)
  setupUI()
}

engine.addSystem(platformCheckSystem)
```

{% endhint %}

## Divida sua UI por plataforma

Um padrão comum é configurar uma UI diferente para players mobile e desktop:

```ts
import { isMobile, isDesktop } from '@dcl/sdk/platform'

function setupUI() {
  if (isMobile()) {
    // Botões maiores, layout mais simples para toque
    createMobileUI()
  } else if (isDesktop()) {
    // Layout mais denso ajustado para teclado e mouse
    createDesktopUI()
  }
}
```

Você também pode usar o mesmo padrão para:

* Mostrar ou esconder instruções na tela adaptadas a cada método de input.
* Substituir elementos clicáveis pequenos por alvos de toque maiores no mobile.
* Desativar bindings de input que não estão facilmente disponíveis no mobile (veja [Input no mobile](/creator/content-creator-pt/criar-para-mobile/desenvolver/input-on-mobile.md)).

## Verificando o valor bruto da plataforma

Se você precisar lidar com múltiplas plataformas em um único switch, use `getPlatform()`:

```ts
import { getPlatform } from '@dcl/sdk/platform'

const platform = getPlatform()

switch (platform) {
  case 'mobile':
    // comportamento específico de mobile
    break
  case 'desktop':
    // comportamento específico de desktop
    break
  case 'web':
    // comportamento específico de web
    break
  case null:
    // plataforma ainda desconhecida
    break
}
```

## Relacionados

* [Área segura do mobile](/creator/content-creator-pt/criar-para-mobile/desenvolver/safe-area.md)
* [Boas práticas de UI para mobile](/creator/content-creator-pt/criar-para-mobile/desenvolver/ui-best-practices.md)
* [UI no ecrã](/creator/content-creator-pt/scenes-sdk7/ui-2d/onscreen-ui.md)


---

# 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-pt/criar-para-mobile/desenvolver/detect-platform.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.
