@safe-engine/cocos 2.5.9 → 2.5.10
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.
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +5 -0
- package/dist/dragonbones/PixiDragonBonesSprite.d.ts +19 -0
- package/dist/dragonbones/PixiDragonBonesSprite.d.ts.map +1 -0
- package/dist/dragonbones/PixiDragonBonesSprite.js +75 -0
- package/dist/gworld/EnhancedComponent.d.ts +22 -0
- package/dist/gworld/EnhancedComponent.d.ts.map +1 -0
- package/dist/gworld/EnhancedComponent.js +44 -0
- package/dist/gworld/NodeComp.d.ts +153 -0
- package/dist/gworld/NodeComp.d.ts.map +1 -0
- package/dist/gworld/NodeComp.js +337 -0
- package/dist/gworld/NodePool.d.ts +9 -0
- package/dist/gworld/NodePool.d.ts.map +1 -0
- package/dist/gworld/NodePool.js +23 -0
- package/dist/gworld/Scene.d.ts +5 -0
- package/dist/gworld/Scene.d.ts.map +1 -0
- package/dist/gworld/Scene.js +14 -0
- package/dist/gworld/decorator.d.ts +8 -0
- package/dist/gworld/decorator.d.ts.map +1 -0
- package/dist/gworld/decorator.js +12 -0
- package/dist/gworld/index.d.ts +8 -0
- package/dist/gworld/index.d.ts.map +1 -0
- package/dist/gworld/index.js +14 -0
- package/dist/safex.d.ts +10 -0
- package/dist/safex.d.ts.map +1 -0
- package/dist/safex.js +1 -0
- package/dist/spine/CCSkeleton.d.ts +189 -0
- package/dist/spine/CCSkeleton.d.ts.map +1 -0
- package/dist/spine/CCSkeleton.js +320 -0
- package/dist/spine/CCSkeletonAnimation.d.ts +146 -0
- package/dist/spine/CCSkeletonAnimation.d.ts.map +1 -0
- package/dist/spine/CCSkeletonAnimation.js +311 -0
- package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts +2 -0
- package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts.map +1 -0
- package/dist/spine/CCSkeletonCanvasRenderCmd.js +228 -0
- package/dist/spine/CCSkeletonTexture.d.ts +25 -0
- package/dist/spine/CCSkeletonTexture.d.ts.map +1 -0
- package/dist/spine/CCSkeletonTexture.js +60 -0
- package/dist/spine/CCSkeletonWebGLRenderCmd.d.ts +28 -0
- package/dist/spine/CCSkeletonWebGLRenderCmd.d.ts.map +1 -0
- package/dist/spine/CCSkeletonWebGLRenderCmd.js +277 -0
- package/dist/spine/PixiSpineSprite.d.ts +19 -0
- package/dist/spine/PixiSpineSprite.d.ts.map +1 -0
- package/dist/spine/PixiSpineSprite.js +72 -0
- package/dist/spine/SpineSkeleton.d.ts +1 -1
- package/dist/spine/SpineSkeleton.d.ts.map +1 -1
- package/dist/spine/SpineSystem.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,72 @@
|
|
|
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._canvas = document.createElement('canvas');
|
|
16
|
+
this._canvas.width = config.width || 1024;
|
|
17
|
+
this._canvas.height = config.height || 1024;
|
|
18
|
+
this._pixiApp = new Application();
|
|
19
|
+
this._pixiApp.init({
|
|
20
|
+
view: this._canvas,
|
|
21
|
+
width: this._canvas.width,
|
|
22
|
+
height: this._canvas.height,
|
|
23
|
+
backgroundAlpha: 0, // nền trong suốt
|
|
24
|
+
// transparent: true, // bắt buộc để alpha hoạt động
|
|
25
|
+
clearBeforeRender: true, // xoá trước khi vẽ frame mới
|
|
26
|
+
preserveDrawingBuffer: true, // giúp lấy ảnh từ canvas
|
|
27
|
+
antialias: true,
|
|
28
|
+
});
|
|
29
|
+
this._texture = new cc.Texture2D();
|
|
30
|
+
this._texture.initWithElement(this._canvas);
|
|
31
|
+
this._texture.handleLoadedTexture();
|
|
32
|
+
this.initWithTexture(this._texture);
|
|
33
|
+
this._config = config;
|
|
34
|
+
this._setupSpine();
|
|
35
|
+
}
|
|
36
|
+
_setupSpine() {
|
|
37
|
+
const { skeleton, atlas, loop, skin, timeScale, animationName } = this._config;
|
|
38
|
+
// console.log('_setupSpine', this._config, Assets.get(this._config.texture))
|
|
39
|
+
const display = Spine.from({ skeleton, atlas, scale: timeScale });
|
|
40
|
+
if (!display) {
|
|
41
|
+
console.error('Cannot build spine:', skeleton);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (skin) {
|
|
45
|
+
const skeletonData = display.skeleton.data;
|
|
46
|
+
const newSkin = skeletonData.findSkin(skin);
|
|
47
|
+
display.skeleton.setSkin(newSkin);
|
|
48
|
+
display.skeleton.setSlotsToSetupPose();
|
|
49
|
+
}
|
|
50
|
+
if (animationName)
|
|
51
|
+
display.state.setAnimation(0, animationName, loop);
|
|
52
|
+
display.x = this._canvas.width / 2;
|
|
53
|
+
display.y = this._canvas.height;
|
|
54
|
+
this._pixiApp.stage.addChild(display);
|
|
55
|
+
this._armatureDisplay = display;
|
|
56
|
+
}
|
|
57
|
+
updateTexture() {
|
|
58
|
+
if (this._armatureDisplay && this._pixiApp.renderer && this._texture) {
|
|
59
|
+
this._pixiApp.renderer.render(this._pixiApp.stage);
|
|
60
|
+
this._texture.initWithElement(this._canvas);
|
|
61
|
+
this._texture.handleLoadedTexture();
|
|
62
|
+
// console.log('updateTexture', this._texture.getPixelsHigh(), this._texture.getPixelsWide())
|
|
63
|
+
this.setTexture(this._texture);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
onExit() {
|
|
67
|
+
// console.log('onExit')
|
|
68
|
+
this._pixiApp.destroy(true, { children: true });
|
|
69
|
+
this._canvas.remove();
|
|
70
|
+
super.onExit();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -11,7 +11,7 @@ interface SpineSkeletonProps {
|
|
|
11
11
|
animation?: string;
|
|
12
12
|
timeScale?: number;
|
|
13
13
|
loop?: boolean;
|
|
14
|
-
onAnimationComplete?:
|
|
14
|
+
onAnimationComplete?: (animationName?: string, loopCount?: number) => void;
|
|
15
15
|
}
|
|
16
16
|
export declare class SpineSkeleton extends ComponentX<SpineSkeletonProps & BaseComponentProps<SpineSkeleton>, SkeletonAnimation> {
|
|
17
17
|
set scaleX(flip: number);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpineSkeleton.d.ts","sourceRoot":"","sources":["../../src/spine/SpineSkeleton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAA0B,IAAI,EAAE,MAAM,IAAI,CAAA;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AAErE,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;IACd,mBAAmB,CAAC,
|
|
1
|
+
{"version":3,"file":"SpineSkeleton.d.ts","sourceRoot":"","sources":["../../src/spine/SpineSkeleton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAA0B,IAAI,EAAE,MAAM,IAAI,CAAA;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AAErE,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;IACd,mBAAmB,CAAC,EAAE,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CAC3E;AACD,qBAAa,aAAc,SAAQ,UAAU,CAAC,kBAAkB,GAAG,kBAAkB,CAAC,aAAa,CAAC,EAAE,iBAAiB,CAAC;IACtH,IAAI,MAAM,CAAC,IAAI,EAAE,MAAM,EAGtB;IACD,gBAAgB;IAIhB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,UAAQ;IAOvC,eAAe,CAAC,IAAI,EAAE,SAAS;CAIhC;AAID,UAAU,+BAAgC,SAAQ,kBAAkB,CAAC,0BAA0B,CAAC;IAC9F,OAAO,EAAE,IAAI,EAAE,CAAA;IACf,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB;AACD,qBAAa,0BAA2B,SAAQ,UAAU,CAAC,+BAA+B,EAAE,iBAAiB,CAAC;IAC5G,KAAK;CAYN"}
|
|
@@ -27,7 +27,7 @@ export class SpineSystem {
|
|
|
27
27
|
if (onAnimationComplete) {
|
|
28
28
|
node.setCompleteListener((track, loopCount) => {
|
|
29
29
|
// console.log(track, loopCount)
|
|
30
|
-
onAnimationComplete(track, loopCount);
|
|
30
|
+
onAnimationComplete(track.animation.name, loopCount);
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
};
|