Two.Image

Extends: Two.Rectangle

A convenient package to display images scaled to fit specific dimensions. Unlike Two.Sprite, this class scales the image to the provided width and height rather than using the image's native dimensions. By default, images are scaled to 'fill' within the bounds while preserving aspect ratio.

Constructor

ArgumentDescription
srcThe URL path or Two.Texture to be used as the bitmap data displayed on the image.
oxThe initial x position of the Two.Image.
oyThe initial y position of the Two.Image.
widthThe width to display the image at.
heightThe height to display the image at.
modeThe fill mode

Modes

Different mode types to render an image inspired by Figma.

Modes.fill: Scale image to fill the bounds while preserving aspect ratio.

Modes.fit: Scale image to fit within bounds while preserving aspect ratio.

Modes.crop: Scale image to fill bounds while preserving aspect ratio, cropping excess.

Modes.tile: Repeat image at original size to fill the bounds.

Modes.stretch: Stretch image to fill dimensions, ignoring aspect ratio.

Properties

A list of properties that are on every Two.Image.

fromObject

Returns: Two.Image

ArgumentDescription
objObject notation of a Two.Image to create a new instance

Create a new Two.Image from an object notation of a Two.Image.

nota-bene

Works in conjunction with Two.Image.toObject

texture

The texture to be used as bitmap data to display image in the scene.

copy

ArgumentDescription
imageThe reference Two.Image

Copy the properties of one Two.Image onto another.

clone

Returns: Two.Image

ArgumentDescription
parentThe parent group or scene to add the clone to.

Create a new instance of Two.Image with the same properties of the current image.

toObject

Returns: Object

Return a JSON compatible plain object that represents the image.

dispose

Returns: Two.Image

Release the image's renderer resources and detach all events. This method disposes the texture (calling dispose() for thorough cleanup) and inherits comprehensive cleanup from the Rectangle/Path hierarchy while preserving the renderer type for potential re-attachment.