@safe-engine/cocos 1.6.2 → 1.6.4
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/box2d-wasm/PhysicsComponent.d.ts +4 -0
- package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsComponent.js +28 -0
- package/dist/box2d-wasm/PhysicsSystem.d.ts +2 -1
- package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsSystem.js +7 -8
- package/dist/box2d-wasm/index.d.ts +2 -2
- package/dist/box2d-wasm/index.d.ts.map +1 -1
- package/dist/box2d-wasm/index.js +4 -1
- package/package.json +1 -1
- package/dist/gworld/components/AnimationComponent.d.ts +0 -65
- package/dist/gworld/components/AnimationComponent.d.ts.map +0 -1
- package/dist/gworld/components/AnimationComponent.js +0 -141
- package/dist/gworld/components/CollideComponent.d.ts +0 -64
- package/dist/gworld/components/CollideComponent.d.ts.map +0 -1
- package/dist/gworld/components/CollideComponent.js +0 -265
- package/dist/gworld/systems/AnimationSystem.d.ts +0 -6
- package/dist/gworld/systems/AnimationSystem.d.ts.map +0 -1
- package/dist/gworld/systems/AnimationSystem.js +0 -30
- package/dist/gworld/systems/CollideSystem.d.ts +0 -20
- package/dist/gworld/systems/CollideSystem.d.ts.map +0 -1
- package/dist/gworld/systems/CollideSystem.js +0 -171
- package/dist/helper/html-text-parser.d.ts +0 -30
- package/dist/helper/html-text-parser.d.ts.map +0 -1
- package/dist/helper/html-text-parser.js +0 -354
|
@@ -18,6 +18,10 @@ interface RigidBodyProps {
|
|
|
18
18
|
export declare class RigidBody extends NoRenderComponentX<RigidBodyProps> {
|
|
19
19
|
body: Box2D.b2Body;
|
|
20
20
|
physicSprite: PhysicsSprite;
|
|
21
|
+
set linearVelocity(vel: Vec2);
|
|
22
|
+
get linearVelocity(): Vec2;
|
|
23
|
+
set position(pos: Vec2);
|
|
24
|
+
get position(): Vec2;
|
|
21
25
|
}
|
|
22
26
|
interface BoxColliderPhysicsProps {
|
|
23
27
|
width: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhysicsComponent.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"PhysicsComponent.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAG/C,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAChB,OAAO,CAAC,EAAE,KAAK,CAAA;IACf,WAAW,CAAC,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB,YAAY,CAAC,EAAE,KAAK,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAA;IAC3C,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAA;IACzC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,KAAA,KAAK,IAAI,CAAA;IACjD,WA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
|
+
import { box2D } from './PhysicsSystem';
|
|
2
4
|
export class RigidBody extends NoRenderComponentX {
|
|
3
5
|
body;
|
|
4
6
|
physicSprite;
|
|
7
|
+
set linearVelocity(vel) {
|
|
8
|
+
if (!this.node) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
this.physicSprite.getBody().SetLinearVelocity(new box2D.b2Vec2(vel.x, vel.y));
|
|
12
|
+
}
|
|
13
|
+
get linearVelocity() {
|
|
14
|
+
if (!this.node) {
|
|
15
|
+
return Vec2.ZERO;
|
|
16
|
+
}
|
|
17
|
+
const vel = this.physicSprite.getBody().GetLinearVelocity();
|
|
18
|
+
return Vec2(vel);
|
|
19
|
+
}
|
|
20
|
+
set position(pos) {
|
|
21
|
+
this.physicSprite.node.setPosition(pos.x, pos.y);
|
|
22
|
+
const physicsPos = new box2D.b2Vec2(pos.x, pos.y);
|
|
23
|
+
// console.log('SetTransform', pos, physicsPos)
|
|
24
|
+
const body = this.physicSprite.getBody();
|
|
25
|
+
body.SetLinearVelocity(new box2D.b2Vec2(0, 0));
|
|
26
|
+
body.SetAngularVelocity(0);
|
|
27
|
+
body.SetAwake(true);
|
|
28
|
+
body.SetTransform(physicsPos, this.node.rotation);
|
|
29
|
+
}
|
|
30
|
+
get position() {
|
|
31
|
+
return Vec2(this.physicSprite.getBody().GetPosition());
|
|
32
|
+
}
|
|
5
33
|
}
|
|
6
34
|
export class PhysicsBoxCollider extends NoRenderComponentX {
|
|
7
35
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EntityManager, EventManager, System } from 'entityx-ts';
|
|
2
|
+
import { Vec2 } from '..';
|
|
2
3
|
export declare const DynamicBody = 2;
|
|
3
4
|
export declare const KinematicBody = 1;
|
|
4
5
|
export declare const StaticBody = 0;
|
|
@@ -14,6 +15,6 @@ export declare class PhysicsSystem implements System {
|
|
|
14
15
|
addDebug(): void;
|
|
15
16
|
configure(event_manager: EventManager): void;
|
|
16
17
|
update(entities: EntityManager, events: EventManager, dt: number): void;
|
|
17
|
-
set
|
|
18
|
+
set gravity(val: Vec2);
|
|
18
19
|
}
|
|
19
20
|
//# sourceMappingURL=PhysicsSystem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhysicsSystem.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsSystem.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAc,MAAM,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"PhysicsSystem.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsSystem.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAc,MAAM,EAAE,MAAM,YAAY,CAAA;AAE5E,OAAO,EAAoC,IAAI,EAAE,MAAM,IAAI,CAAA;AAM3D,eAAO,MAAM,WAAW,IAAI,CAAA;AAC5B,eAAO,MAAM,aAAa,IAAI,CAAA;AAC9B,eAAO,MAAM,UAAU,IAAI,CAAA;AAC3B,eAAO,IAAI,KAAK,EAAE,OAAO,KAAK,CAAA;AAE9B,wBAAgB,SAAS,CAAC,EAAE,KAAA,QAK3B;AASD,wBAAgB,iBAAiB,CAAC,cAAc,cAAW,QAG1D;AAOD,qBAAa,aAAc,YAAW,MAAM;IAC1C,KAAK,EAAE,KAAK,CAAC,OAAO,CAAA;IACpB,cAAc,EAAE,KAAK,CAAC,MAAM,EAAE,CAAK;IACnC,eAAe,EAAE,KAAK,CAAC,OAAO,EAAE,CAAK;IACrC,cAAc,cAAW;IACzB,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAA;IAErB,QAAQ;IAKR,SAAS,CAAC,aAAa,EAAE,YAAY;IA4JrC,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;IAwBhE,IAAI,OAAO,CAAC,GAAG,EAAE,IAAI,EAIpB;CACF"}
|
|
@@ -157,10 +157,11 @@ export class PhysicsSystem {
|
|
|
157
157
|
const polygonShape = new b2PolygonShape();
|
|
158
158
|
const fixedPoints = points.map((p) => {
|
|
159
159
|
if (p.x)
|
|
160
|
-
return Vec2(p.x + x - width * anchorX * scaleX, p.y + y
|
|
161
|
-
return Vec2(p[0] + x - width * anchorX * scaleX, p[1] + y
|
|
160
|
+
return Vec2(p.x + x - width * anchorX * scaleX, -p.y + y + height * scaleY * anchorY);
|
|
161
|
+
return Vec2(p[0] + x - width * anchorX * scaleX, -p[1] + y + height * scaleY * anchorY);
|
|
162
162
|
});
|
|
163
163
|
const [vecArr, destroyVecArr] = pointsToVec2Array(fixedPoints);
|
|
164
|
+
// console.log('vecArr', vecArr, vecArr.Length())
|
|
164
165
|
polygonShape.Set(vecArr, points.length);
|
|
165
166
|
destroyVecArr();
|
|
166
167
|
const fixtureDef = new b2FixtureDef();
|
|
@@ -212,11 +213,9 @@ export class PhysicsSystem {
|
|
|
212
213
|
// console.log('GetBodyCount', this.world.GetBodyCount())
|
|
213
214
|
}
|
|
214
215
|
}
|
|
215
|
-
set
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
// this.world.collisionSlop = 0.5
|
|
220
|
-
}
|
|
216
|
+
set gravity(val) {
|
|
217
|
+
this.world.SetGravity(new box2D.b2Vec2(val.x, val.y));
|
|
218
|
+
// this.world.iterations = 60
|
|
219
|
+
// this.world.collisionSlop = 0.5
|
|
221
220
|
}
|
|
222
221
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { GameWorld } from '..';
|
|
1
|
+
import { GameWorld, Vec2 } from '..';
|
|
2
2
|
export * from './PhysicsComponent';
|
|
3
3
|
export * from './PhysicsSprite';
|
|
4
4
|
export * from './PhysicsSystem';
|
|
5
|
-
export declare function setupPhysics(world?: GameWorld, isDebugDraw?:
|
|
5
|
+
export declare function setupPhysics(world?: GameWorld, isDebugDraw?: boolean, gravity?: Vec2): void;
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAGpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAE/B,wBAAgB,YAAY,CAAC,KAAK,YAAqB,EAAE,WAAW,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,IAAI,QAU7F"}
|
package/dist/box2d-wasm/index.js
CHANGED
|
@@ -3,11 +3,14 @@ import { PhysicsSystem } from './PhysicsSystem';
|
|
|
3
3
|
export * from './PhysicsComponent';
|
|
4
4
|
export * from './PhysicsSprite';
|
|
5
5
|
export * from './PhysicsSystem';
|
|
6
|
-
export function setupPhysics(world = GameWorld.Instance, isDebugDraw) {
|
|
6
|
+
export function setupPhysics(world = GameWorld.Instance, isDebugDraw, gravity) {
|
|
7
7
|
world.systems.add(PhysicsSystem);
|
|
8
8
|
world.systems.configureOnce(PhysicsSystem);
|
|
9
9
|
world.listUpdate.push(PhysicsSystem);
|
|
10
10
|
if (isDebugDraw) {
|
|
11
11
|
world.systems.get(PhysicsSystem).addDebug();
|
|
12
12
|
}
|
|
13
|
+
if (gravity) {
|
|
14
|
+
world.systems.get(PhysicsSystem).gravity = gravity;
|
|
15
|
+
}
|
|
13
16
|
}
|
package/package.json
CHANGED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { EnhancedComponent } from '../gworld/components/EnhancedComponent';
|
|
2
|
-
export declare namespace AnimationClip {
|
|
3
|
-
interface IEvent {
|
|
4
|
-
frame: number;
|
|
5
|
-
func: string;
|
|
6
|
-
params: string[];
|
|
7
|
-
isCalled: boolean;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export declare enum WrapMode {
|
|
11
|
-
Default = 0,
|
|
12
|
-
Normal = 1,
|
|
13
|
-
Loop = 2,
|
|
14
|
-
PingPong = 22,
|
|
15
|
-
Reverse = 36,
|
|
16
|
-
LoopReverse = 38,
|
|
17
|
-
PingPongReverse = 54
|
|
18
|
-
}
|
|
19
|
-
interface AnimProp {
|
|
20
|
-
frame: number;
|
|
21
|
-
value: number;
|
|
22
|
-
}
|
|
23
|
-
interface SpriteFrameProp {
|
|
24
|
-
frame: number;
|
|
25
|
-
value: string;
|
|
26
|
-
}
|
|
27
|
-
interface CurveData {
|
|
28
|
-
comps: {
|
|
29
|
-
spriteFrame: SpriteFrameProp[];
|
|
30
|
-
nextFrame: number;
|
|
31
|
-
};
|
|
32
|
-
props: {
|
|
33
|
-
[key: string]: AnimProp[];
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
export declare class AnimationClip {
|
|
37
|
-
static WrapMode: typeof WrapMode;
|
|
38
|
-
sample: number;
|
|
39
|
-
speed: number;
|
|
40
|
-
wrapMode: WrapMode;
|
|
41
|
-
events: AnimationClip.IEvent[];
|
|
42
|
-
duration: number;
|
|
43
|
-
name: string;
|
|
44
|
-
curveData: CurveData;
|
|
45
|
-
}
|
|
46
|
-
export declare class AnimationComp extends EnhancedComponent {
|
|
47
|
-
defaultClip: AnimationClip;
|
|
48
|
-
clips: AnimationClip[];
|
|
49
|
-
playOnLoad: boolean;
|
|
50
|
-
private isPaused;
|
|
51
|
-
private elapsed;
|
|
52
|
-
private currentClip;
|
|
53
|
-
constructor(defaultClip: AnimationClip, clips: AnimationClip[], playOnLoad: boolean);
|
|
54
|
-
start(): void;
|
|
55
|
-
update(dt: Float): void;
|
|
56
|
-
getAnimationState(name: string): {
|
|
57
|
-
isPlaying: boolean;
|
|
58
|
-
};
|
|
59
|
-
play(name?: string): void;
|
|
60
|
-
pause(): void;
|
|
61
|
-
resume(): void;
|
|
62
|
-
stop(name?: string): void;
|
|
63
|
-
}
|
|
64
|
-
export { };
|
|
65
|
-
//# sourceMappingURL=AnimationComponent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AnimationComponent.d.ts","sourceRoot":"","sources":["../../../src/gworld/components/AnimationComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAGvD,MAAM,CAAC,OAAO,WAAW,aAAa,CAAC;IACrC,UAAiB,MAAM;QACrB,KAAK,EAAE,MAAM,CAAA;QACb,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,EAAE,CAAA;QAChB,QAAQ,EAAE,OAAO,CAAA;KAClB;CACF;AAED,oBAAY,QAAQ;IAClB,OAAO,IAAI;IACX,MAAM,IAAI;IACV,IAAI,IAAI;IACR,QAAQ,KAAK;IACb,OAAO,KAAK;IACZ,WAAW,KAAK;IAChB,eAAe,KAAK;CACrB;AAED,UAAU,QAAQ;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED,UAAU,eAAe;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED,UAAU,SAAS;IACjB,KAAK,EAAE;QAAE,WAAW,EAAE,eAAe,EAAE,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAA;IAC5D,KAAK,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,EAAE,CAAA;KAAE,CAAA;CACrC;AAED,qBAAa,aAAa;IACxB,OAAc,QAAQ,kBAAW;IAC1B,MAAM,SAAK;IACX,KAAK,SAAI;IACT,QAAQ,WAAkB;IAC1B,MAAM,EAAE,aAAa,CAAC,MAAM,EAAE,CAAK;IACnC,QAAQ,SAAI;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,SAAS,CAAA;CACrB;AAID,qBAAa,aAAc,SAAQ,iBAAiB;IAClD,WAAW,EAAE,aAAa,CAAA;IAC1B,KAAK,EAAE,aAAa,EAAE,CAAA;IACtB,UAAU,EAAE,OAAO,CAAA;IACnB,OAAO,CAAC,QAAQ,CAAO;IACvB,OAAO,CAAC,OAAO,CAAI;IACnB,OAAO,CAAC,WAAW,CAAe;gBAEtB,WAAW,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,OAAO;IAOnF,KAAK;IASL,MAAM,CAAC,EAAE,EAAE,KAAK;IAqChB,iBAAiB,CAAC,IAAI,EAAE,MAAM;;;IAMvB,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM;IAoBlB,KAAK;IAKL,MAAM;IAKN,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM;CAI1B"}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.AnimationComp = exports.AnimationClip = exports.WrapMode = void 0;
|
|
19
|
-
var EnhancedComponent_1 = require("./EnhancedComponent");
|
|
20
|
-
var RenderComponent_1 = require("./RenderComponent");
|
|
21
|
-
var WrapMode;
|
|
22
|
-
(function (WrapMode) {
|
|
23
|
-
WrapMode[WrapMode["Default"] = 0] = "Default";
|
|
24
|
-
WrapMode[WrapMode["Normal"] = 1] = "Normal";
|
|
25
|
-
WrapMode[WrapMode["Loop"] = 2] = "Loop";
|
|
26
|
-
WrapMode[WrapMode["PingPong"] = 22] = "PingPong";
|
|
27
|
-
WrapMode[WrapMode["Reverse"] = 36] = "Reverse";
|
|
28
|
-
WrapMode[WrapMode["LoopReverse"] = 38] = "LoopReverse";
|
|
29
|
-
WrapMode[WrapMode["PingPongReverse"] = 54] = "PingPongReverse";
|
|
30
|
-
})(WrapMode || (exports.WrapMode = WrapMode = {}));
|
|
31
|
-
var AnimationClip = /** @class */ (function () {
|
|
32
|
-
function AnimationClip() {
|
|
33
|
-
this.sample = 60;
|
|
34
|
-
this.speed = 1;
|
|
35
|
-
this.wrapMode = WrapMode.Normal;
|
|
36
|
-
this.events = [];
|
|
37
|
-
this.duration = 0;
|
|
38
|
-
}
|
|
39
|
-
AnimationClip.WrapMode = WrapMode;
|
|
40
|
-
return AnimationClip;
|
|
41
|
-
}());
|
|
42
|
-
exports.AnimationClip = AnimationClip;
|
|
43
|
-
// cc.AnimationClip = AnimationClip;
|
|
44
|
-
var AnimationComp = /** @class */ (function (_super) {
|
|
45
|
-
__extends(AnimationComp, _super);
|
|
46
|
-
function AnimationComp(defaultClip, clips, playOnLoad) {
|
|
47
|
-
var _this = _super.call(this) || this;
|
|
48
|
-
_this.isPaused = true;
|
|
49
|
-
_this.elapsed = 0;
|
|
50
|
-
_this.defaultClip = defaultClip;
|
|
51
|
-
_this.clips = clips;
|
|
52
|
-
_this.playOnLoad = playOnLoad;
|
|
53
|
-
return _this;
|
|
54
|
-
}
|
|
55
|
-
AnimationComp.prototype.start = function () {
|
|
56
|
-
var _this = this;
|
|
57
|
-
if (this.playOnLoad) {
|
|
58
|
-
setTimeout(function () {
|
|
59
|
-
_this.play();
|
|
60
|
-
}, 0);
|
|
61
|
-
}
|
|
62
|
-
// cc.log(this.clips);
|
|
63
|
-
};
|
|
64
|
-
AnimationComp.prototype.update = function (dt) {
|
|
65
|
-
var _this = this;
|
|
66
|
-
if (this.isPaused || !this.node.active) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
var _a = this.currentClip, curveData = _a.curveData, wrapMode = _a.wrapMode, events = _a.events, duration = _a.duration, speed = _a.speed;
|
|
70
|
-
this.elapsed += dt * speed;
|
|
71
|
-
var _b = curveData.comps, spriteFrame = _b.spriteFrame, nextFrame = _b.nextFrame;
|
|
72
|
-
var nextFrameTime = spriteFrame[nextFrame].frame;
|
|
73
|
-
events.forEach(function (evt) {
|
|
74
|
-
var func = evt.func, frame = evt.frame, params = evt.params, isCalled = evt.isCalled;
|
|
75
|
-
if (!isCalled && _this.elapsed >= frame) {
|
|
76
|
-
evt.isCalled = true;
|
|
77
|
-
// this.node.emit(func, ...params)
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
if (this.elapsed >= nextFrameTime) {
|
|
81
|
-
var imageComp = this.node.getComponent(RenderComponent_1.SpriteRender);
|
|
82
|
-
if (imageComp) {
|
|
83
|
-
imageComp.spriteFrame = spriteFrame[nextFrame].value;
|
|
84
|
-
}
|
|
85
|
-
// cc.log(spriteFrame[nextFrame].value, nextFrameTime);
|
|
86
|
-
curveData.comps.nextFrame += 1;
|
|
87
|
-
curveData.comps.nextFrame = cc.clampf(curveData.comps.nextFrame, 0, spriteFrame.length - 1);
|
|
88
|
-
if (this.elapsed >= duration) {
|
|
89
|
-
if (wrapMode === WrapMode.Loop) {
|
|
90
|
-
curveData.comps.nextFrame = 0;
|
|
91
|
-
this.elapsed = 0;
|
|
92
|
-
events.forEach(function (evt) {
|
|
93
|
-
evt.isCalled = false;
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
this.isPaused = true;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
AnimationComp.prototype.getAnimationState = function (name) {
|
|
103
|
-
return {
|
|
104
|
-
isPlaying: !this.isPaused,
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
AnimationComp.prototype.play = function (name) {
|
|
108
|
-
this.elapsed = 0;
|
|
109
|
-
// cc.log('play', name, this.defaultClip.name);
|
|
110
|
-
if (!name) {
|
|
111
|
-
if (!this.defaultClip) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
name = this.defaultClip.name;
|
|
115
|
-
}
|
|
116
|
-
else if (this.currentClip && name === this.currentClip.name) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
this.currentClip = this.clips.find(function (clip) { return clip.name === name; });
|
|
120
|
-
this.currentClip.curveData.comps.nextFrame = 0;
|
|
121
|
-
// cc.log('name', name, this.currentClip);
|
|
122
|
-
this.currentClip.events.forEach(function (evt) {
|
|
123
|
-
evt.isCalled = false;
|
|
124
|
-
});
|
|
125
|
-
this.isPaused = false;
|
|
126
|
-
};
|
|
127
|
-
AnimationComp.prototype.pause = function () {
|
|
128
|
-
this.node.instance.pause();
|
|
129
|
-
this.isPaused = true;
|
|
130
|
-
};
|
|
131
|
-
AnimationComp.prototype.resume = function () {
|
|
132
|
-
this.node.instance.resume();
|
|
133
|
-
this.isPaused = false;
|
|
134
|
-
};
|
|
135
|
-
AnimationComp.prototype.stop = function (name) {
|
|
136
|
-
this.node.instance.unscheduleAllCallbacks();
|
|
137
|
-
this.isPaused = true;
|
|
138
|
-
};
|
|
139
|
-
return AnimationComp;
|
|
140
|
-
}(EnhancedComponent_1.EnhancedComponent));
|
|
141
|
-
exports.AnimationComp = AnimationComp;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Vec2 } from '../../polyfills';
|
|
2
|
-
import { NoRenderComponentX } from '../core/decorator';
|
|
3
|
-
interface ColliderProps {
|
|
4
|
-
offset?: Vec2;
|
|
5
|
-
tag?: number;
|
|
6
|
-
enabled?: boolean;
|
|
7
|
-
onCollisionEnter?: (other: Collider) => void;
|
|
8
|
-
onCollisionExit?: (other: Collider) => void;
|
|
9
|
-
onCollisionStay?: (other: Collider) => void;
|
|
10
|
-
}
|
|
11
|
-
export declare class Collider<T = ColliderProps> extends NoRenderComponentX<T> {
|
|
12
|
-
_worldPoints: cc.Vec2[] | cc.Point[];
|
|
13
|
-
_worldPosition: cc.Vec2 | cc.Point;
|
|
14
|
-
_worldRadius: any;
|
|
15
|
-
_AABB: cc.Rect;
|
|
16
|
-
_preAabb: cc.Rect;
|
|
17
|
-
getAABB(): cc.Rect;
|
|
18
|
-
get world(): {
|
|
19
|
-
points: cc.Point[] | cc.Vec2[];
|
|
20
|
-
preAabb: cc.Rect;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
interface BoxColliderProps extends ColliderProps {
|
|
24
|
-
width: number;
|
|
25
|
-
height: number;
|
|
26
|
-
}
|
|
27
|
-
export declare class BoxCollider extends Collider<BoxColliderProps> {
|
|
28
|
-
get size(): cc.Size;
|
|
29
|
-
set size(s: cc.Size);
|
|
30
|
-
update(dt: any, draw: cc.DrawNode): void;
|
|
31
|
-
}
|
|
32
|
-
interface CircleColliderProps extends ColliderProps {
|
|
33
|
-
radius: number;
|
|
34
|
-
}
|
|
35
|
-
export declare class CircleCollider extends Collider<CircleColliderProps> {
|
|
36
|
-
update(dt: any, draw: cc.DrawNode): void;
|
|
37
|
-
}
|
|
38
|
-
interface PolygonColliderProps extends ColliderProps {
|
|
39
|
-
points: Array<Vec2>;
|
|
40
|
-
}
|
|
41
|
-
export declare class PolygonCollider extends Collider<PolygonColliderProps> {
|
|
42
|
-
get points(): Vec2[];
|
|
43
|
-
set points(points: Vec2[]);
|
|
44
|
-
update(dt: any, draw: cc.DrawNode): void;
|
|
45
|
-
}
|
|
46
|
-
export declare enum CollisionType {
|
|
47
|
-
NONE = 0,
|
|
48
|
-
ENTER = 1,
|
|
49
|
-
STAY = 2,
|
|
50
|
-
EXIT = 3
|
|
51
|
-
}
|
|
52
|
-
export declare class Contract {
|
|
53
|
-
_collider1: Collider;
|
|
54
|
-
_collider2: Collider;
|
|
55
|
-
_touching: boolean;
|
|
56
|
-
_isPolygonPolygon: boolean;
|
|
57
|
-
_isCircleCircle: boolean;
|
|
58
|
-
_isPolygonCircle: boolean;
|
|
59
|
-
constructor(collider1: Collider, collider2: Collider);
|
|
60
|
-
updateState(): CollisionType;
|
|
61
|
-
test(): any;
|
|
62
|
-
}
|
|
63
|
-
export {};
|
|
64
|
-
//# sourceMappingURL=CollideComponent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CollideComponent.d.ts","sourceRoot":"","sources":["../../../src/gworld/components/CollideComponent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAYtD,UAAU,aAAa;IACrB,MAAM,CAAC,EAAE,IAAI,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAA;IAC5C,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAA;IAC3C,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAA;CAC5C;AACD,qBAAa,QAAQ,CAAC,CAAC,GAAG,aAAa,CAAE,SAAQ,kBAAkB,CAAC,CAAC,CAAC;IACpE,YAAY,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,CAAK;IACzC,cAAc,EAAE,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,KAAK,CAAA;IAClC,YAAY,MAAA;IACZ,KAAK,EAAE,EAAE,CAAC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