Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加useSharedTicker参数, 以及 静态的公共方法advanceTime(passedTime) #97

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions Pixi/4.x/src/dragonBones/pixi/PixiFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
Expand All @@ -38,6 +38,19 @@ namespace dragonBones {
private static _clockHandler(passedTime: number): void {
this._dragonBonesInstance.advanceTime(PIXI.ticker.shared.elapsedMS * passedTime * 0.001);
}

/*
* `passedTime` is elapsed time, specified in seconds.
*/
public static advanceTime(passedTime: number): void {
this._dragonBonesInstance.advanceTime(passedTime);
}

/*
* whether use `PIXI.ticker.shared`
*/
public static useSharedTicker: boolean = true;

/**
* - A global factory instance that can be used directly.
* @version DragonBones 4.7
Expand All @@ -50,21 +63,37 @@ namespace dragonBones {
*/
public static get factory(): PixiFactory {
if (PixiFactory._factory === null) {
PixiFactory._factory = new PixiFactory();
PixiFactory._factory = new PixiFactory(null, PixiFactory.useSharedTicker);
}

return PixiFactory._factory;
}

/**
* - 一个获取全局工厂实例(单例)的方法, 和get factory相比, 优点是可以传参数。
* @version DragonBones 4.7
* @language zh_CN
*/
public static newInstance(useSharedTicker = true): PixiFactory {
if (PixiFactory._factory === null) {
PixiFactory._factory = new PixiFactory(null, useSharedTicker);
}

return PixiFactory._factory;
}

/**
* @inheritDoc
*/
public constructor(dataParser: DataParser | null = null) {
public constructor(dataParser: DataParser | null = null, useSharedTicker = true) {
super(dataParser);

if (PixiFactory._dragonBonesInstance === null) {
const eventManager = new PixiArmatureDisplay();
PixiFactory._dragonBonesInstance = new DragonBones(eventManager);
PIXI.ticker.shared.add(PixiFactory._clockHandler, PixiFactory);
if (useSharedTicker) {
PIXI.ticker.shared.add(PixiFactory._clockHandler, PixiFactory);
}
}

this._dragonBones = PixiFactory._dragonBonesInstance;
Expand Down Expand Up @@ -182,4 +211,4 @@ namespace dragonBones {
return this._dragonBones.eventManager as PixiArmatureDisplay;
}
}
}
}