Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SpriteFrame

A SpriteFrame support several types

  1. Rectangle sprite frame
  2. Sliced 9 sprite frame
  3. Mesh sprite frame It mainly contains:
  • texture: A TextureBase or RenderTexture that will be used by render process
  • rectangle: A rectangle of the texture
  • Sliced 9 border insets: The distance of each side from the internal rect to the sprite frame rect
  • vertices: Vertex list for the mesh type sprite frame
  • uv: The quad uv
  • uvSliced: The sliced 9 uv
example
import { resources } from 'cc';
// First way to use a SpriteFrame
const url = "assets/PurpleMonster/icon/spriteFrame";
resources.load(url, (err, spriteFrame) => {
  const node = new Node("New Sprite");
  const sprite = node.addComponent(Sprite);
  sprite.spriteFrame = spriteFrame;
  node.parent = self.node;
});
// Second way to use a SpriteFrame
const self = this;
const url = "test_assets/PurpleMonster";
resources.load(url, (err, imageAsset) => {
 if(err){
   return;
 }
 const node = new Node("New Sprite");
 const sprite = node.addComponent(Sprite);
 const spriteFrame = new SpriteFrame();
 const tex = imageAsset._texture;
 spriteFrame.texture = tex;
 sprite.spriteFrame = spriteFrame;
 node.parent = self.node;
});
// Third way to use a SpriteFrame
const self = this;
const cameraComp = this.getComponent(Camera);
const renderTexture = new RenderTexture();
rendetTex.reset({
  width: 512,
  height: 512,
  depthStencilFormat: RenderTexture.DepthStencilFormat.DEPTH_24_STENCIL_8
});
cameraComp.targetTexture = renderTexture;
const spriteFrame = new SpriteFrame();
spriteFrame.texture = renderTexture;

Hierarchy

Index

Constructors

constructor

Properties

__asyncLoadAssets__

__asyncLoadAssets__: boolean = false

__depends__

__depends__: any = null

__nativeDepend__

__nativeDepend__: any = null

__onLoadedInvoked__

__onLoadedInvoked__: boolean = false

Protected _atlasUuid

_atlasUuid: string = ""

Protected _capInsets

_capInsets: number[] = [0, 0, 0, 0]

Protected _isFlipUVX

_isFlipUVX: boolean = false

Protected _isFlipUVY

_isFlipUVY: boolean = false

_native

_native: string = ""

Serializable url for native asset. For internal usage.

default

""

_nativeUrl

_nativeUrl: string = ""

Protected _offset

_offset: Vec2 = new Vec2()

Protected original

original: { _texture: TextureBase | RenderTexture; _x: number; _y: number } | null = null

Protected _originalSize

_originalSize: Size = new Size()

Protected _packable

_packable: boolean = true

Protected _rect

_rect: Rect = new Rect()

Protected _rotated

_rotated: boolean = false

Protected _texture

_uuid

_uuid: string

loaded

loaded: boolean = true

Whether the asset is loaded or not

unbiasUV

unbiasUV: number[] = []

uv

uv: number[] = []

UV for quad vertices

uvHash

uvHash: number = 0

uvSliced

uvSliced: IUV[] = []

UV for sliced 9 vertices

vertices

vertices: IVertices | null = null

Vertex list for the mesh type sprite frame

Static preventDeferredLoadDependents

preventDeferredLoadDependents: boolean = false

Indicates whether its dependent native assets can support deferred load if the owner scene (or prefab) is marked as asyncLoadAssets.

default

false

Static preventPreloadNativeObject

preventPreloadNativeObject: boolean = false

Indicates whether its native object should be preloaded from native url.

default

false

Accessors

Private nativeAsset

  • get nativeAsset(): any
  • set nativeAsset(obj: any): void
  • The underlying native asset of this asset if one is available.
    This property can be used to access additional details or functionality releated to the asset.
    This property will be initialized by the loader if _native is available.

    default

    null

    Returns any

  • The underlying native asset of this asset if one is available.
    This property can be used to access additional details or functionality releated to the asset.
    This property will be initialized by the loader if _native is available.

    default

    null

    Parameters

    • obj: any

    Returns void

