Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SpriteFrame

精灵帧资源。 一个 SpriteFrame 包含:

  • 纹理:会被渲染组件使用的 Texture2D 对象。
  • 矩形:在纹理中的矩形区域。 可通过 cc.SpriteFrame 获取该组件。
example
// First way to use a SpriteFrame
const url = "assets/PurpleMonster/icon/spriteFrame";
cc.loader.loadRes(url, (err, spriteFrame) => {
  const node = new Node("New Sprite");
  const sprite = node.addComponent(SpriteComponent);
  sprite.spriteFrame = spriteFrame;
  node.parent = self.node;
});
// Second way to use a SpriteFrame
const self = this;
const url = "test_assets/PurpleMonster";
cc.loader.loadRes(url, (err, imageAsset) => {
 if(err){
   return;
 }
 const node = new Node("New Sprite");
 const sprite = node.addComponent(SpriteComponent);
 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(CameraComponent);
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

Implements

Index

Constructors

constructor

Properties

Protected _atlasUuid

_atlasUuid: string = ""

_callbackTable

_callbackTable: any = createMap(true)

IEventTarget 实现,它们将被 applyMixins 在 EventTarget 中用相同的实现覆盖

Protected _capInsets

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

Protected _flipUv

_flipUv: boolean = false

Protected _name

_name: string

_native

_native: string = ""

用于本机资产的可序列化URL。供内部使用。

default

""

_objFlags

_objFlags: number

Protected _offset

_offset: Vec2 = new Vec2()

Protected _originalSize

_originalSize: Size = new Size()

Protected _rect

_rect: Rect = new Rect()

Protected _rotated

_rotated: boolean = false

Protected _texture

_texture: TextureBase

_uuid

_uuid: string

内部使用。

loaded

loaded: boolean = true

该资源是否已经成功加载。

uv

uv: number[] = []

不带裁切的 UV。

uvHash

uvHash: number = 0

uvSliced

uvSliced: IUV[] = []

带有裁切的 UV。

vertices

vertices: IVertices | null = null

Static preventDeferredLoadDependents

preventDeferredLoadDependents: boolean = false

当场景或 Prefab 被标记为 asyncLoadAssets,禁止延迟加载该资源所依赖的其它 RawAsset。

property

{Boolean} preventDeferredLoadDependents

default

false

static

Static preventPreloadNativeObject

preventPreloadNativeObject: boolean = false

禁止预加载原生对象。

property

{Boolean} preventPreloadNativeObject

default

false

static

Accessors

Private nativeAsset

  • get nativeAsset(): any
  • set nativeAsset(obj: any): void

textureSource

atlasUuid

  • get atlasUuid(): string
  • set atlasUuid(value: string): 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

isValid

  • get isValid(): boolean
  • 表示该对象是否可用(被 destroy 后将不可用)。
    当一个对象的 destroy 调用以后,会在这一帧结束后才真正销毁。
    因此从下一帧开始 isValid 就会返回 false,而当前帧内 isValid 仍然会是 true。
    如果希望判断当前帧是否调用过 destroy,请使用 cc.isValid(obj, true),不过这往往是特殊的业务需求引起的,通常情况下不需要这样。

    property

    {Boolean} isValid

    default

    true

    readonly
    example
    import * as cc from 'cc';
    var node = new cc.Node();
    cc.log(node.isValid);    // true
    node.destroy();
    cc.log(node.isValid);    // true, still valid in this frame
    // after a frame...
    cc.log(node.isValid);    // false, destroyed in the end of last frame

    Returns boolean

name

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

nativeUrl

  • get nativeUrl(): string
  • 返回该资源对应的目标平台资源的 URL,如果没有将返回一个空字符串。

    property

    nativeUrl

    type

    {String}

    readonly

    Returns string

offset

  • get offset(): Vec2
  • set offset(value: Vec2): void

originalSize

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

rect

  • get rect(): Rect
  • set rect(value: Rect): void

rotated

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

texture

width

  • get width(): number

Methods

calculateSlicedUV

  • _calculateSlicedUV(): void

calculateUV

  • _calculateUV(): void

deserialize

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

destroyImmediate

  • _destroyImmediate(): void

destruct

  • _destruct(): void
  • Clear all references in the instance.

    NOTE: this method will not clear the getter or setter functions which defined in the instance of CCObject. You can override the _destruct method if you need, for example: _destruct: function () { for (var key in this) { if (this.hasOwnProperty(key)) { switch (typeof this[key]) { case 'string': this[key] = ''; break; case 'object': case 'function': this[key] = null; break; } } }

    Returns void

Protected refreshTexture

serialize

  • serialize(exporting?: any): any

Private setRawAsset

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

Protected textureLoaded

  • _textureLoaded(): void

checkRect

Optional createNode

destroy

  • destroy(): boolean

dispatchEvent

  • dispatchEvent(event: Event): void

emit

  • emit(key: string, ...args: any[]): void

getGFXSampler

getGFXTextureView

getOffset

getOriginalSize

getRect

  • 获取 SpriteFrame 的纹理矩形区域。 如果是一个 atlas 的贴图,则为当前贴图的实际剔除透明像素区域。

    deprecated

    即将在 1.2 废除,请使用 rect.set(spritFrame.rect)

    Parameters

    • Optional out: Rect

    Returns Rect

hasEventListener

  • hasEventListener(key: string, callback?: Function | undefined, target?: Object | undefined): boolean

isRotated

  • isRotated(): boolean

off

  • off(type: string, callback?: Function | undefined, target?: Object | undefined): void

on

  • on(type: string, callback: Function, target?: Object | undefined): Function | undefined

onLoaded

  • onLoaded(): void

once

  • once(type: string, callback: Function, target?: Object | undefined): Function | undefined

removeAll

  • removeAll(keyOrTarget?: string | Object | undefined): void

reset

Private serialize

  • serialize(): void

setOffset

  • setOffset(offset: Vec2): void

setOriginalSize

  • setOriginalSize(size: Size): void
  • 设置修剪前的原始大小。

    deprecated

    即将在 1.2 废除,请使用 spritFrame.originalSize = size

    Parameters

    • size: Size

      设置精灵原始大小。

    Returns void

setRect

  • setRect(rect: Rect): void

setRotated

  • setRotated(rotated: boolean): void
  • 设置 SpriteFrame 是否旋转。

    deprecated

    即将在 1.2 废除,请使用 rect.rotated = true

    Parameters

    • rotated: boolean

    Returns void

targetOff

  • targetOff(keyOrTarget?: string | Object | undefined): void

textureLoaded

  • textureLoaded(): boolean

toString

  • toString(): string
  • 返回对象的字符串表示形式。
    Asset 对象将会重写 Object 对象的 toString() 方法。
    当资源要表示为文本值时或在字符串连接时引用时,
    JavaScript 会自动调用 toString() 方法。

    对于原始类型的资源,它将返回this.nativeUrl
    否则,返回空字符串。
    子类可能会覆盖此方法。

    method

    toString

    Returns string

Static deferredDestroy

  • _deferredDestroy(): void

Static deserialize

  • deserialize(data: any): any

Static isRawAssetType

  • isRawAssetType(ctor: Function): boolean

Generated using TypeDoc