Transition
Effects played between two nodes by Scene.playTransition.
ts
import { Transition, TransitionCanvas } from "willow";Transition
ts
class TransitionAn effect Scene.playTransition plays between two nodes. Willow's C++ SceneManager plays the same effects, so the two always look alike. Use Transition.fade for a crossfade, or write your own: a class that extends Transition, calls super(seconds) and overrides render(). new Transition() itself is not available. class LeftWipe extends Transition { constructor(seconds: float) { super(seconds); } render(progress: float, outgoing: TextureRegion, incoming: TextureRegion, canvas: TransitionCanvas): void { canvas.draw(outgoing, 0.0, 0.0); canvas.drawPart(incoming, 0.0, 0.0, progress * canvas.width, canvas.height, 0.0, 0.0); } }
Transition: constructors
ts
new Transition(seconds: float)Called by a subclass as super(seconds).
seconds: How long the transition takes, 0 or more. 0 completes on the next frame.
Transition: properties
| Member | Description |
|---|---|
readonly duration: float | Length of the transition in seconds. |
Transition: methods
| Member | Description |
|---|---|
render(progress: float, outgoing: TextureRegion, incoming: TextureRegion, canvas: TransitionCanvas): void | The hook a subclass overrides to draw one frame. Willow has already drawn both screens, the way the scene draws them (camera, lights, filters and masks included), and calls this every frame while the transition plays. Draw the result with canvas: whatever is not drawn leaves the scene showing through, so a transition normally draws outgoing first and then the part of incoming that has arrived. Both regions and the canvas are valid only during this call, so do not store them. An exception thrown here is reported and that frame keeps whatever was drawn before it threw. - progress: How far along the transition is, from 0 (just started) to 1 (finished). - outgoing: The outgoing node, drawn as it looks now. - incoming: The incoming node, drawn as it looks now. - canvas: What to draw the effect with. |
Transition: static methods
| Member | Description |
|---|---|
static fade(seconds: float): Transition | A crossfade: the incoming node fades in over the outgoing one, a linear blend of the two. - seconds: How long the fade takes, 0 or more. 0 completes on the next frame. - Returns: The transition. |
TransitionCanvas
ts
class TransitionCanvasWhat a Transition draws with, passed to its render(). Drawing goes straight onto the screen at the point where the transition sorts in the scene, in screen pixels (the top-left of the screen is (0, 0)). The canvas is only valid while render() runs: a stored canvas raises InvalidStateError when used later.
TransitionCanvas: properties
| Member | Description |
|---|---|
readonly width: int | Width of the area being transitioned, in pixels. Both source regions are this wide. |
readonly height: int | Height of the area being transitioned, in pixels. Both source regions are this tall. |
TransitionCanvas: methods
| Member | Description |
|---|---|
draw(region: TextureRegion, x: float, y: float, alpha?: float): void | Draws region whole, with its top-left corner at (x, y), at its own size. - region: What to draw, normally outgoing or incoming. - x: Screen X of the region's left edge. - y: Screen Y of the region's top edge. - alpha: Opacity from 0 to 1. Defaults to 1. |
drawPart(region: TextureRegion, srcX: float, srcY: float, width: float, height: float, x: float, y: float, alpha?: float): void | Draws one rectangle of region, with its top-left corner at (x, y), at its own size. A wipe draws a strip of the incoming screen that grows with the progress. A rectangle that runs past the region is cut to it. - region: What to draw, normally outgoing or incoming. - srcX: Left edge of the rectangle, in the region's own pixels. - srcY: Top edge of the rectangle, in the region's own pixels. - width: Width of the rectangle in pixels. - height: Height of the rectangle in pixels. - x: Screen X where the rectangle's left edge lands. - y: Screen Y where the rectangle's top edge lands. - alpha: Opacity from 0 to 1. Defaults to 1. |