@@ -158,48 +158,50 @@ export abstract class FComponent extends FComponentCore {
158
158
159
159
/**
160
160
* @description Set the position of the component.
161
- * @param x The x position.
162
- * @param y The y position.
161
+ * @param options The options for the position.
162
+ * @param options.x The x position.
163
+ * @param options.y The y position.
163
164
* @example
164
165
* ```ts
165
- * component.setPosition(0, 0 )
166
+ * component.setPosition({ x: 0, y: 0 } )
166
167
* ```
167
168
*/
168
- setPosition ( x : number , y : number ) : void {
169
- this . position = { x, y }
170
- this . container . position . set ( x , y )
169
+ setPosition ( options : { x : number , y : number } ) : void {
170
+ this . position = { x : options . x , y : options . y }
171
+ this . container . position . set ( options . x , options . y )
171
172
// If a collider exists, update its translation
172
173
if ( this . collider )
173
- this . collider . collider . setTranslation ( new RAPIER . Vector2 ( x , y ) )
174
+ this . collider . collider . setTranslation ( new RAPIER . Vector2 ( options . x , options . y ) )
174
175
// If a rigid body exists, update its translation
175
176
if ( this . rigidBody )
176
- this . rigidBody . rigidBody . setTranslation ( new RAPIER . Vector2 ( x , y ) , true )
177
+ this . rigidBody . rigidBody . setTranslation ( new RAPIER . Vector2 ( options . x , options . y ) , true )
177
178
}
178
179
179
180
/**
180
181
* @description Set the scale of the component.
181
- * @param x The x scale.
182
- * @param y The y scale.
182
+ * @param options The options for the scale.
183
+ * @param options.x The x scale.
184
+ * @param options.y The y scale.
183
185
* @example
184
186
* ```ts
185
- * component.setScale(1, 1 )
187
+ * component.setScale({ x: 1, y: 1 } )
186
188
* ```
187
189
*/
188
- setScale ( x : number , y : number ) : void {
189
- this . scale = { x, y }
190
- this . container . height = y * 100
191
- this . container . width = x * 100
190
+ setScale ( options : { x : number , y : number } ) : void {
191
+ this . scale = { x : options . x , y : options . y }
192
+ this . container . height = options . y * 100
193
+ this . container . width = options . x * 100
192
194
// If a collider exists
193
195
if ( this . collider ) {
194
196
// If the collider is a cuboid, update its half extents
195
197
if ( this . collider . collider . shape . type === RAPIER . ShapeType . Cuboid ) {
196
- this . collider . collider . setHalfExtents ( new RAPIER . Vector2 ( x / 2 , y / 2 ) )
198
+ this . collider . collider . setHalfExtents ( new RAPIER . Vector2 ( options . x / 2 , options . y / 2 ) )
197
199
}
198
200
// If the collider is a ball, update its radius
199
201
else if ( this . collider . collider . shape . type === RAPIER . ShapeType . Ball ) {
200
202
this . collider . collider . setRadius (
201
203
// Get the maximum value of x and y
202
- Math . max ( x , y ) / 2 ,
204
+ Math . max ( options . x , options . y ) / 2 ,
203
205
)
204
206
}
205
207
}
@@ -334,15 +336,15 @@ export abstract class FComponent extends FComponentCore {
334
336
}
335
337
336
338
set x ( x : number ) {
337
- this . setPosition ( x , this . position . y )
339
+ this . setPosition ( { x, y : this . position . y } )
338
340
}
339
341
340
342
get y ( ) : number {
341
343
return this . position . y
342
344
}
343
345
344
346
set y ( y : number ) {
345
- this . setPosition ( this . position . x , y )
347
+ this . setPosition ( { x : this . position . x , y } )
346
348
}
347
349
348
350
get rotationDegree ( ) : number {
@@ -358,14 +360,14 @@ export abstract class FComponent extends FComponentCore {
358
360
}
359
361
360
362
set scaleX ( x : number ) {
361
- this . setScale ( x , this . scale . y )
363
+ this . setScale ( { x, y : this . scale . y } )
362
364
}
363
365
364
366
get scaleY ( ) : number {
365
367
return this . scale . y
366
368
}
367
369
368
370
set scaleY ( y : number ) {
369
- this . setScale ( this . scale . x , y )
371
+ this . setScale ( { x : this . scale . x , y } )
370
372
}
371
373
}
0 commit comments