GifCapture

Entityceramic.GifCapture (Class)

Captures the screen content and creates animated GIF files.

This utility allows recording gameplay or animations from your Ceramic app and exporting them as GIF files. It supports frame blending for smooth animations and configurable frame rates.

Features

  • Screen capture to animated GIF
  • Configurable frame rates and duration
  • Frame blending for smoother animations
  • Automatic file saving
  • Real-time capture with fixed delta time

Usage Example

var capture = new GifCapture();

// Start capturing for 5 seconds at 30 FPS
capture.captureScreen(1, 1.0, 30, 5.0, "recording.gif");

// Listen for completion
capture.onFinish(this, () -> {
    trace("GIF saved!");
});

// Or manually stop capture
app.onceDelay(this, 3.0, () -> {
    var bytes = capture.finish("manual-stop.gif");
    trace("Captured " + bytes.length + " bytes");
});

Instance Members

gif
captureScreen(?imagesPerFrame: Int = 1, ?middleFactor: Float = 1, ?gifFps: Int = 50, ?duration: Float = -1, ?path: String): Void

Starts capturing the screen content to create an animated GIF.

Name Type Default Description
imagesPerFrame Int 1 Number of screen captures to blend per GIF frame (higher = smoother)
middleFactor Float 1 Blending weight for middle frames (0-1, affects smoothness)
gifFps Int 50 Target frame rate for the output GIF
duration Float -1 Duration to capture in seconds (-1 to capture until manually stopped)
path String (optional) Optional file path to save the GIF (can also be specified in finish())

gif
finish(?path: String): haxe.io.Bytes

Finishes the GIF capture and saves the file.

Name Type Default Description
path String (optional) Optional file path to save the GIF (overrides path from captureScreen)
Returns Description
haxe.io.Bytes The encoded GIF data as bytes

gif
destroy(): Void

Cleans up resources and restores settings. Automatically stops capture if still running.


gif
new(): Void

Creates a new GIF capture instance.

Private Members

gif
screenFps: Int

Internal frame rate for screen capture


gif
gifFps: Int

Output GIF frame rate


gif
duration: Float

Duration to capture in seconds (-1 for manual stop)


gif
elapsed: Float

Elapsed capture time


gif
capturing: Bool

Whether currently capturing


gif
frameNumber: Int

Current frame number


gif
encoder: gif.GifEncoder

GIF encoder instance


Output stream for GIF data


gif
width: Int

Capture width in pixels


gif
height: Int

Capture height in pixels


gif
prevOverrideDelta: Float

Previous delta time override value


gif
pendingPath: String

Path to save the GIF file


gif
pendingPixelsList: Array<UInt8Array>

List of captured pixel buffers for blending


gif
mixedPixels: UInt8Array

Buffer for mixed/blended pixels


gif
middleFactor: Float

Blending factor for middle frames


gif
imagesPerFrame: Int

Number of screen captures per GIF frame


gif
emitFinish(): Void

Emitted when GIF capture has finished. Called after the file has been saved and encoding is complete.

Metadata

Name Parameters
:build ceramic.macros.EntityMacro.buildForCompletion()
:autoBuild ceramic.macros.EntityMacro.buildForCompletion()
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()