Canvas (WebGL/WebGPU)
How to control Pixi’VN canvas components from ink scripts using hashtag commands such as `# show`, `# edit`, `# remove`, `# pause`, `# resume` and `# animate`. Explains syntax, parameters and examples.
The ink + Pixi’VN integration introduces a "# script" that allows you to show, edit, remove, and animate a canvas component.
Animated sprites
Animated sprites from ink require @drincs/pixi-vn-ink 1.4.0, @drincs/pixi-vn 1.9.9 and @drincs/pixi-vn-json 1.16.0 or later.
You can use the AnimatedSprite component from ink. Use asprite as the component type. A spritesheet can come from AssetPack, TexturePacker, or the Aseprite/LibreSprite conversion plugin described on the component page.
# show asprite hero heroSheet animation walk useFrameDurations true
# show asprite blink heroSheet frames [ eyes_open.png eyes_closed.png ]
# pause asprite hero
# resume asprite hero
# edit asprite hero animationSpeed 0.5 loop false
# goto asprite hero 2
# remove asprite hero with moveout duration 1The show command uses the component alias as its spritesheet alias when a separate source is omitted. animation, frames, spritesheet, and useFrameDurations describe the frames, while display properties such as anchor, align, scale, animationSpeed, and loop configure the component. pause stops playback and resume starts it again.
goto selects a zero-based frame index and preserves the playing state. Editing source properties reloads the frames. Show and remove commands support the existing with <transition> [<key> <value> ...] syntax. Ink maps these commands to static asprite operations in the compiled JSON; @drincs/pixi-vn-json handles their execution at runtime.
=== start ===
# show image eggHead x 20 y 20
# show image flowerTop x 220 y 20 with dissolve
# show image helmlok x 20 y 220 with movein
# show image skully x 220 y 220 with zoomin
# pause
# move eggHead x 300 y 0
# rotate flowerTop
# edit image helmlok alpha 0.5
# shake skully
# pause
# remove image eggHead
# remove image flowerTop with dissolve duration 2
# remove image helmlok with moveout
# remove image skully with zoomout
# pause
-> DONEComponents functions
Show
You can use the show to show a canvas component in ink. To do this, you need to use the following syntax:
# show image eggHead
# show image "eggHead 2" eggHead xAlign 1 yAlign 1
# show image flowerTop xAlign 0 yAlign 1 visible true cursor "pointer" alpha 0.5
# show video my_video xAlign 1 yAlign 0
# show text hello "Hello, this is a text" xAlign 0.5 yAlign 0.5 style \\\{ "fill": "red", "fontSize": 30 \\\}Available parameters (all optional) are the properties of PixiVNJsonCanvasImageVideoShowProps or PixiVNJsonCanvasTextShowProps.
Edit
You can use the edit to edit a canvas component in ink. To do this, you need to use the following syntax:
# edit image bg position \{ "x": 20, "y": 30 \} visible true cursor "pointer" alpha 0.5Available parameters (all optional) vary by component:
image: properties ofImageSpriteMemory.video: properties ofVideoSpriteMemory.imagecontainer: properties ofImageContainerMemory.text: properties ofTextMemory.
Remove
You can use the remove to remove a canvas componentin ink. To do this, you need to use the following syntax:
# remove image bg
# remove image "bg 2"Pause and resume
=== start ===
# show video my_video
Video started
# pause video my_video
Video
Video paused
# resume video my_video
Video resumed
-> DONEAnimate
You can use the animate to use the animations in ink. To do this, you need to use the following syntax:
# animate alien angle 360 options duration 1The keyframes define the target state you want the component's properties to reach (e.g. a position, scale, or opacity), while parameters define how to get there (e.g. duration, easing).
Available keyframes vary by component:
image: properties ofImageSpriteMemory.video: properties ofVideoSpriteMemory.imagecontainer: properties ofImageContainerMemory.text: properties ofTextMemory.
Available parameters (all Optional) can include all the motion options and additional parameters you would use in JS/TS. You can find all the parameters in detail in PixiVNJsonAnimateBaseOptions.
Here are some examples:
Articulated animations
Articulated animations are functions that use the canvas.animate function under the hood to create animations that involve multiple steps, such as shaking, bouncing, or other complex effects. You can trigger them in ink using a dedicated hashtag command for each effect.
You can use an effect command (such as shake) to apply a ready-made articulated animation effect (for example shakeEffect) to a canvas component. To do this, you need to use the following syntax:
# shake bg
# shake "bg 2"
# shake bg strength 20
# bounce eggHead
# pulse "bg 2"
# glitch bg
# shockwave bgAvailable effect values, with their parameters (all optional), which are the properties of the corresponding interface:
shake: properties ofShakeEffectProps.bounce: properties ofBounceEffectProps.pulse: properties ofPulseEffectProps.hop: properties ofHopEffectProps.wiggle: properties ofWiggleEffectProps.nod: properties ofNodEffectProps.sway: properties ofSwayEffectProps.punch: properties ofPunchEffectProps.glitch: properties ofGlitchEffectProps.chromatic-aberration: properties ofChromaticAberrationEffectProps.shockwave: properties ofShockwaveEffectProps.radial-blur: properties ofRadialBlurEffectProps.blur-pulse: properties ofBlurPulseEffectProps.vignette-pulse: properties ofVignettePulseEffectProps.desaturate: properties ofDesaturateEffectProps.glow-pulse: properties ofGlowPulseEffectProps.