PlaninJamin Posted May 12, 2018 Share Posted May 12, 2018 Hey all, I want to add a matter physics body to a Phaser sprite. I'm not too familiar with ES6, but I want to use this code, which is used to add an Arcade physics body to a sprite export default class Actor extends Phaser.GameObjects.Sprite { constructor(config) { super(config.scene, config.x, config.y, config.key); config.scene.physics.world.enable(this); config.scene.add.existing(this); } } and do the equivalent using a Matter physics body type export default class Actor extends Phaser.GameObjects.Sprite { constructor(config) { super(config.scene, config.x, config.y, config.key); // config.scene.matter.world.enable(this); config.scene.add.existing(this); console.log(this.body); // this.body.isStatic = true; } } then declare it in my main phaser file (or any other file). (*config.scene.matter.world.enable(this) doesn't work for matter physics, but will compile without this line*) import 'phaser'; import Actor from './Actor'; var actor; function create () { actor = new Actor ({ scene: this, key: 'logo', x: 500, y: 500 }); } But when I attempt to manipulate the program crashes out with an error, and the Physics body type returns null, even though a matter physics body is still created. So how can I add a matter physics body to a Phaser sprite? thanks in advance Link to comment Share on other sites More sharing options...
samme Posted May 13, 2018 Share Posted May 13, 2018 Extend Phaser.Physics.Matter.Sprite instead? Link to comment Share on other sites More sharing options...
PlaninJamin Posted May 13, 2018 Author Share Posted May 13, 2018 doesn't compile. Phaser.GameObjects.Sprite still creates an body, but Matter.Sprite is undefined Uncaught TypeError: Cannot read property 'queueDepthSort' of undefined at Actor.GameObject [as constructor] (project.bundle.js:521) at new MatterSprite (project.bundle.js:91467) at new Actor (project.bundle.js:160577) at Scene.create (project.bundle.js:109729) at SceneManager.create (project.bundle.js:66916) at SceneManager.loadComplete (project.bundle.js:66810) at LoaderPlugin.emit (project.bundle.js:2680) at LoaderPlugin.loadComplete (project.bundle.js:146302) at LoaderPlugin.fileProcessComplete (project.bundle.js:146258) at ImageFile.onProcessComplete (project.bundle.js:4574) Link to comment Share on other sites More sharing options...
samme Posted May 13, 2018 Share Posted May 13, 2018 I think you're going to have to use the debugging tools to find that undefined value. Double-check the arguments, especially config.scene. Link to comment Share on other sites More sharing options...
samme Posted May 14, 2018 Share Posted May 14, 2018 Matter.Sprite has a world argument, not a scene argument. blackhawx 1 Link to comment Share on other sites More sharing options...
jurbank Posted September 25, 2018 Share Posted September 25, 2018 Did you ever figure this out? I'm getting the same error trying to call to extend Phaser.Physics.Matter.Sprite Link to comment Share on other sites More sharing options...
OtoRexia Posted November 18, 2018 Share Posted November 18, 2018 It's actually simple for matter or impact, you just need to pass world instead of scene. super(scene.matter.world, x, y, sprite, frame, option); // if you are using matter // OR super(scene.impact.world, x, y, sprite, frame); // if you are using impact But if you are using Arcade, that creates a problem. you can't just extend Phaser.Physics.Arcade.Sprite. You have to add this line of code. scene.physics.world.enableBody(this, 0); P.S. To solve this kind of problem I created a development setup to custom create classes. IF you like you can check out my setup at github. blackhawx and juniorgarcia 2 Link to comment Share on other sites More sharing options...
Recommended Posts