From f66e619d13b44c0d0525dd2e8c70daa58773af90 Mon Sep 17 00:00:00 2001 From: Matt Jennings Date: Sun, 3 Dec 2023 22:28:46 -0600 Subject: [PATCH] fix examples to not be 0-based coordinates but still be responsive --- .../docs/api/components/animated-sprite.mdx | 4 ++ .../docs/api/components/application.mdx | 14 +++--- .../docs/api/components/assets-loader.mdx | 2 + .../docs/api/components/bitmap-text.mdx | 3 +- .../content/docs/api/components/container.mdx | 6 +-- .../content/docs/api/components/graphics.mdx | 2 + .../content/docs/api/components/html-text.mdx | 2 + docs/src/content/docs/api/components/mesh.mdx | 10 +++- .../docs/api/components/nine-slice-plane.mdx | 2 + .../api/components/particle-container.mdx | 6 +-- .../content/docs/api/components/renderer.mdx | 16 +++---- .../docs/api/components/simple-plane.mdx | 4 +- .../docs/api/components/simple-rope.mdx | 3 +- .../content/docs/api/components/sprite.mdx | 2 + docs/src/content/docs/api/components/text.mdx | 2 + .../content/docs/api/components/ticker.mdx | 2 + .../docs/api/components/tiling-sprite.mdx | 2 + .../content/docs/api/utilities/on-tick.mdx | 2 +- docs/src/content/docs/api/utilities/track.mdx | 14 +++--- .../content/docs/getting-started/usage.mdx | 48 ++++++++++++------- docs/src/content/docs/guides/animation.mdx | 9 ++-- .../src/content/docs/guides/binding-props.mdx | 19 ++++---- .../docs/guides/optimizing-performance.mdx | 18 +++---- .../layouts/examples/wrappers/Empty.svelte | 4 +- .../layouts/examples/wrappers/WithApp.svelte | 23 +++++++-- 25 files changed, 140 insertions(+), 79 deletions(-) diff --git a/docs/src/content/docs/api/components/animated-sprite.mdx b/docs/src/content/docs/api/components/animated-sprite.mdx index 70536d1..bca8f02 100644 --- a/docs/src/content/docs/api/components/animated-sprite.mdx +++ b/docs/src/content/docs/api/components/animated-sprite.mdx @@ -19,6 +19,8 @@ I recommend using spritesheets created by TexturePacker ([they have a great tuto - + - +
console.log('render')} > - + diff --git a/docs/src/content/docs/api/components/container.mdx b/docs/src/content/docs/api/components/container.mdx index cb4b312..22dab8e 100644 --- a/docs/src/content/docs/api/components/container.mdx +++ b/docs/src/content/docs/api/components/container.mdx @@ -16,9 +16,9 @@ When child components are rendered inside, their coordinates become local to the import { Container, Text } from 'svelte-pixi' - - - + + + ``` diff --git a/docs/src/content/docs/api/components/graphics.mdx b/docs/src/content/docs/api/components/graphics.mdx index 049f9fa..d3ee88f 100644 --- a/docs/src/content/docs/api/components/graphics.mdx +++ b/docs/src/content/docs/api/components/graphics.mdx @@ -25,6 +25,8 @@ Graphics can be used for any kind of drawing. Use the `draw` prop to interact wi { graphics.clear() graphics.beginFill(0xde3249) diff --git a/docs/src/content/docs/api/components/html-text.mdx b/docs/src/content/docs/api/components/html-text.mdx index 388cf36..9af3563 100644 --- a/docs/src/content/docs/api/components/html-text.mdx +++ b/docs/src/content/docs/api/components/html-text.mdx @@ -17,6 +17,8 @@ Renders text with support for styling via HTML tags. The rendering can vary acro - + ``` ## API diff --git a/docs/src/content/docs/api/components/nine-slice-plane.mdx b/docs/src/content/docs/api/components/nine-slice-plane.mdx index 03d73df..6c30b3c 100644 --- a/docs/src/content/docs/api/components/nine-slice-plane.mdx +++ b/docs/src/content/docs/api/components/nine-slice-plane.mdx @@ -27,6 +27,8 @@ Allows you to stretch a texture using 9-slice scaling. The corners will remain u @@ -38,9 +38,9 @@ This is an alternative to using the [Application](/docs/components/application) can access it with getStage() --> - + @@ -82,7 +82,7 @@ If you want to customize the element that the canvas is rendered into, you can u }} /> { @@ -134,9 +134,9 @@ we can still implement this ourselves: }} > - + diff --git a/docs/src/content/docs/api/components/sprite.mdx b/docs/src/content/docs/api/components/sprite.mdx index c9e0b79..6902c94 100644 --- a/docs/src/content/docs/api/components/sprite.mdx +++ b/docs/src/content/docs/api/components/sprite.mdx @@ -16,6 +16,8 @@ Sprites are the base for all textured objects that are rendered to the screen - + ``` ## Type Definition diff --git a/docs/src/content/docs/api/utilities/track.mdx b/docs/src/content/docs/api/utilities/track.mdx index 125f567..31d0b88 100644 --- a/docs/src/content/docs/api/utilities/track.mdx +++ b/docs/src/content/docs/api/utilities/track.mdx @@ -11,17 +11,17 @@ This is useful for watching a property on a PixiJS instance that is getting upda import { Container, Text, onTick, track } from 'svelte-pixi' let instance - let x = track(() => instance.x, -200) - let y = track(() => instance.y, 0) + let x = track(() => instance.x, 200) + let y = track(() => instance.y, 200) - $: text = $x < -75 ? "I'm on the left!" : "I'm on the right!" + $: text = $x < 300 ? "I'm on the left!" : "I'm on the right!" + // modify the instance directly onTick((delta) => { - if (instance.x < 100) { - // modify the instance directly - instance.x += 1 * delta + if (instance.x < 500) { + instance.x += delta } else { - instance.x = -200 + instance.x = 200 } }) diff --git a/docs/src/content/docs/getting-started/usage.mdx b/docs/src/content/docs/getting-started/usage.mdx index dec74fa..1e97999 100644 --- a/docs/src/content/docs/getting-started/usage.mdx +++ b/docs/src/content/docs/getting-started/usage.mdx @@ -15,9 +15,9 @@ All Svelte Pixi components should be children of `Application`. import { Application, Text } from 'svelte-pixi' - + - + @@ -72,13 +72,13 @@ _Note: You may want to enable network throttling in your browser dev tools to ac ] - + @@ -113,8 +113,8 @@ components can hook into the loop with `onTick`. import * as PIXI from 'pixi.js' import { Sprite, onTick } from 'svelte-pixi' - let x = 0 - let y = 0 + let x = 360 + let y = 200 let time = 0 onTick((delta) => { @@ -122,8 +122,8 @@ components can hook into the loop with `onTick`. // for any kind of movement, you should multiply by delta // to ensure it moves at the same speed regardless of framerate time += delta * 0.05 - x = Math.cos(time) * 50 - y = Math.sin(time) * 50 + x = 360 + Math.cos(time) * 50 + y = 200 + Math.sin(time) * 50 }) @@ -142,7 +142,7 @@ Most Svelte Pixi components have an `instance` prop that contains the underlying PixiJS instance. It's akin to the `this` prop for HTML elements, so you can bind to it if you need to access it. -```svelte live +```svelte live {5,14} - + ``` ## Using a Custom Instance @@ -164,7 +170,7 @@ The `instance` prop also lets you pass down a custom PixiJS class that you've instantiated yourself. This is particularly useful if you have a custom class (whether that be your own or from a third-party library). -```svelte live +```svelte live {14} - + ``` diff --git a/docs/src/content/docs/guides/animation.mdx b/docs/src/content/docs/guides/animation.mdx index a58884f..5dc9047 100644 --- a/docs/src/content/docs/guides/animation.mdx +++ b/docs/src/content/docs/guides/animation.mdx @@ -14,7 +14,7 @@ You can animate using `svelte/motion` just like you would in other Svelte applic let dragging = false let offset = { x: 0, y: 0 } - let startingPosition = { x: 0, y: 0 } + let startingPosition = { x: 360, y: 200 } let position = spring(startingPosition, { stiffness: 0.2, @@ -66,9 +66,10 @@ You can animate using `svelte/motion` just like you would in other Svelte applic /> ``` @@ -107,6 +108,8 @@ You can animate using `svelte/motion` just like you would in other Svelte applic { graphics.clear() diff --git a/docs/src/content/docs/guides/binding-props.mdx b/docs/src/content/docs/guides/binding-props.mdx index 35c150e..cc1a854 100644 --- a/docs/src/content/docs/guides/binding-props.mdx +++ b/docs/src/content/docs/guides/binding-props.mdx @@ -14,20 +14,21 @@ Instead, Svelte Pixi provides a [track](/docs/utilities/track) utility function let instance - let x = track(() => instance.x, -300) - let y = track(() => instance.y, -150) + let x = track(() => instance.x, 360) + let y = track(() => instance.y, 200) function reset() { - $x = -300 - $y = -150 + $x = 360 + $y = 200 + time = 0 } + let time = 0 onTick((delta) => { - if (instance.x < 200) { - instance.x += 0.5 * delta - instance.y += 0.2 * delta - } - }) + time += delta * 0.02 + instance.x = 360 + Math.cos(time) * 50 + instance.y = 200 + Math.sin(time) * 50 + }) {/each} @@ -74,7 +74,7 @@ Let's take another approach by using Pixi a bit more directly: import { Sprite, onTick, Container } from 'svelte-pixi' import { onMount } from 'svelte' - const width = 800 + const width = 720 const height = 400 const speed = 0.025 const fov = 20 @@ -127,8 +127,8 @@ Let's take another approach by using Pixi a bit more directly: star.scale.set(distance * starSize) star.anchor.set(0.5, 0.7) - star.x = star.initX * (fov / z) * width - star.y = star.initY * (fov / z) * width + star.x = star.initX * (fov / z) * width + width / 2 + star.y = star.initY * (fov / z) * height + height / 2 } // move the camera forward @@ -173,15 +173,15 @@ You can set `render="demand"` on the `Application` component to opt into this be console.log('render')} > - + +
diff --git a/docs/src/layouts/examples/wrappers/WithApp.svelte b/docs/src/layouts/examples/wrappers/WithApp.svelte index 2cf7d96..4378c65 100644 --- a/docs/src/layouts/examples/wrappers/WithApp.svelte +++ b/docs/src/layouts/examples/wrappers/WithApp.svelte @@ -1,5 +1,5 @@