@safe-engine/cocos 2.1.9 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,15 @@
1
- export declare const SharedDragonBonesManager: {
2
- isLoaded: boolean;
3
- factory: any;
4
- assets: {};
5
- loadAssetsOnce: (key: any, texJsonUrl: any, texPngUrl: any) => void;
6
- buildArmatureDisplay: (key: any) => any;
7
- };
8
- export declare const PixiDragonBonesSprite: any;
1
+ import { PixiArmatureDisplay } from 'dragonbones-pixijs';
2
+ import { Application } from 'pixi.js';
3
+ export declare function loadDragonBonesAssets(skeleton: any, atlas: any, texture: any): Promise<any>;
4
+ export declare class PixiDragonBonesSprite extends cc.Sprite {
5
+ _canvas: any;
6
+ _pixiApp: Application;
7
+ _texture: cc.Texture2D;
8
+ _config: any;
9
+ _armatureDisplay: PixiArmatureDisplay;
10
+ constructor(config: any);
11
+ _setupArmature(): void;
12
+ updateTexture(): void;
13
+ onExit(): void;
14
+ }
9
15
  //# sourceMappingURL=PixiDragonBonesSprite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PixiDragonBonesSprite.d.ts","sourceRoot":"","sources":["../../src/dragonbones/PixiDragonBonesSprite.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB;;;;;;CA8BpC,CAAA;AAED,eAAO,MAAM,qBAAqB,EAAE,GA+DlC,CAAA"}
