jcharry Posted February 2, 2017 Share Posted February 2, 2017 Hello! I'm new to Phaser and Box2D, but I've looked through as many posts as I could find on scaling box2d and am still struggling to get it working well. I'm trying to scale a bunch of sprites, and on each scale step increase the worldsize as well so that I can reset box2d world bounds. I've gotten the world scaling and the sprites scaling, but the physics bodies stay behind. It looks like this: the sprites are beyond the bounds of the world and they are offset from their box2d bodies. Here's what I've tried - using body.setRectangle() to scale the Box2D rectangle as well. I've also noticed that the sprites are scaling faster than the world and are leaving the world bounds. I've been banging my head against the wall for a while and was hoping someone had some wisdom to share. if (this.cursors.up.isDown) { // An internal function that I use to track world scale. This is working fine this.scaleWorld(1); // Scale all the bodies in the world inside a group called stageGroup this.stageGroup.scale.set(this.worldScale); // Set the world scale & reset bounds this.game.world.scale.setTo(this.worldScale); this.game.world.setBounds(0, 0, this.worldSize.width * this.worldScale, this.worldSize.height * this.worldScale); // Reset box2d world bounds this.game.physics.box2d.setBoundsToWorld(); // For all sprites in the sprite group, scale them this.stageGroup.children.forEach(child => { // scale x and y child.position.x = child.position.x * this.worldScale; child.position.y = child.position.y * this.worldScale; // This is what I've tried but it's not working child.body.setRectangle(child.initialSize* this.worldScale, child.initialSize * this.worldScale, 0, 0, 0); }); } Thanks!! Link to comment Share on other sites More sharing options...
samme Posted February 2, 2017 Share Posted February 2, 2017 Is stageGroup in game.world? Link to comment Share on other sites More sharing options...
jcharry Posted February 3, 2017 Author Share Posted February 3, 2017 Not sure I understand exactly what you mean. stageGroup is created through game.add.group(), then I add sprites to it through stageGroup.add() Is it possible that a group can not be inside game.world? Link to comment Share on other sites More sharing options...
samme Posted February 4, 2017 Share Posted February 4, 2017 Is stageGroup.parent game.world or game.stage? I have to ask because it's called "stageGroup". If it's in game.world. you may be double scaling the sprites. Set stageGroup.scale or world.scale but not both. Link to comment Share on other sites More sharing options...
Recommended Posts