1// Simple physics body configuration helper 2import { Config } from './Config.js'; 3 4export function configurePhysicsBody(sprite, entityType) { 5 const physicsConfig = Config.get(`${entityType}.physics`); 6 7 if (!physicsConfig || !sprite.body) { 8 return; // Use default Phaser collision 9 } 10 11 const { alignBottom } = physicsConfig; 12 13 // Get collision size from config (simplified structure) 14 let bodyWidth, bodyHeight; 15 16 // Handle absolute pixel sizes with aspect ratio preservation 17 if (physicsConfig.width && physicsConfig.height) { 18 // Both specified - use exact values 19 bodyWidth = physicsConfig.width; 20 bodyHeight = physicsConfig.height; 21 } else if (physicsConfig.width) { 22 // Only width specified - preserve sprite aspect ratio 23 const aspectRatio = sprite.height / sprite.width; 24 bodyWidth = physicsConfig.width; 25 bodyHeight = physicsConfig.width * aspectRatio; 26 } else if (physicsConfig.height) { 27 // Only height specified - preserve sprite aspect ratio 28 const aspectRatio = sprite.width / sprite.height; 29 bodyHeight = physicsConfig.height; 30 bodyWidth = physicsConfig.height * aspectRatio; 31 } else { 32 return; // No size specified, use default 33 } 34 35 // Calculate offset relative to original sprite frame 36 const scaleX = sprite.scaleX; 37 const scaleY = sprite.scaleY; 38 // Phaser physics body offsets are in original texture coordinates, not scaled display coordinates. 39 // We need to work backwards from the scaled size to get the correct offset. 40 let offsetX = (sprite.width - bodyWidth / scaleX) / 2; 41 let offsetY = alignBottom 42 ? sprite.height - bodyHeight / scaleY // Bottom-aligned (feet on ground) 43 : (sprite.height - bodyHeight / scaleY) / 2; // Center-aligned 44 // Apply the collision settings 45 sprite.body.setSize(bodyWidth / scaleX, bodyHeight / scaleY); 46 sprite.body.setOffset(offsetX, offsetY); 47 48 // Physics configuration applied successfully 49}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.