Nonononoki Posted July 8, 2015 Share Posted July 8, 2015 Hi, I'm looking for a way to collide 2 groups with each other. This is my first group:// Our core Bullet class // This is a simple Sprite object that we set a few properties on // It is fired by all of the Weapon classes var Bullet = function (game, key) { Phaser.Sprite.call(this, game, 0, 0, key); this.texture.baseTexture.scaleMode = PIXI.scaleModes.NEAREST; this.anchor.set(-0.5); this.checkWorldBounds = true; this.outOfBoundsKill = true; this.exists = false; this.tracking = false; this.scaleSpeed = 0; }; Bullet.prototype = Object.create(Phaser.Sprite.prototype); Bullet.prototype.constructor = Bullet; Bullet.prototype.fire = function (x, y, angle, speed, gx, gy) { gx = gx || 0; gy = gy || 0; this.reset(x, y); this.scale.set(1); this.game.physics.arcade.velocityFromAngle(angle, speed, this.body.velocity); this.angle = angle; this.body.gravity.set(gx, gy); }; Bullet.prototype.update = function () { if (this.tracking) { this.rotation = Math.atan2(this.body.velocity.y, this.body.velocity.x); } if (this.scaleSpeed > 0) { this.scale.x += this.scaleSpeed; this.scale.y += this.scaleSpeed; } }; var Weapon = {}; //////////////////////////////////////////////////// // A single bullet is fired in front of the ship // //////////////////////////////////////////////////// Weapon.SingleBullet = function (game) { Phaser.Group.call(this, game, game.world, 'Single_Bullet', false, true, Phaser.Physics.ARCADE); this.nextFire = 0; this.bulletSpeed = 600; for (var i = 0; i < 100; i++) //maxBulets { var nb = new Bullet(game, 'bullet1'); myBullets.add(nb); this.add(nb, true); } return this; }; Weapon.SingleBullet.prototype = Object.create(Phaser.Group.prototype); Weapon.SingleBullet.prototype.constructor = Weapon.SingleBullet; Weapon.SingleBullet.prototype.fire = function (source) { if (this.game.time.time < this.nextFire) { return; } var x = source.x -10 ; var y = source.y -10; bulletSound.play(); this.getFirstExists(false).fire(x, y, -90, this.bulletSpeed, 0, 0); this.nextFire = this.game.time.time + fireRate; }; ////////////////////////////////////////////////////////////////////////// // Fires a streaming beam of lazers, very fast, in front of the player // ////////////////////////////////////////////////////////////////////////// Weapon.Beam = function (game) { Phaser.Group.call(this, game, game.world, 'Beam', false, true, Phaser.Physics.ARCADE); this.nextFire = 0; this.bulletSpeed = 1000; for (var i = 0; i < 100; i++) { var nb = new Bullet(game, 'lazor'); myBullets.add(nb); this.add(nb, true); } return this; }; Weapon.Beam.prototype = Object.create(Phaser.Group.prototype); Weapon.Beam.prototype.constructor = Weapon.Beam; Weapon.Beam.prototype.fire = function (source) { if (this.game.time.time < this.nextFire) { return; } var x = source.x-12; var y = source.y+3; bulletSound.play(); this.getFirstExists(false).fire(x, y, -90, this.bulletSpeed, 0, 0); this.nextFire = this.game.time.time + fireRate/5; };This is the second group:var baddies;create: function () { baddies = game.add.group(); baddies.enableBody = true; baddies.physicsBodyType = Phaser.Physics.ARCADE;}The thing is, that those two different groups are of a different kind (I think). I already looked up the examples on the phaser example page but it was of no help. Thanks for all answers. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.