codevinsky Posted March 4, 2014 Share Posted March 4, 2014 Cross posted from here. I've got a prefab class that inherits from Group. var PipeGroup = function(game, x, y, collisionGroup, collidesWith) {Phaser.Group.call(this, game);var topPipe = this.create(0,0,'pipes');topPipe.physicsEnabled = true;topPipe.body.kinematic = true;topPipe.body.setRectangle();topPipe.body.setCollisionGroup(collisionGroup);topPipe.body.collides(collidesWith);this.x = x;this.y = y,}; PipeGroup.prototype = Object.create(Phaser.Group.prototype);PipeGroup.prototype.constructor = PipeGroup;And in my main game's create function: create = function() { .. this.playerCG = game.physics.createCollisionGroup(); this.pipeCG = game.physics.createCollisionGroup(); // add our player to the stage this.player = this.add.sprite(game.world.width/3,220,'bird'); // enable physics on our player this.player.physicsEnabled = true; // add our player to the player collision group this.player.body.setCollisionGroup(this.playerCG); this.player.body.collides([this.pipeCG], this.death, this); .. game.time.events.loop(Phaser.Timer.SECOND,this.generatePipes, this);}and generatePipes looks like: generatePipes: function() { var pipeY = game.rnd.integerInRange(-120,120); var pipes = new PipeGroup(game,game.world.width + 32, pipeY, this.pipeCG, this.playerCG); this.player.body.collides([this.pipeCG], this.death, this);}However, the player is never colliding with the pipes. Can you modify a collision group after the create phase of a state?I'm a bit at a loss to figure out why this doesn't work. Link to comment Share on other sites More sharing options...
rich Posted March 4, 2014 Share Posted March 4, 2014 I'll post up examples of how to use this tomorrow, I've been refining the process today. Link to comment Share on other sites More sharing options...
codevinsky Posted March 4, 2014 Author Share Posted March 4, 2014 Just for my own sanity, is there anything I'm doing wrong? I've been banging my head against this for hours. Link to comment Share on other sites More sharing options...
Recommended Posts