# Mobile, touch and orientation

This guide shows how to make a game playable on phones and tablets inside the portal's frame: detecting the device, orientation, safe areas, touch controls, audio and memory. Most players arrive on a phone. If you tick **Works on mobile** in the submission, reviewers test on one, and the game must offer the same features as on desktop. Examples assume `const SDK = window.ZokoGames.SDK;` as in the [SDK introduction](https://docs.zokogames.com/sdk/introduction#loading); unfamiliar terms are in the [glossary](https://docs.zokogames.com/getting-started/glossary).

## Know the device

```js
const SDK = window.ZokoGames.SDK;
await SDK.init();
const info = SDK.environment !== "disabled" ? SDK.user.systemInfo : null;
const isMobile = info?.device.type === "mobile";
const inAppShell = info !== null && info.applicationType !== "web";
```

`device.type` is `"desktop"`, `"tablet"` or `"mobile"`. Use it, not `"ontouchstart" in window`: laptops have touch screens and tablets have keyboards. `applicationType` is `"web"`, `"pwa"`, `"google_play_store"` or `"apple_store"`; the last three mean the portal runs inside an app shell, where safe areas matter more. In local mode (your own `localhost` page) `systemInfo` is read from your own browser (and `applicationType` is always `"web"`), so confirm the values the portal reports in the [Preview tool](https://www.zokogames.com/preview). When the SDK is disabled `info` is `null` and the code above falls back to desktop; add your own check such as `matchMedia("(pointer: coarse)")` for standalone runs.

## Orientation

You declare orientation in the submission: landscape, portrait or both. The portal shows a rotate prompt when the phone is held the wrong way, so you do not lock orientation in code.

- A game that declares **both** must lay out correctly in each. Listen to `resize`, not `orientationchange`, and read `innerWidth` and `innerHeight` fresh.
- Portrait games should make the playfield fit a 360 x 640 CSS pixel viewport without scrolling.
- Keep important UI away from the corners and bottom edge, where the OS reserves gesture zones.

## Safe areas

```css
.hud {
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  padding-left: max(8px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right));
}
```

Include `<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover, user-scalable=no">` in `index.html`.

## Touch controls

- Use pointer events and track each finger by `pointerId`.
- Touch targets are at least 44 x 44 CSS pixels with a gap between them.
- Put virtual sticks and buttons where thumbs rest, and let the player see through them.
- `touch-action: none` on the canvas stops panning and pinch zoom. Add `user-select: none` and `-webkit-touch-callout: none` to the body.
- Never require hover or a right-click. Offer a long-press or a visible button instead.
- Show on-screen controls only when `device.type` is `"mobile"` or `"tablet"` and hide keyboard hints there. Show keyboard hints on desktop.

More input pitfalls are in [control pitfalls](https://docs.zokogames.com/guides/input-controls).

## Audio on iOS

Resume the `AudioContext` inside the first touch or click handler. See [audio on iOS](https://docs.zokogames.com/requirements/technical#audio-on-ios). Also honour `SDK.game.settings.muteAudio`.

## Memory and performance

- Cap `devicePixelRatio` at 1 on phones for large canvases; 2 is usually the most you can afford.
- Keep textures compressed or small. A 2048 x 2048 texture uses about 16 MB of memory however small the file.
- Mobile initial download target is 20 MB. Above it the validator warns and reviewers test on a phone.
- Avoid allocating in the frame loop. Phones throttle when they heat up.
- Unity WebGL is off on iOS by default. Tick **Works on iOS** only after testing.

## Text input

Use a real `<input>` so the on-screen keyboard opens, and keep it visible when the visual viewport shrinks. Use `window.visualViewport` to reposition UI when the keyboard opens.

## Ads and banners on small screens

- Use banners on menus, game-over and shop screens, never over controls. A 320x50 or 320x100 banner fits a 360 px wide phone; see [banners](https://docs.zokogames.com/sdk/banners).
- Pause on `adStarted` and refocus the canvas after `adFinished`.

## Test checklist

- [ ] Playable at 360 x 640 and at 360 x 800 with no clipped buttons.
- [ ] Rotating the phone does not reset the game or break the layout, if both orientations are declared.
- [ ] No accidental zoom, text selection or pull-to-refresh.
- [ ] Sound starts after the first tap and respects mute.
- [ ] The game runs on a mid-range Android phone with a throttled network. The target is about 10 seconds to reach play on 4G.
- [ ] Works with the on-screen keyboard open when there is text input.

## Next steps

- [Mouse, keyboard and touch control pitfalls](https://docs.zokogames.com/guides/input-controls)
- [Audio, pausing and ads](https://docs.zokogames.com/guides/audio-and-ads)
