Skip to Content
defold-typescript libraries
defold (official)

defold/extension-camera

Provides functionality to capture images using the camera. Supported on macOS, iOS and Android.

  • GitHub: defold/extension-camera — pinned to 2.2.3 (released while Defold 1.13.1 was current)
    1. Pick a release from defold/extension-camera releases and add its Source code (zip) URL (or a packaged .zip asset, if the library ships one) to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Call it through the global camera — no import. It adds members to the engine camera namespace.

Functions

camera.start_capture(type: string, quality: string, callback: function)

Start camera capture using the specified camera (front/back) and capture quality. This may trigger a camera usage permission popup. When the popup has been dismissed the callback will be invoked with camera start status.

camera.start_capture(camera.CAMERA_TYPE_BACK, camera.CAPTURE_QUALITY_HIGH, function(self, message)
    if message == camera.CAMERA_STARTED then
        -- do stuff
    end
end)

Parameters

  • type: string — Which camera to use, font or back.
  • quality: string — Quality of the captured image.
  • callback: function — The function to call camera state has changed.

camera.stop_capture()

Stops a previously started capture session.

camera.stop_capture()

camera.get_info(): table

Gets the info from the current capture session.

local info = camera.get_info()
print("width", info.width)
print("height", info.height)

Returns

  • info: table — Information about the camera.

camera.get_frame(): buffer

Get captured frame.

self.cameraframe = camera.get_frame()

Returns

  • frame: buffer — Retrieves the camera pixel buffer. This buffer has one stream named "rgb", and is of type buffer.VALUE_TYPE_UINT8 and has the value count of 1.

Constants

camera.CAMERA_TYPE_FRONT

Constant for the front camera.

camera.CAMERA_TYPE_BACK

Constant for the back camera.

camera.CAPTURE_QUALITY_HIGH

High quality capture session.

camera.CAPTURE_QUALITY_MEDIUM

Medium quality capture session.

camera.CAPTURE_QUALITY_LOW

Low quality capture session.

camera.CAMERA_STARTED

The capture session has started.

camera.CAMERA_STOPPED

The capture session has stopped.

camera.CAMERA_NOT_PERMITTED

The user did not give permission to start the capture session.

camera.CAMERA_ERROR

Something went wrong when starting the capture session.

On this page