andrii.barvynko Posted November 9, 2015 Share Posted November 9, 2015 Hi there. I have a noob question... How I can update bounds of nested sprites? For example:I have a spritelevelSprite = this.game.add.sprite(0, 0); //now width and height - 32x32This sprite has two childs levelNum1 = this.game.add.sprite(0, 0, 'game_assets_4');levelNum1.frameName = "gm_level_number_0001.png";levelNum2 = this.game.add.sprite(100, 100, 'game_assets_4');levelNum2.frameName = "gm_level_number_0002.png";levelSprite.addChild(levelNum1);levelSprite.addChild(levelNum2); // now width and height still 32x32... why? I use phaser v. 2.4.3Would you be so kind to help me please... Link to comment Share on other sites More sharing options...
jmp909 Posted November 10, 2015 Share Posted November 10, 2015 unfortunately it doesn't work like that... here's an example that will calculate what you needhttp://phaser.io/sandbox/QULRhkjt/play this is what @rich said. bounds is, width/height are effectively the scale of the object, the texture size if you willeven a sprite with no assigned texture (like the forum post) still has a texture ... hence, it has dimensions it’s more how it’s called.. a PIXI Sprite getBounds doesn’t iterate children, it’s just the display bounds of the Sprite itself - whereas a DisplayObjectContainer (like a Group) iterates just childrenPixi overrides the DoC getBounds with the Sprite one, because the result is used for the uv verts to get a complete bounds of a Sprite with children you’d need to do a getBounds on the Sprite and sum that rect with a getBounds on its children also remember if you’re doing bounds calls within a create function it hasn’t had a chance for the render pass yet, so you’d need to call updateTransform on it first Link to comment Share on other sites More sharing options...
jmp909 Posted November 11, 2015 Share Posted November 11, 2015 here's an interactive version. click to add a sprite and calculate new boundshttp://phaser.io/sandbox/gzJBGihp/play Link to comment Share on other sites More sharing options...
andrii.barvynko Posted November 11, 2015 Author Share Posted November 11, 2015 Thank you! @jmp909, you saved my game "updateTransform" is what exactly I were looking for. jmp909 1 Link to comment Share on other sites More sharing options...
Recommended Posts