From 38c8d82f0d50ac4da29b9b373ec7a42306fe9d1d Mon Sep 17 00:00:00 2001 From: finscn Date: Thu, 4 Apr 2019 00:42:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0`useSharedTicker`?= =?UTF-8?q?=E5=8F=82=E6=95=B0,=20=E4=BB=A5=E5=8F=8A=20=E9=9D=99=E6=80=81?= =?UTF-8?q?=E7=9A=84=E5=85=AC=E5=85=B1=E6=96=B9=E6=B3=95`advanceTime(passe?= =?UTF-8?q?dTime)`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 其实在实际项目中, 大多数 Pixi的用户 并不会使用 PIXI.ticker.shared , 而且 PIXI的ticker设计的并不好. 所以 这个PR 为DragonBonesJS pixi版本增加了 是否使用 PIXI.ticker.shared 的参数. 参数默认值 是 true, 所以这个改变并不会影响现有的项目. 用法: ``` dragonBones.PixiFactory.useSharedTicker = false; var factory = dragonBones.PixiFactory.factory; // 此时 不会使用 PIXI.ticker.shared // 用户可以在 自己的 game loop 函数里使用 下面的方法来更新动画 dragonBones.PixiFactory.advanceTime(passedTime); ``` --- Pixi/4.x/src/dragonBones/pixi/PixiFactory.ts | 27 +++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Pixi/4.x/src/dragonBones/pixi/PixiFactory.ts b/Pixi/4.x/src/dragonBones/pixi/PixiFactory.ts index 43713b45..f8b02d5e 100644 --- a/Pixi/4.x/src/dragonBones/pixi/PixiFactory.ts +++ b/Pixi/4.x/src/dragonBones/pixi/PixiFactory.ts @@ -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 @@ -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 @@ -50,7 +63,7 @@ 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; @@ -58,13 +71,15 @@ namespace dragonBones { /** * @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; @@ -182,4 +197,4 @@ namespace dragonBones { return this._dragonBones.eventManager as PixiArmatureDisplay; } } -} \ No newline at end of file +} From 6d9199826dab87773de215a1b704e43dfcf10731 Mon Sep 17 00:00:00 2001 From: finscn Date: Thu, 4 Apr 2019 00:48:06 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20newInstance=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Pixi/4.x/src/dragonBones/pixi/PixiFactory.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Pixi/4.x/src/dragonBones/pixi/PixiFactory.ts b/Pixi/4.x/src/dragonBones/pixi/PixiFactory.ts index f8b02d5e..afcd4565 100644 --- a/Pixi/4.x/src/dragonBones/pixi/PixiFactory.ts +++ b/Pixi/4.x/src/dragonBones/pixi/PixiFactory.ts @@ -68,6 +68,20 @@ namespace dragonBones { 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 */