@dill-pixel/plugin-crunch-physics
Version:
Crunch Physics
120 lines • 3.46 kB
TypeScript
import { Application } from 'dill-pixel';
import { Actor } from './Actor';
import { Entity } from './Entity';
import { Sensor } from './Sensor';
import { Solid } from './Solid';
import { EntityData, PhysicsEntityType } from './types';
/**
* A container for managing collections of physics entities that move together.
* Groups are useful for creating compound objects, moving platforms with riders,
* and other scenarios where multiple entities need to move as one unit.
*
* Features:
* - Maintains relative positioning of child entities
* - Supports actors, solids, and sensors as children
* - Preserves world positions when adding entities
* - Provides type-safe access to children by entity type
*
* @typeParam T - Application type, defaults to base Application
*
* @example
* ```typescript
* // Create a moving platform with obstacles
* const platformGroup = physics.createGroup({
* type: 'MovingPlatform',
* position: [100, 300]
* });
*
* // Add platform and spikes
* const platform = physics.createSolid({
* type: 'Platform',
* size: [200, 32]
* });
*
* const spikes = physics.createSensor({
* type: 'Spikes',
* position: [0, -32],
* size: [200, 32]
* });
*
* platformGroup.add(platform);
* platformGroup.add(spikes);
*
* // Move the entire group
* gsap.to(platformGroup, {
* x: 500,
* duration: 2,
* yoyo: true,
* repeat: -1
* });
* ```
*/
export declare class Group<T extends Application = Application, D extends EntityData = EntityData> extends Entity<T, D> {
entityType: PhysicsEntityType;
/** Map of child entities to their relative offsets from the group's position */
private childOffsets;
/** Whether this group's position is static (not affected by physics) */
isStatic: boolean;
/**
* Gets the relative offset of a child entity from the group's position.
* @param entity - The child entity to get the offset for
* @returns The relative {x, y} offset of the entity
*/
getChildOffset(entity: Entity): {
x: number;
y: number;
};
/**
* Sets the group's X position, affecting all child entities.
*/
set x(value: number);
get x(): number;
/**
* Sets the group's Y position, affecting all child entities.
*/
set y(value: number);
get y(): number;
/**
* Add an entity to this container
* @param entity The entity to add
* @param preserveWorldPosition If true, the entity's world position will be preserved
*/
add(entity: Entity, offset?: {
x: number;
y: number;
}): Group;
/**
* Remove an entity from this container
*/
remove(entity: Entity): Group;
/**
* Move the container and all its children
*/
move(x: number, y: number): void;
/**
* Force move the container and all its children to an absolute position
*/
moveTo(x: number, y: number): void;
/**
* Get all children of a specific type
*/
getChildrenByType<E extends Entity>(type: PhysicsEntityType): E[];
/**
* Get all actors in this container
*/
getActors(): Actor[];
/**
* Get all solids in this container
*/
getSolids(): Solid[];
/**
* Get all sensors in this container
*/
getSensors(): Sensor[];
/**
* Get all groups in this container
*/
getGroups(): Group[];
destroy(): void;
}
//# sourceMappingURL=Group.d.ts.map