A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(editor): pick the one-way collision direction (not always up)
yhh8b43c1e0025b
diff --git a/desktop/src/i18n/messages/tile.ts b/desktop/src/i18n/messages/tile.tsindex 0865cbca3..a916578ad 100644--- a/desktop/src/i18n/messages/tile.ts+++ b/desktop/src/i18n/messages/tile.ts@@ -111,7 +111,11 @@ export const tileMessages = defineMessages({'tile.shape.circle': { en: 'Circle', zh: '圆形' },'tile.modifiers': { en: 'Modifiers', zh: '修饰' },'tile.oneWay': { en: 'One-way', zh: '单向' },- 'tile.oneWayTip': { en: 'One-way platform: painted collision is solid on top, pass-through from below', zh: '单向平台:所画碰撞上方实心、下方可穿过' },+ 'tile.oneWayTip': { en: 'One-way platform: painted collision is solid on the chosen side, pass-through from the other', zh: '单向平台:所画碰撞在所选一侧实心、另一侧可穿过' },+ 'tile.oneWay.up': { en: 'Solid top (jump-through)', zh: '顶部实心(可上跳穿过)' },+ 'tile.oneWay.down': { en: 'Solid bottom (ceiling)', zh: '底部实心(天花板)' },+ 'tile.oneWay.left': { en: 'Solid left', zh: '左侧实心' },+ 'tile.oneWay.right': { en: 'Solid right', zh: '右侧实心' },'tile.sensor': { en: 'Sensor', zh: '触发器' },'tile.sensorTip': { en: 'Sensor: painted collision is a non-solid trigger (fires events, no physical response)', zh: '触发器:所画碰撞为非实心触发(触发事件、无物理响应)' },'tile.friction': { en: 'friction', zh: '摩擦' },diff --git a/desktop/src/panels/TilesetEditor.tsx b/desktop/src/panels/TilesetEditor.tsxindex fff93c4dc..1692b733b 100644--- a/desktop/src/panels/TilesetEditor.tsx+++ b/desktop/src/panels/TilesetEditor.tsx@@ -18,7 +18,7 @@ import {useEffect, useRef, useState, useSyncExternalStore,type CSSProperties, type MouseEvent as ReactMouseEvent, type PointerEvent as ReactPointerEvent,} from 'react';-import { Plus, Trash2, X, ArrowUp } from 'lucide-react';+import { Plus, Trash2, X, ArrowUp, ArrowDown, ArrowLeft, ArrowRight } from 'lucide-react';import {TB_N, TB_E, TB_S, TB_W, TB_NE, TB_SE, TB_SW, TB_NW,type TilesetAsset, type TilesetAnimFrame,@@ -38,6 +38,14 @@ import { AnimPreview, tileThumbStyle, type TileAtlas } from '@/tools/tileThumb';import { SLOPE_PRESETS, presetPointsPx, type SlopePreset } from '@/tileset/slopePresets';import { t } from '@/i18n';+// One-way platform normals (physics/world convention, y-up): the solid side tiles pass+// through from the opposite side. `up` = solid-top (the classic jump-through platform).+const ONE_WAY_NORMALS = {+ up: { nx: 0, ny: 1 }, down: { nx: 0, ny: -1 }, left: { nx: -1, ny: 0 }, right: { nx: 1, ny: 0 },+} as const;+type OneWayDir = keyof typeof ONE_WAY_NORMALS;+const ONE_WAY_ICON: Record<OneWayDir, typeof ArrowUp> = { up: ArrowUp, down: ArrowDown, left: ArrowLeft, right: ArrowRight };+// Peering zones in the cell's 3×3 grid; center (membership) is handled separately.const ZONES: { gx: number; gy: number; bit: number; corner: boolean; dir: string }[] = [{ gx: 1, gy: 0, bit: TB_N, corner: false, dir: t('tile.dir.north') },@@ -324,6 +332,7 @@ export function TilesetEditor() {// Collision brush modifiers, orthogonal to the shape: while set, painted/stamped// collision carries a solid-top one-way normal, sensor flag, and/or a material override.const [oneWayOn, setOneWayOn] = useState(false);+ const [oneWayDir, setOneWayDir] = useState<OneWayDir>('up');const [sensorOn, setSensorOn] = useState(false);const [frictionStr, setFrictionStr] = useState('');const [restitutionStr, setRestitutionStr] = useState('');@@ -390,7 +399,7 @@ export function TilesetEditor() {};const brushMods = ((): TileCollisionMods => {const m: TileCollisionMods = {};- if (oneWayOn) m.oneWay = { nx: 0, ny: 1 };+ if (oneWayOn) m.oneWay = ONE_WAY_NORMALS[oneWayDir];if (sensorOn) m.sensor = true;const fr = numOrU(frictionStr); if (fr !== undefined) m.friction = fr;const re = numOrU(restitutionStr); if (re !== undefined) m.restitution = re;@@ -919,8 +928,30 @@ export function TilesetEditor() {aria-pressed={oneWayOn}onClick={() => setOneWayOn((v) => !v)}>- <ArrowUp size={13} /> {t('tile.oneWay')}+ {(() => { const I = ONE_WAY_ICON[oneWayDir]; return <I size={13} />; })()} {t('tile.oneWay')}</button>+ {oneWayOn && (+ // Which side is solid — a jump-through platform is `up`; ceilings/side gates+ // need the others. The painted normal follows this choice.+ <span className="ts-oneway-dirs">+ {(['up', 'down', 'left', 'right'] as OneWayDir[]).map((d) => {+ const I = ONE_WAY_ICON[d];+ return (+ <button+ key={d}+ type="button"+ className={'ts-oneway-dir' + (oneWayDir === d ? ' is-active' : '')}+ title={t(`tile.oneWay.${d}` as const)}+ aria-label={t(`tile.oneWay.${d}` as const)}+ aria-pressed={oneWayDir === d}+ onClick={() => setOneWayDir(d)}+ >+ <I size={12} />+ </button>+ );+ })}+ </span>+ )}<buttontype="button"className={'ts-oneway' + (sensorOn ? ' is-active' : '')}diff --git a/desktop/src/theme/tileset.css b/desktop/src/theme/tileset.cssindex d2daae931..e28d2a3a5 100644--- a/desktop/src/theme/tileset.css+++ b/desktop/src/theme/tileset.css@@ -178,6 +178,16 @@color: var(--text);background: color-mix(in srgb, var(--warn) 15%, var(--srf-3));}+/* One-way solid-side picker (shown while One-way is armed). */+.ts-oneway-dirs { display: inline-flex; gap: 2px; }+.ts-oneway-dir {+ display: grid; place-items: center; width: 22px; height: 22px;+ background: var(--srf-3); border: 1px solid var(--line); border-radius: var(--r-sm);+ color: var(--text-dim); cursor: pointer; transition: color var(--t-fast), border-color var(--t-fast);+}+.ts-oneway-dir:not(.is-active):hover { color: var(--text); border-color: var(--line-strong); }+.ts-oneway-dir.is-active { border-color: var(--warn); color: var(--text); background: color-mix(in srgb, var(--warn) 15%, var(--srf-3)); }+/* Solid side of a one-way tile — a bright top edge (the default {0,1} solid-top normal). */.ts-cell.is-oneway { box-shadow: inset 0 2px 0 var(--warn); }