Skip to content

Commit 3ca3c92

Browse files
committed
docs: add documentation for Sprite Manager
1 parent 68bd3b6 commit 3ca3c92

15 files changed

Lines changed: 247 additions & 29 deletions

File tree

editor/src/editor/layout/inspector/sprites/sprite-manager.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export class EditorSpriteManagerNodeInspector extends Component<IEditorInspector
248248
accept3dlTexture={false}
249249
acceptCubeTexture={false}
250250
onChange={async (texture) => {
251-
if (isTexture(texture)) {
251+
if (!texture || isTexture(texture)) {
252252
this._handleSpritesheetTextureChanged(texture);
253253
}
254254
}}

editor/src/editor/layout/inspector/sprites/sprite.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,19 @@ export class EditorSpriteInspector extends Component<IEditorInspectorImplementat
160160
}
161161

162162
private _getSpriteAnimationsInspector(): ReactNode {
163-
let maxFrame = this._spriteManagerNode?._previews?.length;
164-
if (maxFrame !== undefined) {
165-
maxFrame -= 1;
163+
let maxFrame = 0;
164+
165+
if (this._spriteManagerNode?.atlasJson) {
166+
maxFrame = Object.keys(this._spriteManagerNode.atlasJson.frames).length - 1;
167+
} else if (this._spriteManagerNode) {
168+
maxFrame = this._spriteManagerNode._previews?.length;
169+
if (maxFrame !== undefined) {
170+
maxFrame -= 1;
171+
}
166172
}
167173

168174
const spriteAnimations = this.props.object.metadata.spriteAnimations as ISpriteAnimation[];
169175

170-
this.props.object.animationStarted;
171-
172176
return (
173177
<EditorInspectorSectionField title="Animations">
174178
<div className="flex justify-between items-center">

editor/src/editor/nodes/sprite-manager.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { readJSONSync } from "fs-extra";
21
import { dirname, isAbsolute, join } from "path/posix";
2+
import { pathExistsSync, readJSONSync } from "fs-extra";
33

44
import { Node, TransformNode, Scene, Tools, serialize, SerializationHelper, Matrix, GetClass, SpriteManager, Texture, Sprite, Observer } from "babylonjs";
55

6+
import { showAlert } from "../../ui/dialog";
7+
68
import { UniqueNumber } from "../../tools/tools";
79

810
import { configureImportedTexture } from "../layout/preview/import/import";
@@ -90,13 +92,19 @@ export class SpriteManagerNode extends TransformNode {
9092
}
9193

9294
public buildFromAtlasJsonAbsolutePath(absolutePath: string, serializeSpriteManager?: any): void {
95+
const atlasJson = readJSONSync(absolutePath);
96+
const imagePath = join(dirname(absolutePath), atlasJson.meta["image"]);
97+
98+
if (!pathExistsSync(imagePath)) {
99+
showAlert("Error", `Cannot find the associated image for the atlas JSON file: ${imagePath}`);
100+
return;
101+
}
102+
93103
this.spriteManager?.dispose();
94104

95-
this.atlasJson = readJSONSync(absolutePath);
105+
this.atlasJson = atlasJson;
96106
this.atlasJsonRelativePath = absolutePath.replace(getProjectAssetsRootUrl()!, "");
97107

98-
const imagePath = join(dirname(absolutePath), this.atlasJson.meta["image"]);
99-
100108
this.spriteManager = new SpriteManager(
101109
this.name,
102110
imagePath,
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
538 KB
Loading

website/src/app/documentation/scripting/listening-events/page.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ import {
1515
} from "./pointer-event";
1616

1717
import { NextChapterComponent } from "../../components/next-chapter";
18-
import { PointerEventTypes } from "@babylonjs/core";
1918

2019
export default function DocumentationRunningProjectPage() {
21-
PointerEventTypes.POINTERDOUBLETAP;
22-
2320
return (
2421
<main className="w-full min-h-screen p-5 bg-black text-neutral-50">
2522
<div className="flex flex-col gap-10 lg:max-w-3xl 2xl:max-w-6xl mx-auto pt-32">
@@ -128,7 +125,7 @@ export default function DocumentationRunningProjectPage() {
128125

129126
<CodeBlock code={onKeyboardEventArrayBasicExample} />
130127

131-
<NextChapterComponent href="/documentation/advanced/compressing-textures" title="Compressing textures" />
128+
<NextChapterComponent href="/documentation/sprites/using-sprite-manager" title="Using Sprite Manager" />
132129
</div>
133130
</Fade>
134131
</div>

0 commit comments

Comments
 (0)