rbarriuso Posted December 4, 2014 Share Posted December 4, 2014 Hi all,I'm trying to enable physics on a text object but it seems it doesn't work. Here's the code: //In the "create" function of my Phaser.Statethis.physics.startSystem(Phaser.Physics.ARCADE);// ...var text = this.add.text(this.world.centerX-100, this.world.centerY-200, "MyText", { font: 'bold 100pt Arial', fill: "#8888FF", align: 'center' });text.anchor.setTo(0.5);text.setShadow(5, 5, 'rgba(0,0,0,0.5)', 5);this.physics.enable(text, Phaser.Physics.ARCADE);text.body.bounce.y = 1;text.body.gravity.y = 2000;text.body.collideWorldBounds = true;I get an error because "text.body" is not defined (line 8 in the code above).I supposed "Phaser.Text" supported physics since it inherits from "Sprite".Is this an expected limitation?Thanks in advance, Rafa. Link to comment Share on other sites More sharing options...
lewster32 Posted December 4, 2014 Share Posted December 4, 2014 Only Sprites can have physics enabled, but you can create an empty sprite and attach the text object to it with addChild:var text = this.add.text(0, 0, "MyText", { font: 'bold 100pt Arial', fill: "#8888FF", align: 'center' });text.anchor.setTo(0.5);text.setShadow(5, 5, 'rgba(0,0,0,0.5)', 5);var textSprite = this.add.sprite(this.world.centerX-100, this.world.centerY-200, null);textSprite.addChild(text);this.physics.enable(textSprite, Phaser.Physics.ARCADE);textSprite.body.bounce.y = 1;textSprite.body.gravity.y = 2000;textSprite.body.collideWorldBounds = true; Mike and menthos984 2 Link to comment Share on other sites More sharing options...
rbarriuso Posted December 4, 2014 Author Share Posted December 4, 2014 Thank you! It works perfectly. menthos984 and lewster32 2 Link to comment Share on other sites More sharing options...
Recommended Posts