Skip to content

Commit 5049469

Browse files
author
Daniel Báez
authored
fix: screenPos() worldPos() correctly type set functionality (and other type errors) (#593)
1 parent ac9f28c commit 5049469

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/components/physics/area.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,24 @@ export interface AreaComp extends Comp {
131131
*
132132
* @since v2001.0
133133
*/
134-
onCollide(tag: Tag, f: (obj: GameObj, col?: Collision) => void): void;
134+
onCollide(
135+
tag: Tag,
136+
f: (obj: GameObj, col?: Collision) => void,
137+
): KEventController;
135138
/**
136139
* Register an event runs once when collide with another game obj.
137140
*
138141
* @since v2000.1
139142
*/
140-
onCollide(f: (obj: GameObj, col?: Collision) => void): void;
143+
onCollide(f: (obj: GameObj, col?: Collision) => void): KEventController;
141144
/**
142145
* Register an event runs every frame when collide with another game obj with certain tag.
143146
*
144147
* @since v3000.0
145148
*/
146149
onCollideUpdate(
147150
tag: Tag,
148-
f: (obj: GameObj, col?: Collision) => void,
151+
f: (obj: GameObj, col?: Collision) => KEventController,
149152
): KEventController;
150153
/**
151154
* Register an event runs every frame when collide with another game obj.

src/components/transform/pos.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,48 @@ export interface PosComp extends Comp {
3333
moveTo(dest: Vec2, speed?: number): void;
3434
moveTo(x: number, y: number, speed?: number): void;
3535
/**
36-
* Get the position of the object on the screen.
36+
* Get / Set the position of the object on the screen.
37+
*
38+
* @since v2000.0
3739
*/
38-
screenPos(): Vec2 | null;
40+
screenPos(newPos?: Vec2): Vec2 | null;
3941
/**
40-
* Get the position of the object relative to the root.
42+
* Get / Set the position of the object relative to the root.
43+
*
44+
* @since v2000.0
4145
*/
42-
worldPos(): Vec2 | null;
46+
worldPos(newPos?: Vec2): Vec2 | null;
4347
/**
4448
* Transform a local point (relative to this) to a screen point (relative to the camera)
4549
*/
4650
toScreen(this: GameObj<PosComp | FixedComp>, p: Vec2): Vec2;
4751
/**
4852
* Transform a local point (relative to this) to a world point (relative to the root)
53+
*
4954
* @since v3001.0
5055
*/
5156
toWorld(this: GameObj<PosComp>, p: Vec2): Vec2;
5257
/**
5358
* Transform a screen point (relative to the camera) to a local point (relative to this)
59+
*
5460
* @since v3001.0
5561
*/
5662
fromScreen(this: GameObj<PosComp | FixedComp>, p: Vec2): Vec2;
5763
/**
5864
* Transform a world point (relative to the root) to a local point (relative to this)
65+
*
5966
* @since v3001.0
6067
*/
6168
fromWorld(this: GameObj<PosComp>, p: Vec2): Vec2;
6269
/**
6370
* Transform a point relative to this to a point relative to other
71+
*
6472
* @since v3001.0
6573
*/
6674
toOther(this: GameObj<PosComp>, other: GameObj<PosComp>, p: Vec2): Vec2;
6775
/**
6876
* Transform a point relative to other to a point relative to this
77+
*
6978
* @since v3001.0
7079
*/
7180
fromOther(this: GameObj<PosComp>, other: GameObj<PosComp>, p: Vec2): Vec2;

0 commit comments

Comments
 (0)