Files

6.5 KiB

From a full UI image to an editable Cocos prefab

Use this workflow for a new page or a set of switchable pages drawn in a user design. Work with the project's reusable artwork and the user's own designs and assets. For a third-party inspiration reference, create original visuals for the new UI.

When image generation helps

Image generation is optional. Cocos MCP handles asset import, prefab composition, and preview verification. Any image generation or editing comes from a tool available in the AI client or the project's art pipeline.

  • For a layered design, reuse its exported assets. For a flattened image, reuse clean cuts from visible regions and build text, dividers, and simple surfaces with native UI components. The reference can be analyzed by an image-capable client or described in a supplied component map.
  • If a complex background or icon is missing, or a UI element hides part of the background, use an available image generation or editing tool to produce just the missing asset. Specify its intended dimensions, silhouette, style, and transparency or bleed. Inspect the output at its intended size and mark generated artwork as an approximation until it passes the visual comparison.
  • With no generation tool, proceed with reusable assets and the layout that can be verified. If missing artwork blocks fidelity acceptance, request the corresponding clean background, transparent sprite, or layered design. Record any placeholder and the affected regions in the review.

Lock the design and map the parts

  • Keep each reference at its original pixel dimensions. Identify the game viewport, the selected page/tab, the locale, visible counter values, list scroll position, and relevant control states. Keep the reference and state record for comparison after implementation. If supplied pages disagree on a shared control, resolve the intended variant and record each deliberate departure from the references.
  • Use the existing Canvas policy in an established project. On a new page without a baseline, use the intended full viewport as the design basis. Map part bounds in top-left reference pixels, node paths, stacking order, anchors, and fixed or flexible edges. Distinguish visible artwork bounds from the control's layout box and hit area.
  • Record the chosen source for each part. Inspect cutouts, including their alpha edges and original padding, against the background they will actually use.

Build the saved UI

  • Keep the full reference image outside the rendered hierarchy. Import only the separately reusable art and use real SpriteFrames. Separate the background, title, button surfaces, icons, labels, badges, progress track/fill, and state overlays so each can move or change independently. Give text, dynamic values, and localization native text components. Reserve graphical lettering for artwork meant to stay fixed.
  • Share a navigation prefab or shell across related pages. Keep each tab's icon and caption separate from the normal and selected backgrounds and divider lines. Derive the highlight, tab widths, divider positions, label placement, and hit areas from the selected state and available width. Use nine-slice for stretchable surfaces with fixed corners. Keep icon proportions and intentional blank margins.
  • Author repeated lists as reusable rows in a ScrollView with a clipped viewport and Layout-managed content. Give each row separate art, text, and button bindings. Bind callbacks inside standalone prefab boundaries and use the project's normal events or controller bindings to connect them to a shell.
  • Save the UI under the existing Canvas with UI_2D layers. Use native prefab serialization, verify exact imported references, and confirm that assets survive reload or fresh instantiation. Consult sprites and importers for trim/insets and text and localization for font behavior. If an icon appears too large, check the imported trim and padding first. If a label clips, apply the font and overflow policy before setting the final box, then inspect the glyph baseline in preview.
  • Adapt regions independently. Use anchors for pinned controls, let the list viewport consume the remaining space, and crop flexible background art while preserving its aspect ratio. Keep a single owner for each driven dimension. Use layout and adaptation for the project's resize and safe-area policy.

Verify fidelity in the actual preview

  1. Capture the saved scene or prefab instance in the target Cocos preview. For fidelity, use a raw PNG of the same game viewport size and state as the reference. Check visible landmarks, the crop and the canvas size. Equal PNG dimensions alone can still conceal a cropped or zoomed capture.
  2. Compare at the same pixel coordinates. Review the whole page, then zoom into the mapped regions for icon silhouettes, alignment, text baselines, borders, shadow/alpha edges, and clipping. Use a side-by-side view and, when available, a same-scale overlay, wipe, or difference heatmap. Avoid shifting or stretching individual regions during comparison.
  3. Check node geometry and rendered appearance separately. Use runtime bounds projected into capture pixels for geometry. Use the visible pixels for glyphs, strokes, and artwork. Region color error, structural similarity, and tolerant edge overlap can help locate differences. Choose tolerances for the project before accepting results, and review each required region so a large matching background cannot hide a small control defect.
  4. Fix the source of each difference and recapture under the same conditions. A flat 1 px stroke may require a filled border or different pixel alignment. A matching node box can still contain the wrong sprite or state. Preserve the original design, captures, per-region results, and any approved variations for review.
  5. Check adaptation at the requested narrow and wide viewports with real pointer input. Exercise the in-scope page changes, button states, value updates, list scrolling and clipping using input and validation. Report the fidelity result for the baseline size and the adaptation/input results for the tested sizes. State any remaining mismatches or untested conditions.

For example, a shared bottom bar can have separate mapped regions for five icon silhouettes, the selected surface, a thin divider, and the full bar. At the reference size, check these independently. On a wider viewport, check that the highlight and lines follow the slots and that the same tabs respond to clicks. This catches trim and resize problems even when the page looks close in a thumbnail.