nativeDep

  • get nativeDep(): undefined | { __isNative__: boolean; ext: string; uuid: string }

textureSource

atlasUuid

  • get atlasUuid(): string
  • set atlasUuid(value: string): void

flipUVX

  • get flipUVX(): boolean
  • set flipUVX(value: boolean): void

flipUVY

  • get flipUVY(): boolean
  • set flipUVY(value: boolean): void

height

  • get height(): number

insetBottom

  • get insetBottom(): number
  • set insetBottom(value: number): void

insetLeft

  • get insetLeft(): number
  • set insetLeft(value: number): void

insetRight

  • get insetRight(): number
  • set insetRight(value: number): void

insetTop

  • get insetTop(): number
  • set insetTop(value: number): void

nativeUrl

  • get nativeUrl(): string

offset

  • get offset(): Vec2
  • set offset(value: Vec2): void
  • The offset of the sprite frame center. Sprite frame in an atlas texture could be trimmed for clipping the transparent pixels, so the trimmed rect is smaller than the original one, the offset defines the distance from the original center to the trimmed center.

    Returns Vec2

  • The offset of the sprite frame center. Sprite frame in an atlas texture could be trimmed for clipping the transparent pixels, so the trimmed rect is smaller than the original one, the offset defines the distance from the original center to the trimmed center.

    Parameters

    Returns void

original

originalSize

  • get originalSize(): Size
  • set originalSize(value: Size): void

packable

  • get packable(): boolean
  • set packable(value: boolean): void

rect

  • get rect(): Rect
  • set rect(value: Rect): void
  • Returns the rect of the sprite frame in the texture. If it's an atlas texture, a transparent pixel area is proposed for the actual mapping of the current texture.

    Returns Rect

  • Returns the rect of the sprite frame in the texture. If it's an atlas texture, a transparent pixel area is proposed for the actual mapping of the current texture.

    Parameters

    Returns void

refCount

  • get refCount(): number

rotated

  • get rotated(): boolean
  • set rotated(rotated: boolean): void

texture

width

  • get width(): number

Methods

calculateSlicedUV

  • _calculateSlicedUV(): void

calculateUV

  • _calculateUV(): void

checkPackable

  • _checkPackable(): void

deserialize

  • deserialize(serializeData: any, handle: any): void

Protected refreshTexture

resetDynamicAtlasFrame

  • _resetDynamicAtlasFrame(): void

serialize

  • serialize(ctxForExporting: any): any

setDynamicAtlasFrame

  • setDynamicAtlasFrame(frame: any): void

Private setRawAsset

  • setRawAsset(filename: string, inLibrary?: boolean): void

Protected textureLoaded

  • _textureLoaded(): void

addRef

checkRect

clone

Optional createNode

decRef

  • decRef(autoRelease?: boolean): Asset

destroy

  • destroy(): any

getGFXSampler

getGFXTexture

getHash

  • getHash(): number

getOffset

getOriginalSize

getRect

  • Returns the rect of the sprite frame in the texture. If it's an atlas texture, a transparent pixel area is proposed for the actual mapping of the current texture.

    deprecated

    since v1.2, please use rect

    Parameters

    • Optional out: Rect

    Returns Rect

getSamplerHash

  • getSamplerHash(): number

isRotated

  • isRotated(): boolean

onLoaded

  • onLoaded(): void

reset

Private serialize

  • serialize(): void

setOffset

  • setOffset(offset: Vec2): void

setOriginalSize

  • setOriginalSize(size: Size): void

setRect

  • setRect(rect: Rect): void

setRotated

  • setRotated(rotated: boolean): void

textureLoaded

  • textureLoaded(): boolean

toString

  • toString(): string
  • Returns the string representation of the object.
    The Asset object overrides the toString() method of the Object object.
    JavaScript calls the toString() method automatically
    when an asset is to be represented as a text value or when a texture is referred to in a string concatenation.

    For assets of the native type, it will return this.nativeUrl.
    Otherwise, an empty string is returned.
    This method may be overwritten by subclasses.

    method

    toString

    Returns string

Static createWithImage

Static deserialize

  • deserialize(data: any): any

Generated using TypeDoc