totallybueno Posted September 24, 2018 Share Posted September 24, 2018 Hi there, I´m having a few problems with something related with a group and Arcade physics, let me explain. I have a prefab extending the normal group, the idea is that I need to add some graphics here in differente layers and one of them, the background should act the de physics sprite, I mean, this one should be the one detecting collisions, the rest of the graphics would be just that, graphics. I create this item like this: Ribbon = function (game, posX, posY) { // //other code // Phaser.Group.call(this, game); this.myBackground = this.create(this.posX, this.posY, "my-background"); this.enableBody = true; this.physicsBodyType = Phaser.Physics.ARCADE // //and more code // }; And then in the main game .js I call it and everything is placed correctly in the stage but the collisions are not working at all (I also using the render() and no green overlay at all). I´m adding a (extended) group into another group and I´m not doing it right obviously :( this.ribbonGroup = this.game.add.group() this.myRibbon = new Ribbon(this.game, posX, posY) this.ribbonGroup.add(this.myRibbon) /*this.ribbonGroup.enableBody = true; this.ribbonGroup.physicsBodyType = Phaser.Physics.ARCADE*/ The item is there, well place, animations working, everything is fine but the physics part, what am I missing here? Thanks in advance. Link to comment Share on other sites More sharing options...
samme Posted September 24, 2018 Share Posted September 24, 2018 enableBody means any new children added to the group are given a physics body. If the group has no children, nothing important will happen. I'd guess you need something like game.physics.enable(this.myBackground); Link to comment Share on other sites More sharing options...
totallybueno Posted September 24, 2018 Author Share Posted September 24, 2018 Maybe I´m missing something, but still same result. Now I have the Ribbon prefab like this: Ribbon = function (game, posX, posY) { // //other code // Phaser.Group.call(this, game); this.myBackground = this.create(this.posX, this.posY, "my-background"); game.physics.arcade.enable(this.myBackground)//line you told me // //and more code // }; But as I said, still same result. Should I add something when I creat the item in the Game.js? Link to comment Share on other sites More sharing options...
samme Posted September 24, 2018 Share Posted September 24, 2018 Take myBackground out of all the groups and create/enable it by itself. I can't remember how Graphics+Physics objects work, you may have to draw on it before enabling the physics body, or you may have to use body.setSize(). Link to comment Share on other sites More sharing options...
totallybueno Posted September 26, 2018 Author Share Posted September 26, 2018 Yes, I didn´t want this solution but finally I extended Sprite instead of Group and attached manually the other elements instead of into a group. Not the best solution probably but at least I can continue with the game Thanks @samme Link to comment Share on other sites More sharing options...
Recommended Posts