Skip to content

API / BaseFactory

Class: abstract BaseFactory ​

Defined in: factory/BaseFactory.ts:46

Base class for the factory that create the armatures. (Typically only one global factory instance is required) The factory instance create armatures by parsed and added DragonBonesData instances and TextureAtlasData instances. Once the data has been parsed, it has been cached in the factory instance and does not need to be parsed again until it is cleared by the factory instance.

Extended by ​

Constructors ​

Constructor ​

ts
new BaseFactory(dataParser: DataParser): BaseFactory;

Defined in: factory/BaseFactory.ts:65

Create a factory instance. (typically only one global factory instance is required)

Parameters ​

ParameterTypeDefault value
dataParserDataParsernull

Returns ​

BaseFactory

Accessors ​

clock ​

Get Signature ​

ts
get clock(): WorldClock;

Defined in: factory/BaseFactory.ts:933

An Worldclock instance updated by engine.

Returns ​

WorldClock

Methods ​

addDragonBonesData() ​

ts
addDragonBonesData(data: DragonBonesData, name: string): void;

Defined in: factory/BaseFactory.ts:462

Cache a DragonBonesData instance to the factory.

Parameters ​

ParameterTypeDefault valueDescription
dataDragonBonesDataundefinedThe DragonBonesData instance.
namestringnullSpecify a cache name for the instance so that the instance can be obtained through this name. (if not set, use the instance name instead)

Returns ​

void


addTextureAtlasData() ​

ts
addTextureAtlasData(data: TextureAtlasData, name: string): void;

Defined in: factory/BaseFactory.ts:535

Cache a TextureAtlasData instance to the factory.

Parameters ​

ParameterTypeDefault valueDescription
dataTextureAtlasDataundefinedThe TextureAtlasData instance.
namestringnullSpecify a cache name for the instance so that the instance can be obtained through this name. (if not set, use the instance name instead)

Returns ​

void


buildArmature() ​

ts
buildArmature(
   armatureName: string, 
   dragonBonesName: string, 
   skinName: string, 
   textureAtlasName: string): Armature;

Defined in: factory/BaseFactory.ts:651

Create a armature from cached DragonBonesData instances and TextureAtlasData instances. Note that when the created armature that is no longer in use, you need to explicitly dispose Armature#dispose().

Parameters ​

ParameterTypeDefault valueDescription
armatureNamestringundefinedThe armature data name.
dragonBonesNamestring""The cached name of the DragonBonesData instance. (If not set, all DragonBonesData instances are retrieved, and when multiple DragonBonesData instances contain a the same name armature data, it may not be possible to accurately create a specific armature)
skinNamestring""The skin name, you can set a different ArmatureData name to share it's skin data. (If not set, use the default skin data)
textureAtlasNamestring""-

Returns ​

Armature

The armature.

Example ​

ts
    let armature = factory.buildArmature("armatureName", "dragonBonesName");
    armature.clock = factory.clock;

clear() ​

ts
clear(disposeData: boolean): void;

Defined in: factory/BaseFactory.ts:603

Clear all cached DragonBonesData instances and TextureAtlasData instances.

Parameters ​

ParameterTypeDefault valueDescription
disposeDatabooleantrueWhether to dispose data.

Returns ​

void


getArmatureData() ​

ts
getArmatureData(name: string, dragonBonesName: string): ArmatureData;

Defined in: factory/BaseFactory.ts:585

Get a specific armature data.

Parameters ​

ParameterTypeDefault valueDescription
namestringundefinedThe armature data name.
dragonBonesNamestring""The cached name for DragonbonesData instance.

Returns ​

ArmatureData


getDragonBonesData() ​

ts
getDragonBonesData(name: string): DragonBonesData;

Defined in: factory/BaseFactory.ts:442

Get a specific DragonBonesData instance.

Parameters ​

ParameterTypeDescription
namestringThe DragonBonesData instance cache name.

Returns ​

DragonBonesData

DragonBonesData instance


getTextureAtlasData() ​

ts
getTextureAtlasData(name: string): TextureAtlasData[];

Defined in: factory/BaseFactory.ts:515

Get a list of specific TextureAtlasData instances.

Parameters ​

ParameterTypeDescription
namestringThe TextureAtlasData cahce name.

Returns ​

TextureAtlasData[]


parseDragonBonesData() ​

ts
parseDragonBonesData(
   rawData: any, 
   name: string, 
   scale: number): DragonBonesData;

Defined in: factory/BaseFactory.ts:347

Parse the raw data to a DragonBonesData instance and cache it to the factory.

Parameters ​

ParameterTypeDefault valueDescription
rawDataanyundefinedThe raw data.
namestringnullSpecify a cache name for the instance so that the instance can be obtained through this name. (If not set, use the instance name instead)
scalenumber1.0Specify a scaling value for all armatures. (Default: 1.0)