1
+ {"version":3,"file":"PixiDragonBonesSprite.d.ts","sourceRoot":"","sources":["../../src/dragonbones/PixiDragonBonesSprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAe,MAAM,oBAAoB,CAAA;AACrE,OAAO,EAAE,WAAW,EAAU,MAAM,SAAS,CAAA;AAE7C,wBAAgB,qBAAqB,CAAC,QAAQ,KAAA,EAAE,KAAK,KAAA,EAAE,OAAO,KAAA,gBAE7D;AACD,qBAAa,qBAAsB,SAAQ,EAAE,CAAC,MAAM;IAClD,OAAO,EAAE,GAAG,CAAA;IACZ,QAAQ,EAAE,WAAW,CAAA;IACrB,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAA;IACtB,OAAO,MAAA;IACP,gBAAgB,EAAE,mBAAmB,CAAA;gBACzB,MAAM,KAAA;IA+BlB,cAAc;IAsBd,aAAa;IASb,MAAM;CAMP"}
@@ -1,44 +1,27 @@
1
- export const SharedDragonBonesManager = {
2
- isLoaded: false,
3
- factory: dragonBones.PixiFactory.factory,
4
- assets: {},
5
- loadAssetsOnce: function (key, texJsonUrl, texPngUrl) {
6
- if (this.assets[key]) {
7
- return;
8
- }
9
- const loader = new PIXI.Loader();
10
- loader
11
- .add(`ske${key}`, key)
12
- .add(`texJson${key}`, texJsonUrl)
13
- .add(`texPng${key}`, texPngUrl)
14
- .load((loader, resources) => {
15
- const dragonData = this.factory.parseDragonBonesData(resources[`ske${key}`].data, key);
16
- this.factory.parseTextureAtlasData(resources[`texJson${key}`].data, resources[`texPng${key}`].texture, key);
17
- this.assets[key] = {
18
- dragonData,
19
- texture: resources[`texPng${key}`].texture,
20
- };
21
- });
22
- },
23
- buildArmatureDisplay: function (key) {
24
- // console.log(this.assets[key])
25
- const { armatureNames } = this.assets[key].dragonData;
26
- const armatureName = armatureNames[0];
27
- return this.factory.buildArmatureDisplay(armatureName, key);
28
- },
29
- };
30
- export const PixiDragonBonesSprite = cc.Sprite.extend({
31
- ctor: function (config) {
32
- this._super();
1
+ import { PixiFactory } from 'dragonbones-pixijs';
2
+ import { Application, Assets } from 'pixi.js';
3
+ export function loadDragonBonesAssets(skeleton, atlas, texture) {
4
+ return Assets.load([skeleton, atlas, texture]);
5
+ }
6
+ export class PixiDragonBonesSprite extends cc.Sprite {
7
+ _canvas;
8
+ _pixiApp;
9
+ _texture;
10
+ _config;
11
+ _armatureDisplay;
12
+ constructor(config) {
13
+ super();
14
+ super.ctor(); // always call this for compatibility with cocos2dx JS Javascript class system
33
15
  this._canvas = document.createElement('canvas');
34
16
  this._canvas.width = config.width || 1024;
35
17
  this._canvas.height = config.height || 1024;
36
- this._pixiApp = new PIXI.Application({
18
+ this._pixiApp = new Application();
19
+ this._pixiApp.init({
37
20
  view: this._canvas,
38
21
  width: this._canvas.width,
39
22
  height: this._canvas.height,
40
23
  backgroundAlpha: 0, // nền trong suốt
41
- transparent: true, // bắt buộc để alpha hoạt động
24
+ // transparent: true, // bắt buộc để alpha hoạt động
42
25
  clearBeforeRender: true, // xoá trước khi vẽ frame mới
43
26
  preserveDrawingBuffer: true, // giúp lấy ảnh từ canvas
44
27
  antialias: true,
@@ -51,32 +34,38 @@ export const PixiDragonBonesSprite = cc.Sprite.extend({
51
34
  this._armatureDisplay = null;
52
35
  this._setupArmature();
53
36
  // this.schedule(this.updateTexture, 1 / 30);
54
- },
55
- _setupArmature: function () {
56
- const display = SharedDragonBonesManager.buildArmatureDisplay(this._config.ske);
37
+ }
38
+ _setupArmature() {
39
+ const { key, skeleton, atlas, texture, playTimes, animationName, scale = 1 } = this._config;
40
+ const factory = PixiFactory.factory;
41
+ const dragonData = factory.parseDragonBonesData(Assets.get(skeleton), key);
42
+ factory.parseTextureAtlasData(Assets.get(atlas), Assets.get(texture), key);
43
+ const { armatureNames } = dragonData;
44
+ const armatureName = armatureNames[0];
45
+ const display = factory.buildArmatureDisplay(armatureName, key);
57
46
  if (!display) {
58
- console.error('Không thể build armature:', this._config.armatureName);
47
+ console.error('Cannot build armature:', armatureName);
59
48
  return;
60
49
  }
61
- display.animation.play(this._config.animationName, 0, this._config.playTimes);
50
+ display.animation.play(animationName, playTimes);
62
51
  display.x = this._canvas.width / 2;
63
52
  display.y = this._canvas.height / 2;
64
- display.scale.set(this._config.scale || 1);
53
+ display.scale.set(scale);
65
54
  this._pixiApp.stage.addChild(display);
66
55
  this._armatureDisplay = display;
67
- },
68
- updateTexture: function () {
69
- if (this._armatureDisplay) {
56
+ }
57
+ updateTexture() {
58
+ if (this._armatureDisplay && this._pixiApp.renderer) {
70
59
  this._pixiApp.renderer.render(this._pixiApp.stage);
71
60
  this._texture.initWithElement(this._canvas);
72
61
  this._texture.handleLoadedTexture();
73
62
  this.setTexture(this._texture);
74
63
  }
75
- },
76
- onExit: function () {
64
+ }
65
+ onExit() {
77
66
  // this.unschedule(this.updateTexture);
78
67
  this._pixiApp.destroy(true, { children: true });
79
68
  this._canvas.remove();
80
- this._super();
81
- },
82
- });
69
+ super.onExit();
70
+ }
71
+ }
@@ -1,6 +1,8 @@
1
+ import { PixiArmatureDisplay } from 'dragonbones-pixijs';
1
2
  import { EntityManager, EventManager, System } from 'entityx-ts';
2
3
  import { ComponentX } from '../core/decorator';
3
4
  import { BaseComponentProps } from '../safex';
5
+ import { PixiDragonBonesSprite } from './PixiDragonBonesSprite';
4
6
  export type DragonBonesEventData = {
5
7
  name: string;
6
8
  };
@@ -19,25 +21,10 @@ interface DragonBonesProps {
19
21
  onAnimationEnd?: () => void;
20
22
  onAnimationComplete?: () => void;
21
23
  }
22
- interface PixiDragonBonesAnimation {
23
- lastAnimationName: string;
24
- gotoAndPlayByTime: (name: string, index?: number, playTimes?: number) => void;
25
- play: (name: string, index?: number, playTimes?: number) => void;
26
- timeScale: Float;
27
- }
28
- interface PixiDragonBonesArmature {
29
- animation: PixiDragonBonesAnimation;
30
- _armature: {
31
- flipX: boolean;
32
- };
33
- removeDBEventListener: () => void;
34
- addDBEventListener: (name: string, cb: (event: any) => void, target: any) => void;
35
- }
36
- export declare class DragonBonesComp extends ComponentX<DragonBonesProps & BaseComponentProps<DragonBonesComp>, cc.Node> {
37
- armature: PixiDragonBonesArmature;
38
- dragon: any;
24
+ export declare class DragonBonesComp extends ComponentX<DragonBonesProps & BaseComponentProps<DragonBonesComp>, PixiDragonBonesSprite> {
25
+ armature: PixiArmatureDisplay;
39
26
  setAnimation(name: string, playTimes?: number): void;
40
- getAnimationName(): string;
27
+ getAnimationName(): any;
41
28
  setFLipX(isFlipX: boolean): void;
42
29
  setTimeScale(timeScale: Float): void;
43
30
  }
@@ -1 +1 @@
1
- {"version":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gB;IACxB,IAAI,EAAE,eAAe,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,SAAS,CAAC,EAAE,KAAK,CAAA;IAEjB,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAA;IAC7B,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;IAC3B,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAA;CACjC;AAED,qBAAa,eAAgB,SAAQ,UAAU,CAAC,gBAAgB,GAAG,kBAAkB,CAAC,eAAe,CAAC,EAAE,qBAAqB,CAAC;IAC5H,QAAQ,EAAE,mBAAmB,CAAA;IAE7B,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,SAAI;IAOxC,gBAAgB;IAShB,QAAQ,CAAC,OAAO,EAAE,OAAO;IAIzB,YAAY,CAAC,SAAS,EAAE,KAAK;CAG9B;AAED,qBAAa,iBAAkB,YAAW,MAAM;IAC9C,SAAS,CAAC,aAAa,EAAE,YAAY;IAmDrC,MAAM,CAAC,QAAQ,EAAE,aAAa;CAU/B;AAED,wBAAgB,gBAAgB,SAE/B;AAED,cAAc,yBAAyB,CAAA"}
@@ -5,7 +5,6 @@ import { GameWorld } from '../gworld';
5
5
  import { PixiDragonBonesSprite } from './PixiDragonBonesSprite';
6
6
  export class DragonBonesComp extends ComponentX {
7
7
  armature;
8
- dragon;
9
8
  setAnimation(name, playTimes = 0) {
10
9
  if (this.armature) {
11
10
  if (this.armature.animation.lastAnimationName === name)
@@ -30,29 +29,23 @@ export class DragonBonesComp extends ComponentX {
30
29
  }
31
30
  export class DragonBonesSystem {
32
31
  configure(event_manager) {
33
- event_manager.subscribe(EventTypes.ComponentAdded, DragonBonesComp, ({ entity }) => {
32
+ event_manager.subscribe(EventTypes.ComponentAdded, DragonBonesComp, async ({ entity }) => {
34
33
  const dbComp = entity.getComponent(DragonBonesComp);
35
34
  const { data, animation, playTimes = 0, timeScale = 1 } = dbComp.props;
36
35
  const { atlas, skeleton, texture } = data;
37
36
  const dragon = new PixiDragonBonesSprite({
38
- ske: skeleton,
39
- texJson: atlas,
40
- texPng: texture,
37
+ skeleton,
38
+ atlas,
39
+ texture,
41
40
  animationName: animation,
42
41
  playTimes,
43
42
  // width: dataSkel.armature[0].aabb.width,
44
43
  // height: dataSkel.armature[0].aabb.height,
45
44
  });
46
- dbComp.dragon = dragon;
47
45
  dbComp.armature = dragon._armatureDisplay;
48
- const node = new cc.Node();
49
- node.addChild(dragon);
50
46
  // console.log('armature', dbComp.armature)
51
47
  dbComp.armature.animation.timeScale = timeScale;
52
- // if (skin) {
53
- // node.setSkin(skin)
54
- // }
55
- dbComp.node = entity.assign(new NodeComp(node, entity));
48
+ dbComp.node = entity.assign(new NodeComp(dragon, entity));
56
49
  if (dbComp.props.onAnimationStart)
57
50
  dbComp.armature.addDBEventListener(dragonBones.EventObject.START, () => {
58
51
  if (dbComp.node.active && dbComp.enabled)
@@ -79,11 +72,10 @@ export class DragonBonesSystem {
79
72
  update(entities) {
80
73
  // console.log('update', dt)
81
74
  const animations = entities.entities_with_components(DragonBonesComp);
82
- // cc.log(animations);
83
75
  animations.forEach((ett) => {
84
76
  const dbComp = ett.getComponent(DragonBonesComp);
85
77
  if (dbComp.node && dbComp.node.active) {
86
- dbComp.dragon.updateTexture();
78
+ dbComp.node.instance.updateTexture();
87
79
  }
88
80
  });
89
81
  }
@@ -4,17 +4,8 @@ import { BaseComponentProps, ColorSource } from '../safex';
4
4
  export declare class NodeRender extends ComponentX {
5
5
  nodeName: string;
6
6
  }
7
- declare enum SpriteTypes {
8
- SIMPLE = 0,
9
- SLICED = 1,
10
- TILED = 2,
11
- FILLED = 3,
12
- MESH = 4,
13
- ANIMATION = 5
14
- }
15
7
  interface SpriteRenderProps {
16
8
  spriteFrame: string;
17
- type?: SpriteTypes;
18
9
  capInsets?: [number, number, number, number];
19
10
  tiledSize?: Size;
20
11
  }
@@ -62,8 +53,8 @@ interface MotionStreakProps {
62
53
  stroke?: number;
63
54
  color?: Color4B;
64
55
  }
65
- export declare class MotionStreak extends ComponentX<MotionStreakProps & {
66
- $ref?: MotionStreak;
56
+ export declare class MotionStreakComp extends ComponentX<MotionStreakProps & {
57
+ $ref?: MotionStreakComp;
67
58
  }, cc.MotionStreak> {
68
59
  reset(): void;
69
60
  }
@@ -1 +1 @@
1
- {"version":3,"file":"RenderComponent.d.ts","sourceRoot":"","sources":["../../src/render/RenderComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAU,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAE1D,qBAAa,UAAW,SAAQ,UAAU;IACxC,QAAQ,EAAE,MAAM,CAAA;CACjB;AACD,aAAK,WAAW;IACd,MAAM,IAAA;IACN,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,IAAI,IAAA;IACJ,SAAS,IAAA;CACV;AACD,UAAU,iBAAiB;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5C,SAAS,CAAC,EAAE,IAAI,CAAA;CACjB;AAED,qBAAa,YAAa,SAAQ,UAAU,CAAC,iBAAiB,GAAG,kBAAkB,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC;IAC3G,IAAI,WAAW,WAEd;IAED,IAAI,WAAW,CAAC,KAAK,QAAA,EAKpB;IACD,WAAW;CAGZ;AACD,UAAU,eAAe;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC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WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AACD,qBAAa,gBAAiB,SAAQ,UAAU,CAAC,iBAAiB,GAAG;IAAE,IAAI,CAAC,EAAE,gBAAgB,CAAA;CAAE,EAAE,EAAE,CAAC,YAAY,CAAC;IAChH,KAAK;CAGN"}
@@ -2,15 +2,6 @@ import { ComponentX, render } from '../core/decorator';
2
2
  export class NodeRender extends ComponentX {
3
3
  nodeName;
4
4
  }
5
- var SpriteTypes;
6
- (function (SpriteTypes) {
7
- SpriteTypes[SpriteTypes["SIMPLE"] = 0] = "SIMPLE";
8
- SpriteTypes[SpriteTypes["SLICED"] = 1] = "SLICED";
9
- SpriteTypes[SpriteTypes["TILED"] = 2] = "TILED";
10
- SpriteTypes[SpriteTypes["FILLED"] = 3] = "FILLED";
11
- SpriteTypes[SpriteTypes["MESH"] = 4] = "MESH";
12
- SpriteTypes[SpriteTypes["ANIMATION"] = 5] = "ANIMATION";
13
- })(SpriteTypes || (SpriteTypes = {}));
14
5
  export class SpriteRender extends ComponentX {
15
6
  get spriteFrame() {
16
7
  return this.props.spriteFrame;
@@ -80,7 +71,7 @@ export class GraphicsRender extends ComponentX {
80
71
  }
81
72
  export class TiledMap extends ComponentX {
82
73
  }
83
- export class MotionStreak extends ComponentX {
74
+ export class MotionStreakComp extends ComponentX {
84
75
  reset() {
85
76
  this.node.instance.reset();
86
77
  }
@@ -91,4 +82,4 @@ Object.defineProperty(MaskRender.prototype, 'render', { value: render });
91
82
  Object.defineProperty(ParticleComp.prototype, 'render', { value: render });
92
83
  Object.defineProperty(GraphicsRender.prototype, 'render', { value: render });
93
84
  Object.defineProperty(TiledMap.prototype, 'render', { value: render });
94
- Object.defineProperty(MotionStreak.prototype, 'render', { value: render });
85
+ Object.defineProperty(MotionStreakComp.prototype, 'render', { value: render });
@@ -1 +1 @@
1
- {"version":3,"file":"RenderSystem.d.ts","sourceRoot":"","sources":["../../src/render/RenderSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAoC,MAAM,EAAE,MAAM,YAAY,CAAA;AAOlG,oBAAY,WAAW;IACrB,MAAM,IAAA;IACN,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,IAAI,IAAA;IACJ,SAAS,IAAA;CACV;AAED,qBAAa,YAAa,YAAW,MAAM;IACzC,SAAS,CAAC,aAAa,EAAE,YAAY;IAWrC,OAAO,CAAC,eAAe,CAKtB;IAED,OAAO,CAAC,iBAAiB,CAuBxB;IAED,OAAO,CAAC,eAAe,CAKtB;IAED,OAAO,CAAC,mBAAmB,CAQ1B;IAED,OAAO,CAAC,iBAAiB,CAKxB;IAED,OAAO,CAAC,aAAa,CAKpB;IAED,OAAO,CAAC,iBAAiB,CAWxB;IAED,OAAO,CAAC,iBAAiB,CAKxB;IAED,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;CAIjE"}
1
+ {"version":3,"file":"RenderSystem.d.ts","sourceRoot":"","sources":["../../src/render/RenderSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAoC,MAAM,EAAE,MAAM,YAAY,CAAA;AAOlG,oBAAY,WAAW;IACrB,MAAM,IAAA;IACN,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,IAAI,IAAA;IACJ,SAAS,IAAA;CACV;AAED,qBAAa,YAAa,YAAW,MAAM;IACzC,SAAS,CAAC,aAAa,EAAE,YAAY;IAWrC,OAAO,CAAC,eAAe,CAKtB;IAED,OAAO,CAAC,iBAAiB,CAgBxB;IAED,OAAO,CAAC,eAAe,CAKtB;IAED,OAAO,CAAC,mBAAmB,CAQ1B;IAED,OAAO,CAAC,iBAAiB,CAKxB;IAED,OAAO,CAAC,aAAa,CAKpB;IAED,OAAO,CAAC,iBAAiB,CAUxB;IAED,OAAO,CAAC,iBAAiB,CAKxB;IAED,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;CAIjE"}
@@ -1,7 +1,7 @@
1
1
  import { EventTypes } from 'entityx-ts';
2
2
  import { NodeComp } from '../core/NodeComp';
3
3
  import { BLUE, RED } from '../polyfills';
4
- import { GraphicsRender, MaskRender, MotionStreak, NodeRender, ParticleComp, SpriteRender, TiledMap } from './RenderComponent';
4
+ import { GraphicsRender, MaskRender, MotionStreakComp, NodeRender, ParticleComp, SpriteRender, TiledMap } from './RenderComponent';
5
5
  import { TiledSprite } from './TiledSprite';
6
6
  export var SpriteTypes;
7
7
  (function (SpriteTypes) {
@@ -20,7 +20,7 @@ export class RenderSystem {
20
20
  event_manager.subscribe(EventTypes.ComponentAdded, GraphicsRender, this.onAddGraphicsRender);
21
21
  event_manager.subscribe(EventTypes.ComponentAdded, ParticleComp, this.onAddParticleComp);
22
22
  event_manager.subscribe(EventTypes.ComponentAdded, TiledMap, this.onAddTiledMap);
23
- event_manager.subscribe(EventTypes.ComponentAdded, MotionStreak, this.onAddMotionStreak);
23
+ event_manager.subscribe(EventTypes.ComponentAdded, MotionStreakComp, this.onAddMotionStreak);
24
24
  event_manager.subscribe(EventTypes.ComponentRemoved, NodeComp, this.onRemovedNodeComp);
25
25
  }
26
26
  onAddNodeRender = ({ entity }) => {
@@ -30,24 +30,20 @@ export class RenderSystem {
30
30
  nodeRenderComp.node = ett.assign(new NodeComp(node, ett));
31
31
  };
32
32
  onAddSpriteRender = ({ entity, component: spriteComp }) => {
33
- const { spriteFrame, type, capInsets, tiledSize } = spriteComp.props;
33
+ const { spriteFrame, capInsets, tiledSize } = spriteComp.props;
34
34
  const frame = cc.spriteFrameCache.getSpriteFrame(spriteFrame);
35
35
  // console.log('frame', spriteFrame, frame)
36
36
  let node;
37
- switch (type) {
38
- case SpriteTypes.TILED:
39
- node = new TiledSprite({ texture: spriteFrame, width: tiledSize.width, height: tiledSize.height });
40
- break;
41
- case SpriteTypes.SLICED:
42
- {
43
- const rect = cc.rect(...capInsets);
44
- node = new ccui.Scale9Sprite(frame || spriteFrame, rect, rect);
45
- // console.log('Scale9Sprite', node)
46
- }
47
- break;
48
- default:
49
- node = new cc.Sprite(frame || spriteFrame);
50
- break;
37
+ if (tiledSize) {
38
+ node = new TiledSprite({ texture: spriteFrame, width: tiledSize.width, height: tiledSize.height });
39
+ }
40
+ else if (capInsets) {
41
+ const rect = cc.rect(...capInsets);
42
+ node = new ccui.Scale9Sprite(frame || spriteFrame, rect, rect);
43
+ // console.log('Scale9Sprite', node)
44
+ }
45
+ else {
46
+ node = new cc.Sprite(frame || spriteFrame);
51
47
  }
52
48
  const ett = entity;
53
49
  spriteComp.node = ett.assign(new NodeComp(node, ett));
@@ -79,14 +75,13 @@ export class RenderSystem {
79
75
  const node = new cc.TMXTiledMap(mapFile);
80
76
  tiledMapComp.node = entity.assign(new NodeComp(node, entity));
81
77
  };
82
- onAddMotionStreak = ({ entity }) => {
83
- const motionStreakComp = entity.getComponent(MotionStreak);
84
- const { spriteFrame, fade, minSeg, stroke, color } = motionStreakComp.props;
78
+ onAddMotionStreak = ({ entity, component }) => {
79
+ const { spriteFrame, fade, minSeg, stroke, color } = component.props;
85
80
  const node = new cc.MotionStreak(fade || 0.4, // fade (vệt tồn tại 0.4s)
86
81
  minSeg || 1, // minSeg
87
82
  stroke || 20, // stroke (độ rộng vệt)
88
83
  color || cc.color(255, 255, 255, 255), spriteFrame);
89
- motionStreakComp.node = entity.assign(new NodeComp(node, entity));
84
+ component.node = entity.assign(new NodeComp(node, entity));
90
85
  };
91
86
  onRemovedNodeComp = ({ component }) => {
92
87
  const node = component;
@@ -1,7 +1,13 @@
1
- export declare const SharedSpritesManager: {
2
- isLoaded: boolean;
3
- assets: {};
4
- loadAssetsOnce: (texPngUrl: any) => Promise<unknown>;
5
- };
6
- export declare const TiledSprite: any;
1
+ import { Application, TilingSprite } from 'pixi.js';
2
+ export declare class TiledSprite extends cc.Sprite {
3
+ _tilingSprite: TilingSprite;
4
+ _canvas: any;
5
+ _pixiApp: Application;
6
+ _texture: cc.Texture2D;
7
+ constructor(config: any);
8
+ setContentSize(size: any, height: any): void;
9
+ setScale(scaleX: any, scaleY?: any): void;
10
+ _updateRepeat(): void;
11
+ onExit(): void;
12
+ }
7
13
  //# sourceMappingURL=TiledSprite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TiledSprite.d.ts","sourceRoot":"","sources":["../../src/render/TiledSprite.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB;;;;CAgBhC,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,GAmExB,CAAA"}
1
+ {"version":3,"file":"TiledSprite.d.ts","sourceRoot":"","sources":["../../src/render/TiledSprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAmB,YAAY,EAAE,MAAM,SAAS,CAAA;AAEpE,qBAAa,WAAY,SAAQ,EAAE,CAAC,MAAM;IACxC,aAAa,EAAE,YAAY,CAAA;IAC3B,OAAO,EAAE,GAAG,CAAA;IACZ,QAAQ,EAAE,WAAW,CAAA;IACrB,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAA;gBAEV,MAAM,KAAA;IAoClB,cAAc,CAAC,IAAI,KAAA,EAAE,MAAM,KAAA;IAM3B,QAAQ,CAAC,MAAM,KAAA,EAAE,MAAM,CAAC,KAAA;IAKxB,aAAa;IAeb,MAAM;CAMP"}
@@ -1,61 +1,53 @@
1
- export const SharedSpritesManager = {
2
- isLoaded: false,
3
- assets: {},
4
- loadAssetsOnce: function (texPngUrl) {
5
- if (this.assets[texPngUrl]) {
6
- return;
7
- }
8
- return new Promise((resolve) => {
9
- const loader = new PIXI.Loader();
10
- loader.add(texPngUrl).load((loader, resources) => {
11
- this.assets[texPngUrl] = resources[texPngUrl].texture;
12
- resolve(this.assets[texPngUrl]);
13
- });
14
- });
15
- },
16
- };
17
- export const TiledSprite = cc.Sprite.extend({
18
- _tilingSprite: null,
19
- ctor: function (config) {
20
- this._super();
1
+ import { Application, Assets, Texture, TilingSprite } from 'pixi.js';
2
+ export class TiledSprite extends cc.Sprite {
3
+ _tilingSprite;
4
+ _canvas;
5
+ _pixiApp;
6
+ _texture;
7
+ constructor(config) {
8
+ super();
9
+ super.ctor();
21
10
  this._canvas = document.createElement('canvas');
22
11
  this._canvas.width = config.width || 1024;
23
12
  this._canvas.height = config.height || 1024;
24
- this._pixiApp = new PIXI.Application({
13
+ this._pixiApp = new Application();
14
+ this._pixiApp
15
+ .init({
25
16
  view: this._canvas,
26
17
  width: this._canvas.width,
27
18
  height: this._canvas.height,
28
19
  backgroundAlpha: 0, // nền trong suốt
29
- transparent: true, // bắt buộc để alpha hoạt động
20
+ // transparent: true, // bắt buộc để alpha hoạt động
30
21
  clearBeforeRender: true, // xoá trước khi vẽ frame mới
31
22
  preserveDrawingBuffer: true, // giúp lấy ảnh từ canvas
32
23
  antialias: true,
24
+ })
25
+ .then(() => {
26
+ Assets.load(config.texture).then(() => {
27
+ const texture = Texture.from(config.texture);
28
+ const { width, height } = config;
29
+ this._tilingSprite = new TilingSprite({ texture, width, height });
30
+ this._pixiApp.stage.addChild(this._tilingSprite);
31
+ this._updateRepeat();
32
+ });
33
33
  });
34
34
  this._texture = new cc.Texture2D();
35
35
  this._texture.initWithElement(this._canvas);
36
36
  this._texture.handleLoadedTexture();
37
37
  this.initWithTexture(this._texture);
38
- this._config = config;
39
- this._tilingSprite = null;
40
- SharedSpritesManager.loadAssetsOnce(config.texture).then(() => {
41
- const texture = PIXI.Texture.from(config.texture);
42
- this._tilingSprite = new PIXI.TilingSprite(texture, config.width, config.height);
43
- this._pixiApp.stage.addChild(this._tilingSprite);
44
- this._updateRepeat();
45
- });
46
- // this.schedule(this._updateRepeat, 1)
47
- },
48
- setContentSize: function (size, height) {
38
+ // this.schedule(this._updateRepeat, 1, Infinity, 0)
39
+ }
40
+ setContentSize(size, height) {
49
41
  // console.log('setContentSize', size, height)
50
- this._super(size, height);
42
+ super.setContentSize(size, height);
51
43
  this._updateRepeat();
52
- },
53
- setScale: function (scaleX, scaleY) {
54
- this._super(scaleX, scaleY);
44
+ }
45
+ setScale(scaleX, scaleY) {
46
+ super.setScale(scaleX, scaleY);
55
47
  this._updateRepeat();
56
- },
57
- _updateRepeat: function () {
58
- if (this._tilingSprite) {
48
+ }
49
+ _updateRepeat() {
50
+ if (this._tilingSprite && this._pixiApp.renderer) {
59
51
  this._tilingSprite.width = this.width;
60
52
  this._tilingSprite.height = this.height;
61
53
  this._canvas.width = this.width;
@@ -67,11 +59,11 @@ export const TiledSprite = cc.Sprite.extend({
67
59
  // console.log('_texture', this._texture, this)
68
60
  this.setTexture(this._texture);
69
61
  }
70
- },
71
- onExit: function () {
72
- // this.unschedule(this.updateTexture);
62
+ }
63
+ onExit() {
64
+ this.unschedule(this._updateRepeat);
73
65
  this._pixiApp.destroy(true, { children: true });
74
66
  this._canvas.remove();
75
- this._super();
76
- },
77
- });
67
+ super.onExit();
68
+ }
69
+ }
@@ -0,0 +1,15 @@
1
+ import { Spine } from '@esotericsoftware/spine-pixi-v8';
2
+ import { Application } from 'pixi.js';
3
+ export declare function loadSpineAssets(skeleton: any, atlas: any, texture: any): Promise<any>;
4
+ export declare class PixiSpineSprite extends cc.Sprite {
5
+ _canvas: any;
6
+ _pixiApp: Application;
7
+ _texture: cc.Texture2D;
8
+ _config: any;
9
+ _armatureDisplay: Spine;
10
+ constructor(config: any);
11
+ _setupArmature(): void;
12
+ updateTexture(): void;
13
+ onExit(): void;
14
+ }
15
+ //# sourceMappingURL=PixiSpineSprite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PixiSpineSprite.d.ts","sourceRoot":"","sources":["../../src/spine/PixiSpineSprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAA;AACvD,OAAO,EAAE,WAAW,EAAU,MAAM,SAAS,CAAA;AAE7C,wBAAgB,eAAe,CAAC,QAAQ,KAAA,EAAE,KAAK,KAAA,EAAE,OAAO,KAAA,gBAEvD;AAED,qBAAa,eAAgB,SAAQ,EAAE,CAAC,MAAM;IAC5C,OAAO,EAAE,GAAG,CAAA;IACZ,QAAQ,EAAE,WAAW,CAAA;IACrB,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAA;IACtB,OAAO,MAAA;IACP,gBAAgB,EAAE,KAAK,CAAA;gBACX,MAAM,KAAA;IAgClB,cAAc;IAmBd,aAAa;IASb,MAAM;CAMP"}
@@ -0,0 +1,70 @@
1
+ import { Spine } from '@esotericsoftware/spine-pixi-v8';
2
+ import { Application, Assets } from 'pixi.js';
3
+ export function loadSpineAssets(skeleton, atlas, texture) {
4
+ return Assets.load([skeleton, atlas, texture]);
5
+ }
6
+ export class PixiSpineSprite extends cc.Sprite {
7
+ _canvas;
8
+ _pixiApp;
9
+ _texture;
10
+ _config;
11
+ _armatureDisplay;
12
+ constructor(config) {
13
+ super();
14
+ super.ctor(); // always call this for compatibility with cocos2dx JS Javascript class system
15
+ // this.scheduleUpdate()
16
+ this._canvas = document.createElement('canvas');
17
+ this._canvas.width = config.width || 1024;
18
+ this._canvas.height = config.height || 1024;
19
+ this._pixiApp = new Application();
20
+ this._pixiApp.init({
21
+ view: this._canvas,
22
+ width: this._canvas.width,
23
+ height: this._canvas.height,
24
+ backgroundAlpha: 0, // nền trong suốt
25
+ // transparent: true, // bắt buộc để alpha hoạt động
26
+ clearBeforeRender: true, // xoá trước khi vẽ frame mới
27
+ preserveDrawingBuffer: true, // giúp lấy ảnh từ canvas
28
+ antialias: true,
29
+ });
30
+ this._texture = new cc.Texture2D();
31
+ this._texture.initWithElement(this._canvas);
32
+ this._texture.handleLoadedTexture();
33
+ this.initWithTexture(this._texture);
34
+ this._config = config;
35
+ this._armatureDisplay = null;
36
+ this._setupArmature();
37
+ // this.schedule(this.updateTexture, 1 / 30);
38
+ }
39
+ _setupArmature() {
40
+ const { skeleton, atlas, loop, skin, timeScale, animationName } = this._config;
41
+ const display = Spine.from({ skeleton, atlas });
42
+ if (!display) {
43
+ console.error('Cannot build armature:', skeleton);
44
+ return;
45
+ }
46
+ if (skin) {
47
+ display.skeleton.setSkin(skin);
48
+ }
49
+ display.state.setAnimation(0, animationName, loop);
50
+ display.x = this._canvas.width / 2;
51
+ display.y = this._canvas.height;
52
+ display.state.timeScale = timeScale;
53
+ this._pixiApp.stage.addChild(display);
54
+ this._armatureDisplay = display;
55
+ }
56
+ updateTexture() {
57
+ if (this._armatureDisplay && this._pixiApp.renderer) {
58
+ this._pixiApp.renderer.render(this._pixiApp.stage);
59
+ this._texture.initWithElement(this._canvas);
60
+ this._texture.handleLoadedTexture();
61
+ this.setTexture(this._texture);
62
+ }
63
+ }
64
+ onExit() {
65
+ // this.unschedule(this.updateTexture);
66
+ this._pixiApp.destroy(true, { children: true });
67
+ this._canvas.remove();
68
+ super.onExit();
69
+ }
70
+ }
@@ -1,6 +1,6 @@
1
1
  import { EntityManager, EventManager, System } from 'entityx-ts';
2
2
  import { BaseComponentProps, ComponentX } from '..';
3
- import { SkeletonAnimation } from './CCSkeletonAnimation';
3
+ import { PixiSpineSprite } from './PixiSpineSprite';
4
4
  export interface SpineData {
5
5
  atlas: string;
6
6
  skeleton: string;
@@ -13,15 +13,14 @@ interface SpineSkeletonProps {
13
13
  timeScale?: number;
14
14
  loop?: boolean;
15
15
  }
16
- export declare class SpineSkeleton extends ComponentX<SpineSkeletonProps & BaseComponentProps<SpineSkeleton>, SkeletonAnimation> {
16
+ export declare class SpineSkeleton extends ComponentX<SpineSkeletonProps & BaseComponentProps<SpineSkeleton>, PixiSpineSprite> {
17
17
  setAnimation(name: string, loop?: boolean): void;
18
- setSkeletonData(data: SpineData): void;
19
18
  }
20
19
  export declare class SpineSystem implements System {
21
20
  configure(event_manager: EventManager): void;
22
21
  private onAddSpineSkeleton;
23
- update(entities: EntityManager, events: EventManager, dt: number): any;
22
+ update(entities: EntityManager): void;
24
23
  }
25
24
  export declare function setupSpine(): void;
26
- export {};
25
+ export * from './PixiSpineSprite';
27
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/spine/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAoC,MAAM,EAAE,MAAM,YAAY,CAAA;AAElG,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAA+B,MAAM,IAAI,CAAA;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAEzD,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,UAAU,kBAAkB;IAC1B,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AACD,qBAAa,aAAc,SAAQ,UAAU,CAAC,kBAAkB,GAAG,kBAAkB,CAAC,aAAa,CAAC,EAAE,iBAAiB,CAAC;IACtH,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,UAAQ;IAOvC,eAAe,CAAC,IAAI,EAAE,SAAS;CAKhC;AAED,qBAAa,WAAY,YAAW,MAAM;IACxC,SAAS,CAAC,aAAa,EAAE,YAAY;IAGrC,OAAO,CAAC,kBAAkB,CAYzB;IACD,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;CAIjE;AAGD,wBAAgB,UAAU,SAGzB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/spine/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAoC,MAAM,EAAE,MAAM,YAAY,CAAA;AAElG,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAA+B,MAAM,IAAI,CAAA;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,UAAU,kBAAkB;IAC1B,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AACD,qBAAa,aAAc,SAAQ,UAAU,CAAC,kBAAkB,GAAG,kBAAkB,CAAC,aAAa,CAAC,EAAE,eAAe,CAAC;IACpH,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,UAAQ;CAYxC;AAED,qBAAa,WAAY,YAAW,MAAM;IACxC,SAAS,CAAC,aAAa,EAAE,YAAY;IAGrC,OAAO,CAAC,kBAAkB,CAczB;IACD,MAAM,CAAC,QAAQ,EAAE,aAAa;CAS/B;AAGD,wBAAgB,UAAU,SAEzB;AACD,cAAc,mBAAmB,CAAA"}
@@ -1,42 +1,45 @@
1
1
  import { EventTypes } from 'entityx-ts';
2
2
  import { ComponentX, GameWorld, NodeComp, render } from '..';
3
- import { SkeletonAnimation } from './CCSkeletonAnimation';
3
+ import { PixiSpineSprite } from './PixiSpineSprite';
4
4
  export class SpineSkeleton extends ComponentX {
5
5
  setAnimation(name, loop = false) {
6
6
  const skel = this.node.instance;
7
- if (skel.setAnimation) {
8
- skel.setAnimation(0, name, loop);
7
+ if (skel._armatureDisplay.state.setAnimation) {
8
+ skel._armatureDisplay.state.setAnimation(0, name, loop);
9
9
  }
10
10
  }
11
- setSkeletonData(data) {
12
- const skel = this.node.instance;
13
- const { atlas, skeleton } = data;
14
- skel.initWithArgs(skeleton, atlas);
15
- }
16
11
  }
17
12
  export class SpineSystem {
18
13
  configure(event_manager) {
19
14
  event_manager.subscribe(EventTypes.ComponentAdded, SpineSkeleton, this.onAddSpineSkeleton);
20
15
  }
21
- onAddSpineSkeleton = ({ entity, component: spineComp }) => {
16
+ onAddSpineSkeleton = async ({ entity, component: spineComp }) => {
22
17
  const { data, skin, animation, loop = true, timeScale = 1 } = spineComp.props;
23
- const { atlas, skeleton } = data;
24
- // console.log('spineComp', spineComp)
25
- const node = SkeletonAnimation.createWithJsonFile(skeleton, atlas, timeScale);
26
- if (skin) {
27
- node.setSkin(skin);
28
- }
29
- if (animation) {
30
- node.setAnimation(0, animation, loop);
31
- }
18
+ const { atlas, skeleton, texture } = data;
19
+ // console.log('spineComp', data)
20
+ const node = new PixiSpineSprite({
21
+ skeleton,
22
+ atlas,
23
+ texture,
24
+ animationName: animation,
25
+ loop,
26
+ skin,
27
+ timeScale,
28
+ });
32
29
  spineComp.node = entity.assign(new NodeComp(node, entity));
33
30
  };
34
- update() {
35
- // throw new Error('Method not implemented.');
31
+ update(entities) {
32
+ const animations = entities.entities_with_components(SpineSkeleton);
33
+ animations.forEach((ett) => {
34
+ const spine = ett.getComponent(SpineSkeleton);
35
+ if (spine.node && spine.node.active) {
36
+ spine.node.instance.updateTexture();
37
+ }
38
+ });
36
39
  }
37
40
  }
38
41
  Object.defineProperty(SpineSkeleton.prototype, 'render', { value: render });
39
42
  export function setupSpine() {
40
- GameWorld.Instance.systems.addThenConfigure(SpineSystem);
41
- // GameWorld.Instance.listUpdate.push(SpineSystem)
43
+ GameWorld.Instance.addSystemAndUpdate(SpineSystem);
42
44
  }
45
+ export * from './PixiSpineSprite';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@safe-engine/cocos",
3
- "version": "2.1.9",
3
+ "version": "2.2.2",
4
4
  "description": "safe-engine with cocos renderer support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -21,12 +21,12 @@
21
21
  "typescript": "^5.9.2"
22
22
  },
23
23
  "dependencies": {
24
- "@esotericsoftware/spine-core": "^4.2.89",
25
- "cocos-html5-ts": "^1.2.2",
24
+ "@esotericsoftware/spine-pixi-v8": "^4.2.90",
26
25
  "box2d-wasm": "^7.0.0",
26
+ "cocos-html5-ts": "^1.2.2",
27
+ "dragonbones-pixijs": "^1.0.5",
27
28
  "entityx-ts": "^2.3.1",
28
- "pixi.js": "5.3.12",
29
- "pixi5-dragonbones": "5.7.0-2b"
29
+ "pixi.js": "^8.13.2"
30
30
  },
31
31
  "author": "",
32
32
  "license": "ISC"