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.
# show imagecontainer james [m01-body m01-eyes m01-mouth] xAlign 0.5 yAlign 1
# show imagecontainer sly [fm01-body fm01-eyes fm01-mouth] xAlign 0.2 yAlign 1 with movein
# show imagecontainer steph [fm02-body fm02-eyes fm02-mouth] xAlign 0.8 yAlign 1 with dissolveAvailable parameters (all optional) are the properties of PixiVNJsonCanvasImageContainerShowProps.
If you want to show the canvas component with a transition, you can add into the parameters the with {transition type}.
# show eggHead with dissolve duration 3
temp durationVar = 3
# show eggHead eggHead2 with fade duration {durationVar}
# show flowerTop x 20 y 30 with movein direction left
# show helmlok x 20 y 30 with zoomin
# show skully x 20 y 30 with pushinAvailable transition parameters (all optional) are the properties of PixiVNJsonMediaTransiotions, and vary depending on the transition type used:
dissolve: properties ofShowWithDissolveTransitionProps.fade: properties ofShowWithFadeTransitionProps.movein: properties ofMoveInOutProps.pushin: properties ofPushInOutProps.zoomin: properties ofZoomInOutProps.wipein: properties ofWipeInOutProps.irisin: properties ofIrisInOutProps.splitin: properties ofSplitInOutProps.blurin: properties ofBlurInOutProps.pixelatein: properties ofPixelateInOutProps.flashin: properties ofFlashInOutProps.glitchin: properties ofGlitchInOutProps.twistin: properties ofTwistInOutProps.warpin: properties ofWarpInOutProps.ripplein: properties ofRippleInOutProps.noisedissolvein: properties ofNoiseDissolveInOutProps.tvin: properties ofTvInOutProps.pinchin: properties ofPinchInOutProps.
For remove, use the out counterpart of each in type (e.g. wipeout, moveout); dissolve and fade stay the same.
Редактировать
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.
Удалить
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"If you want to remove the canvas component with a transition, you can add after the alias of the canvas component with {transition type}.
# remove image bg with dissolve duration 3
temp durationVar = 3
# remove image bg with fade duration {durationVar}
# remove image bg with moveout
# remove image bg with zoomout
# remove image bg with pushoutAvailable transition parameters (all optional) are the properties of PixiVNJsonMediaTransiotions, and vary depending on the transition type used:
dissolve: properties ofShowWithDissolveTransitionProps.fade: properties ofShowWithFadeTransitionProps.movein: properties ofMoveInOutProps.pushin: properties ofPushInOutProps.zoomin: properties ofZoomInOutProps.wipein: properties ofWipeInOutProps.irisin: properties ofIrisInOutProps.splitin: properties ofSplitInOutProps.blurin: properties ofBlurInOutProps.pixelatein: properties ofPixelateInOutProps.flashin: properties ofFlashInOutProps.glitchin: properties ofGlitchInOutProps.twistin: properties ofTwistInOutProps.warpin: properties ofWarpInOutProps.ripplein: properties ofRippleInOutProps.noisedissolvein: properties ofNoiseDissolveInOutProps.tvin: properties ofTvInOutProps.pinchin: properties ofPinchInOutProps.
For remove, use the out counterpart of each in type (e.g. wipeout, moveout); dissolve and fade stay the same.
Пауза и возобновление
=== start ===
# show video my_video
Video started
# pause video my_video
Video
Video paused
# resume video my_video
Video resumed
-> DONETo pause a video in ink, you can use pause. To do this, you need to use the following syntax:
# pause video bg
# pause video "bg 2"To resume a video in ink, you can use resume. To do this, you need to use the following syntax:
# resume video bg
# resume video "bg 2"Animate
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.
Вот несколько примеров:
=== start ===
# show image alien
# animate alien xAlign 1 yAlign 0 options ease "easeOut"
# pause
# animate alien xAlign 1 yAlign 1 options ease "backOut"
# pause
# animate alien xAlign 0 yAlign 1 options ease "circIn"
# pause
# animate alien xAlign 0 yAlign 0 options ease "linear"
# pause
-> DONE=== start ===
# show alien
# animate alien angle 360 options duration 1 type "spring" repeat Infinity repeatDelay 0.2
# pause
-> DONE=== start ===
# show alien
# animate alien alpha 0 options ease "linear" duration 1
# pause
-> DONE=== start ===
# show alien
# animate alien scaleX 0 scaleY 0 options ease "circInOut" duration 1
# pause
-> DONE=== start ===
# show alien
# animate alien scaleX -1 options duration 1
# pause
# animate alien scaleX 1 options duration 1
# pause
-> DONEШарнирные анимации
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.