Returns ​

DragonBonesData

DragonBonesData instance


parseTextureAtlasData() ​

ts
parseTextureAtlasData(
   rawData: any, 
   textureAtlas: any, 
   name: string, 
   scale: number): TextureAtlasData;

Defined in: factory/BaseFactory.ts:394

Parse the raw texture atlas data and the texture atlas object to a TextureAtlasData instance and cache it to the factory.

Parameters ​

ParameterTypeDefault valueDescription
rawDataanyundefinedThe raw texture atlas data.
textureAtlasanyundefinedThe texture atlas object.
namestringnullSpecify a cache name for the instance so that the instance can be obtained through this name. (If not set, use the instance name instead)
scalenumber1.0Specify a scaling value for the map set. (Default: 1.0)

Returns ​

TextureAtlasData

TextureAtlasData instance


removeDragonBonesData() ​

ts
removeDragonBonesData(name: string, disposeData: boolean): void;

Defined in: factory/BaseFactory.ts:492

Remove a DragonBonesData instance.

Parameters ​

ParameterTypeDefault valueDescription
namestringundefinedThe DragonBonesData instance cache name.
disposeDatabooleantrueWhether to dispose data. (Default: true)

Returns ​

void


removeTextureAtlasData() ​

ts
removeTextureAtlasData(name: string, disposeData: boolean): void;

Defined in: factory/BaseFactory.ts:559

Remove a TextureAtlasData instance.

Parameters ​

ParameterTypeDefault valueDescription
namestringundefinedThe TextureAtlasData instance cache name.
disposeDatabooleantrueWhether to dispose data.

Returns ​

void


replaceAnimation() ​

ts
replaceAnimation(
   armature: Armature, 
   armatureData: ArmatureData, 
   isOverride: boolean): boolean;

Defined in: factory/BaseFactory.ts:868

Replaces the existing animation data for a specific armature with the animation data for the specific armature data. This enables you to make a armature template so that other armature without animations can share it's animations.

Parameters ​

ParameterTypeDefault valueDescription
armatureArmatureundefinedThe armtaure.
armatureDataArmatureDataundefinedThe armature data.
isOverridebooleantrueWhether to completely overwrite the original animation. (Default: false)

Returns ​

boolean

Example ​

ts
    let armatureA = factory.buildArmature("armatureA", "dragonBonesA");
    let armatureDataB = factory.getArmatureData("armatureB", "dragonBonesB");
    if (armatureDataB) {
    factory.replaceAnimation(armatureA, armatureDataB);
    }

replaceSkin() ​

ts
replaceSkin(
   armature: Armature, 
   skin: SkinData, 
   isOverride: boolean, 
   exclude: string[]): boolean;

Defined in: factory/BaseFactory.ts:799

Share specific skin data with specific armature.

Parameters ​

ParameterTypeDefault valueDescription
armatureArmatureundefinedThe armature.
skinSkinDataundefinedThe skin data.
isOverridebooleanfalseWhether it completely override the original skin. (Default: false)
excludestring[]nullA list of slot names that do not need to be replace.

Returns ​

boolean

Example ​

ts
    let armatureA = factory.buildArmature("armatureA", "dragonBonesA");
    let armatureDataB = factory.getArmatureData("armatureB", "dragonBonesB");
    if (armatureDataB && armatureDataB.defaultSkin) {
    factory.replaceSkin(armatureA, armatureDataB.defaultSkin, false, ["arm_l", "weapon_l"]);
    }

replaceSlotDisplay() ​

ts
replaceSlotDisplay(
   dragonBonesName: string, 
   armatureName: string, 
   slotName: string, 
   displayName: string, 
   slot: Slot, 
   displayIndex: number): boolean;

Defined in: factory/BaseFactory.ts:731

Replaces the current display data for a particular slot with a specific display data. Specify display data with "dragonBonesName/armatureName/slotName/displayName".

Parameters ​

ParameterTypeDefault valueDescription
dragonBonesNamestringundefinedThe DragonBonesData instance cache name.
armatureNamestringundefinedThe armature data name.
slotNamestringundefinedThe slot data name.
displayNamestringundefinedThe display data name.
slotSlotundefinedThe slot.
displayIndexnumber-1The index of the display data that is replaced. (If it is not set, replaces the current display data)

Returns ​

boolean

Example ​

ts
    let slot = armature.getSlot("weapon");
    factory.replaceSlotDisplay("dragonBonesName", "armatureName", "slotName", "displayName", slot);

updateTextureAtlases() ​

ts
updateTextureAtlases(textureAtlases: any[], name: string): void;

Defined in: factory/BaseFactory.ts:415

Update texture atlases.

Parameters ​

ParameterTypeDescription
textureAtlasesany[]The texture atlas objects.
namestringThe texture atlas name.

Returns ​

void

Released under the MIT License.